Magento: How to enable/disable module output per website level? - magento

I would like to display an image in the onepage checkout payment methods section that would only show up in one of two website levels. So I have three questions:
1) Am I correct to assume this change would be coded in app/design/frontend/default/mytheme/layout/checkout.xml ?
2) if that is the correct file, what would the change be from:
<!--
One page checkout payment methods block
-->
<checkout_onepage_paymentmethod>
<remove name="left"/>
<block type="checkout/onepage_payment_methods" name="root" output="toHtml" template="checkout/onepage/payment/methods.phtml">
<action method="setMethodFormTemplate"><method>purchaseorder</method><template>payment/form/purchaseorder.phtml</template></action>
</block>
</checkout_onepage_paymentmethod>
in order to point to, for example, checkout/onepage/payment/methods-site2.phtml when site2 is being used?
3) Is this the proper way to do this in 1.5.x ?

Yes
You need add STORE_[your_store_code] handle and put there this store specific stuff. More info you can read in this article.
So, in your case, you need update block with name root. To change block template you need some method for this, let's say its name is setTemplate. So, in your layout update file you should write
<STORE_your_code>
<reference name="root">
<action method="setTemplate"><template>checkout/onepage/payment/methods-site2.phtml</template></action>
<block type="my_cool/block" name="my_cool_block">
...
</block>
</reference>
</STORE_your_code>
3. Yes, adding store specific handle to your theme layout update file is the right way for magento CE 1.5.x.

Related

Vote and Compare Blocks need to be taken out in magento

I have some troubles in /checkout/cart page with taking out two blocks:
- compare products block
- voting block
I cant remove them from right sidebar
at current layout xml
/layout/checkout.xml
There is only MY ONE adding template to right sidedar
<reference name="right">
my adding template code here
</reference>
also I have just removed all adding templates to right sidebar from
/layout/page.xml
and as a result I see these two blocks (compare and voting) at right bar anyway (
Let me know where can They be removed by me from ?
Thanks
I hope you're using local.xml to do your customizations.
In local.xml
<default>
<!--other codes-->
<remove name="catalog.compare.sidebar" />
<remove name="right.poll" />
<!--other codes-->
</default>
if need to remove from checkout - cart page only and retain on other pages then use <checkout_cart_index> handler instead of and use "unSetChild". Remember <remove> will completely remove the block.
I found out where was problem )
Magento layouts include one of this
/layout/poll.xml
and There I saw these lines
<!-- Mage_Poll -->
<reference name="right">
<block type="poll/activePoll" name="right.poll">
<action method="setPollTemplate"><template>poll/active.phtml</template><type>poll</type></action>
<action method="setPollTemplate"><template>poll/result.phtml</template><type>results</type></action>
</block>
</reference>
</default>
after commented it They disappeared )

How can i add a new tab in left in sales order view,like now are invoices credit memos,releases etc in magento

i want to add a new tab in left in sales->order->view.For this i have created a module but not solved my problem,it is showing an error like wrong tab configuration,i have search on many links also posted in stack overflow,but not yet satisfied.
Thanks
This actually should be quite easy to do. Just look at the app/design/adminhtml/default/default/layout/sales.xml layout file. You can find there the <adminhtml_sales_order_view> node, which defines all blocks used on order's view page.
In order to add a new tab, you would need to put another <action> declaration in the file. Currently tabs are defined like this (Magento EE 1.11):
<adminhtml_sales_order_view>
(...)
<reference name="left">
<block type="adminhtml/sales_order_view_tabs" name="sales_order_tabs">
<action method="addTab"><name>order_info</name><block>order_tab_info</block></action>
<action method="addTab"><name>order_invoices</name><block>adminhtml/sales_order_view_tab_invoices</block></action>
<action method="addTab"><name>order_creditmemos</name><block>adminhtml/sales_order_view_tab_creditmemos</block></action>
<action method="addTab"><name>order_shipments</name><block>adminhtml/sales_order_view_tab_shipments</block></action>
<action method="addTab"><name>order_history</name><block>adminhtml/sales_order_view_tab_history</block></action>
<action method="addTab"><name>order_transactions</name><block>adminhtml/sales_order_view_tab_transactions</block></action>
</block>
</reference>
</adminhtml_sales_order_view>
Be aware, do not change core templates!
In this case you should create new module or alter existing one in local code pool. Define a layout updates in config.xml and then create new layout file in adminhtml default theme, for example:
app/design/adminhtml/default/default/layout/CUSTOM_VENDOR/sales.xml:
<adminhtml_sales_order_view>
<reference name="sales_order_tabs">
<action method="addTab"><name>TAB_NAME</name><block>CUSTOM_BLOCK</block></action>
</reference>
</adminhtml_sales_order_view>
Then you just need to create new block and a template.

How can I display a magento block in more than one location?

I'm trying to display the cross sell block in it's normal location as well as at the bottom of the page. There is more than one phtml template file involved so $this->getChildHtml does not work in the second location since the block is setup to only be on the cart.phtml file as of now.
In summary, how can I display the same block in more than one template file? I wan't to place these changes in my local.xml and do not want to modify core Magento template files.
The core layout directive for this block is set up as a child of the checkout.cart block:
<checkout_cart_index translate="label">
<!-- ... -->
<reference name="content">
<block type="checkout/cart" name="checkout.cart">
<!-- ... -->
<block type="checkout/cart_crosssell" name="checkout.cart.crosssell" as="crosssell" template="checkout/cart/crosssell.phtml"/>
</block>
</reference>
</checkout_cart_index>
To add it to the footer, you might need to only establish another parent-child relationship in your local.xml:
<checkout_cart_index>
<reference name="footer">
<action method="insert"><!-- or "append" to add to the end -->
<child>checkout.cart.crosssell</child>
</action>
</reference>
</checkout_cart_index>
This approach relies on the stock page/html/footer.phtml template which contains an empty getChildHtml() call, which causes it to render all child blocks.
Note that the footer block class Mage_Page_Block_Html_Footer has a never-expiring block_html cache lifetime, and it does not evaluate child contents for its cache entry. You may need to disable the cache for this block or rewrite the block class to account for the varied content of the crosssell block.

Adding image in Magento via update layout

I'm trying to figure out how to add images, etc. to the left sidebar portion of a 2 column with left sidebar page in Magento using the layout update in the cms ->page->design portion of the admin area.
Is it possible to do this from the update layout xml area? If not, could you explain how to create a module (or whatever else would be required).
Thanks.
If you look in base/default/layout/catalog.xml, you will see an example of using a template with an image placeholder that can be specified in your Update Layout XML area:
<reference name="left">
<block type="core/template" name="left.permanent.callout" template="callouts/left_col.phtml">
<action method="setImgSrc"><src>images/media/col_left_callout.jpg</src></action>
<action method="setImgAlt" translate="alt" module="catalog"><alt>Our customer service is available 24/7. Call us at (555) 555-0123.</alt></action>
<action method="setLinkUrl"><url>checkout/cart</url></action>
</block>
</reference>
So, in your Update Layout XML, you would write something like:
<reference name="left.permanent.callout"> <!-- match this to the block name from above -->
<action method="setImgSrc"><src>images/media/my_file_name.jpg</src></action>
<action method="setImgAlt" translate="alt" module="catalog"><alt>Some text here</alt></action>
<action method="setLinkUrl"><url>your/path</url></action>
</reference>
You can adapt that by taking a copy of the template file left_col.phtml and making changes as you wish.

Magento - use an alternate "price.phtml" (in addition to the existing one)

I am looking for a way to have an alternate template/catalog/product/price.phml used in one specific location, and to continue using the existing price.phtml file in all other locations.
To explain further, I need to display the regular price, and then another special price right below it - but only on the product page (for the main product being displayed). This special price is not a price that can be calculated by the catalog price rules, so I wrote my own module to do the calculation. So, everywhere that I am displaying prices I want to display with the regular ol' template/catalog/product/price.phtml file... but for the product page (the main product - not the related, upsells, etc) I want to use my own custom template/catalog/product/price-custom.phtml template file. Can anybody help?
Normally I just look in the layout xml files (for example catalog.xml) to find these types of things, but price.phtml is kinda special - it isn't that simple. And for the life of me I can't figure out if there is an easy way to swap it out conditionally on the page being viewed. I am aware that I can just update price.phtml to always print out this extra price, and then use css to hide the price everywhere, but I would rather not do that if possible.
(Also you may want to know that I only have simple products.)
This can be done in a layout XML file:
<layout>
<PRODUCT_TYPE_simple>
<reference name="product.clone_prices">
<action method="setTemplate">
<template>catalog/product/price-custom.phtml</template>
</action>
</reference>
</PRODUCT_TYPE_simple>
</layout>
Create a local.xml file, put it in app/frontend/default/YOURTEMPLATE/layout
In the local.xml file, add:
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<!-- Override price template on product view page -->
<PRODUCT_TYPE_simple>
<reference name="product.info.simple">
<action method="setTemplate">
<template>catalog/product/price_product_page.phtml</template>
</action>
</reference>
</PRODUCT_TYPE_simple>
<!-- /Override price template on product view page -->
</layout>
Create a copy of catalog/product/price.phtml and put it in YOURTEMPLATE/templates/product/product_price_page.phtml
This will override the price.phtml in the template, and replace it with product_price_page.phtml
Or in your php block.
See example here :
Mage_Catalog_Block_Product_Abstract
protected $_priceBlockDefaultTemplate = 'catalog/product/price.phtml';
protected $_tierPriceDefaultTemplate = 'catalog/product/view/tierprices.phtml';
I had a similar requirement recently, where a different price template for the product page was the preferred solution.
The price block appears to be something of a special case in Magento (in the RWD theme at least), it's defined in catalog.xml as simply a block type and name within the <default/> handle:
<block type="catalog/product_price_template" name="catalog_product_price_template" />
If you look around at how some core layout files set the price template, you'll find examples like this (from bundle.xml):
<reference name="catalog_product_price_template">
<action method="addPriceBlockType">
<type>bundle</type>
<block>bundle/catalog_product_price</block>
<template>bundle/catalog/product/price.phtml</template>
</action>
</reference>
They call a method called addPriceBlockType which you can find in Mage_Catalog_Block_Product_Abstract
Based on this and after a little experimentation, I found the following solution worked for me:
<catalog_product_view>
<reference name="product.info">
<action method="addPriceBlockType">
<type>simple</type>
<block>catalog/product_price</block>
<template>catalog/product/price_product_page.phtml</template>
</action>
<action method="addPriceBlockType">
<type>configurable</type>
<block>catalog/product_price</block>
<template>catalog/product/price_product_page.phtml</template>
</action>
<!-- Set for each product type as necessary e.g. bundled, virtual etc... -->
</reference>
</catalog_product_view>
The proper way to achieve it :
<PRODUCT_TYPE_simple>
<reference name="product.info.simple">
<action method="addPriceBlockType"><type>simple</type><block>catalog/product_price</block><template>catalog/product/price-product-page.phtml</template></action>
</reference>
</PRODUCT_TYPE_simple>
<PRODUCT_TYPE_configurable>
<reference name="product.info.configurable">
<action method="addPriceBlockType"><type>configurable</type><block>catalog/product_price</block><template>catalog/product/price-product-page.phtml</template></action>
</reference>
</PRODUCT_TYPE_configurable>
...

Resources