Magento : add script phtml to product page - magento

I have a phtml script that I want to add it to the product page view right under the price-box div or the content this img describe where I want to add it in the page source :
I have tried this :
<?xml version="1.0" encoding="UTF-8"?>
<layout version="0.1.0">
<catalog_product_view>
<reference name="product.info">
<block type="core/template" name="customprice" as="other" template="customprice/extJs.phtml"/>
</reference>
</catalog_product_view>
</layout>
but nothing is done! Can you explain why and how to fix it?

In your app/design/frontend/base/default/template/catalog/product/view.phtml file
Change the name from "other" to "otherjs" in your xml
<?php if ($_product->getShortDescription()):?>
<div class="short-description">
<h2><?php echo $this->__('Quick Overview') ?></h2>
<div class="std"><?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?></div>
<div><?php echo $this->getChildHtml('otherjs');//changes here?></div>
</div>
<?php endif;?>

Related

Moving toplinks to another block in Magento

I'm trying to move the toplinks to a static block that I created above the header. Currently, I'm only getting the "Log Out" link instead of all of the top links (My Account, My Wishlist, My Cart, and Checkout). How can I get all these links into the static block?
2columns-right.phtml
<head>
<?php echo $this->getChildHtml('head') ?>
</head>
<body<?php echo $this->getBodyClass()?' class="'.$this->getBodyClass().'"':'' ?>>
<?php echo $this->getChildHtml('after_body_start') ?>
<div class="wrapper">
<?php echo $this->getChildHtml('global_notices') ?>
<div class="page">
<div><?php echo $this->getChildHtml('newreference') ?></div>
<?php echo $this->getChildHtml('header') ?>
<div class="main-container col2-right-layout">
<div class="main">
<?php echo $this->getChildHtml('breadcrumbs') ?>
<div class="col-main">
<?php echo $this->getChildHtml('global_messages') ?>
<?php echo $this->getChildHtml('content') ?>
</div>
<div class="col-right sidebar"><?php echo $this->getChildHtml('right') ?></div>
</div>
</div>
<?php echo $this->getChildHtml('footer') ?>
<?php echo $this->getChildHtml('global_cookie_notice') ?>
<?php echo $this->getChildHtml('before_body_end') ?>
</div>
</div>
<?php echo $this->getAbsoluteFooter() ?>
</body>
</html>
newReference.phtml
<p class="welcome-msg"><?php echo $this->getChildHtml('welcome') ?> <?php echo $this->getAdditionalHtml() ?></p>
<div class="quick-access">
<?php echo $this->getChildHtml('topLinks') ?>
</div>
local.xml
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<default>
<reference name="root">
<block type="core/text_list" name="newreference" as="newreference" translate="label">
<label>New Reference</label>
</block>
</reference>
<reference name="newreference">
<block type="core/template" name="newreferenceblock" template="newreference.phtml">
<block type="page/template_links" name="top.links" as="topLinks"/>
</block>
</reference>
</default>
</layout>
Try this
<reference name="newreference">
<block type="core/template" name="newreferenceblock" template="newreference.phtml">
<block type="page/template_links" name="top.links" as="topLinks"/>
</block>
</reference>
change this to
<reference name="newreference">
<block type="core/template" name="newreference" template="newReference.phtml">
<block type="page/template_links" name="top.links" as="topLinks"/>
</block>
</reference>

Add Structural Block - Magento 1.9

i have a problem with structural block in magento 1.9.
This is my local.xml layout file:
<layout version="0.1.0">
<default>
<reference name="root">
<block type="core/template" name="pluma" as="pluma" template="pluma/helloworld/simple_page.html"/>
</reference>
</default>
This is my 1column.phtml template file:
<body<?php echo $this->getBodyClass()?' class="'.$this->getBodyClass().'"':'' ?>>
<?php echo $this->getChildHtml('after_body_start') ?>
<div class="wrapper">
<?php echo $this->getChildHtml('global_notices'); ?>
<pre><?php echo $this->getChildHtml('pluma'); ?></pre>
<div class="page">
<?php echo $this->getChildHtml('header') ?>
<div class="main-container col1-layout">
<div class="main">
<?php echo $this->getChildHtml('breadcrumbs') ?>
<div class="col-main">
<?php echo $this->getChildHtml('global_messages') ?>
<?php echo $this->getChildHtml('content') ?>
</div>
</div>
</div>
<?php echo $this->getChildHtml('footer_before') ?>
<?php echo $this->getChildHtml('footer') ?>
<?php echo $this->getChildHtml('global_cookie_notice') ?>
<?php echo $this->getChildHtml('before_body_end') ?>
</div>
</div>
<?php echo $this->getAbsoluteFooter() ?>
</body>
And this is my template file (very simple):
<h1 style="background-color:yellow">Hello New Reference!</h1>
Magento response only "empty" tags. I don't understand my error..
Thanks in advance..
Try to use .phtml (default template files for magento) file instead of .html :
<layout version="0.1.0">
<default>
<reference name="root">
<block type="core/template" name="pluma" as="pluma" template="pluma/helloworld/simple_page.phtml"/>
</reference>
</default>
Also make sure you change the name in pluma/helloworld : simple_page.html -> simple_page.phtml

Custom currency switcher in Magento header vanished?

I built a custom currency switcher for my header yesterday, all working well. Today I came to setup the catalog pages and found myself needing to remove the standard currency switcher in the left column, I opened up my local.xml and add a remove to currency. Silly choice perhaps, I managed after fiddleing to get the left.currency to be removed when i suddenly noticed something I had done in one of my files had stopped my header custom currency switcher from displaying.
local.xml
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<default>
<!-- Remove callouts and rarely used stuff -->
<remove name="right.poll"/>
<remove name="right.permanent.callout"/>
<remove name="left.permanent.callout"/>
<remove name="paypal.partner.right.logo"/>
<remove name="catalog.compare.list" />
<!-- add the local stylesheet -->
<reference name="head">
<action method="addCss"><stylesheet>css/smoothness/jquery-ui-1.10.1.custom.css</stylesheet></action>
<action method="addJs"><script>ahoy/jquery-1.9.1.js</script></action>
<action method="addJs"><script>ahoy/jquery-ui-1.10.1.custom.js</script></action>
<action method="addJs"><script>ahoy/script.js</script></action>
<action method="addCss"><stylesheet>css/1140.css</stylesheet></action>
<action method="addCss"><stylesheet>css/ahoy.css</stylesheet></action>
</reference>
<reference name="header">
<block type="template/currency" name="custom_currency_selector" template="currency/currency.phtml"/>
</reference>
</default>
<catalog_category_view>
<reference name="root">
<action method="setTemplate"><template>page/2columns-left.phtml</template></action>
</reference>
</catalog_category_view>
First part of header.phtml
<div class="header">
<div class="row">
<div class="row">
<div class="sixcol">
<?php echo $this->getChildHtml('topLinks') ?>
<?php echo $this->getChildHtml('custom_currency_selector') ?>
</div>
<div class="sixcol last">
<div class="row">
test/default/template/currency/currency.phtml
<?php if($this->getCurrencyCount() > 1): ?>
<div class="currency-block">
<ul>
<?php foreach ($this->getCurrencies() as $_code => $_name): ?>
<?php $active = ($_code==$this->getCurrentCurrencyCode()) ? "active":""; ?>
<li>
<a class="<?php echo $active; ?>" href="<?php echo $this->getSwitchCurrencyUrl() . "currency/" . $_code; ?>" title="Set <?php echo $_code; ?> as your chosen currency">
<?php echo Mage::app()->getLocale()->currency($_code)->getSymbol(); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
From what I remember this is all I need to create the block, assign its position and call it out. I've been clearing the cache constantly while fiddeling, I reloaded in the currency conversion data, removed and retested the "remove" in local that removed the left bars currency, that one has now come back after i removed the remove for left.currency but the top one never came back.
These are my current files, so no removes at all for currency now, I'm not sure when this vanished but I've only been playing with the left sidebar stuff, after css struggles i tried to remove the currency and as i did not know how to reference it tried killing off all currency i could find and when i twigged i was no longer sure when i removed the top currency.
Try changing type="template/currency" to type="directory/currency"

Moving Magento Advanced Search Link From Footer To Beneath Search Bar

I'm trying to move magentos advanced search link from the footer links right beneath the search bar.
I know that the origins of the link are in layout/catalogsearch.xml under
reference name="footer_links" and appear in the footer because of getChildHtml('footer_links') in footer.phtml
And i know that the search bar originates from template/catalogsearch/form.mini.phtml and appears though catalogsearch.xml under reference name="top.menu"
Any ideas on how to proceed here?
thank you for the quick answer!
But it is not exactly what I was looking for as it would display the entire footer links block beneath the searchbar.
Nevertheless thank you for showing me the method you used for that!
Anyways, I figured out a solution on my own:
I modified catalogsearch.xml:
<default>
<reference name="top.menu">
<block type="core/template" name="top.search" as="topSearch" template="catalogsearch/form.mini.phtml"/>
</reference>
<!-- add a new reference to top.search including my new adv.search block -->
<reference name="top.search">
<block type="page/template_links" name="adv.search" as="adv.search" >
<action method="addLink" translate="label title" module="catalogsearch">
<label>Advanced Search</label>
<url helper="catalogsearch/getAdvancedSearchUrl" />
<title>Advanced Search</title>
</action>
</block>
</reference>
<!-- the reference to the footer i commented out as its not longer needed; it includes advanced search and popular search terms-->
</default>
In form.mini.phtml I added a new div that calls adv.search:
</script>
<div class="adv-search"> <?php echo $this->getChildHtml('adv.search') ?> </div>
</div>
And last, in styles.css, I added some code to controll the looks of that div:
.adv-search {width:100px; height:15px; margin-top:24px; margin-left: 120px;}
.adv-search a { color:#fff; font-weight:bold; }
any additional advice is more than welcome
Cheers!
In order for this to work, you must:
1) Update your app/design/frontend/[yourtheme]/default/layout/local.xml file
2) Call the new blocks in app/design/frontend/[yourtheme]/default/template/page/html/header.phtml - this is needed because header.phtml is not a "core/text_list" block type which automatically renders its nested blocks. So we must explicitly tell Magento to render those child blocks
Your app/design/frontend/[yourtheme]/default/layout/local.xml should contain this:
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="header">
<!-- Insert cms links. No need to use <action method="insert"> as this block is not used elsewhere in layout -->
<block type="cms/block" name="top_links_cms" as="top_links_cms" before="top_links_other">
<action method="setBlockId"><block_id>footer_links</block_id></action>
</block>
<!-- Insert former footer links. -->
<action method="insert">
<!-- We must keep block name "footer_links" as it is used as a reference for adding links by other modules -->
<blockName>footer_links</blockName>
<!-- Name of the block we want to have as sibling (in order to get its position and place our block after it. See next node <after> -->
<siblingName>topSearch</siblingName>
<!-- $after param from Mage_Core_Block_Abstract::insert() is a boolean type, so its value in the XML node is [empty], 0 or 1 -->
<after>1</after>
<alias>top_links_other</alias>
</action>
</reference>
<reference name="footer">
<action method="unsetChild"><name>footer_links</name></action>
<action method="unsetChild"><name>cms_footer_links</name></action>
</reference>
</default>
</layout>
This is an updated header.phtml you can get inspiration from for your app/design/frontend/[yourtheme]/default/template/page/html/header.phtml file:
<div class="header-container">
<div class="header">
<?php if ($this->getIsHomePage()):?>
<h1 class="logo"><strong><?php echo $this->getLogoAlt() ?></strong><img src="<?php echo $this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" /></h1>
<?php else:?>
<strong><?php echo $this->getLogoAlt() ?></strong><img src="<?php echo $this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" />
<?php endif?>
<div class="quick-access">
<?php echo $this->getChildHtml('topSearch') ?>
<?php
/**
* Add other top links (footer and cms links)
*/
?>
<?php echo $this->getChildHtml('top_links_cms') ?>
<?php echo $this->getChildHtml('top_links_other') ?>
<p class="welcome-msg"><?php echo $this->getWelcome() ?> <?php echo $this->getAdditionalHtml() ?></p>
<?php echo $this->getChildHtml('topLinks') ?>
<?php echo $this->getChildHtml('store_language') ?>
</div>
<?php echo $this->getChildHtml('topContainer'); ?>
</div>
</div>
<?php echo $this->getChildHtml('topMenu') ?>

Magento: Move product filters

As default, the available product filters are displayed in the left sidebar. But I'd like to display them above the product list instead.
I simply tried to just copy the following code from /template/catalog/layer/view.phtml to /template/catalog/product/list.phtml:
<p class="block-subtitle"><?php echo $this->__('Shopping Options') ?></p>
<dl id="narrow-by-list">
<?php $_filters = $this->getFilters() ?>
<?php foreach ($_filters as $_filter): ?>
<?php if($_filter->getItemsCount()): ?>
<dt><?php echo $this->__($_filter->getName()) ?></dt>
<dd><?php echo $_filter->getHtml() ?></dd>
<?php endif; ?>
<?php endforeach; ?>
</dl>
But apparently it doesn't work that way. How should I do?
Thank you in advance!
You need to make the block (a php class) which uses the filters template a child of the class where you wish to include those filters. This is done in layout XML.
In a local.xml file in your theme's layout folder, do the following:
<?xml version="1.0" ?>
<layout>
<catalog_category_layered>
<!-- remove from left block -->
<reference name="left">
<action method="unsetChild">
<child>catalog.leftnav</child>
</action>
</reference>
<!-- add as child to product list block -->
<reference name="product_list">
<action method="insert">
<child>catalog.leftnav</child>
</action>
</reference>
</catalog_category_layered>
</layout>
using the above, you can simply call <?php echo $this->getChildHtml('catalog.leftnav') ?> inside your custom list template for it to show. You can either style it using CSS, or you can change its template by adding this inside the catalog_category_layered node above:
<reference name="catalog.leftnav">
<action method="setTemplate">
<child>path/to/template.phtml</child>
</action>
</reference>

Resources