cart.phtml override issue - magento

I am trying to override cart.phtml from checkout\cart.phtml using local.xml
<layout version="0.1.0">
<checkout_cart_index translate="label">
<reference name="checkout.cart">
<action method="setTemplate"><template>test/cart.phtml</template></action>
</reference>
</checkout_cart_index>
</layout>
override works fine but when i try to empty cart it always call my cart.phtml instead of checkout\cart\noItems.phtml.
when my cart is empty then it looks like
Any help will be appreciated
Thank you

Take a look at the original checkout.xml
<block type="checkout/cart" name="checkout.cart">
<action method="setCartTemplate"><value>checkout/cart.phtml</value></action>
<action method="setEmptyTemplate"><value>checkout/cart/noItems.phtml</value></action>
It has 2 template methods - setCartTemplate and setEmptyTemplate. Add these methods and you should be golden.

The chosen answer by PixieMedia will not work as is. It is missing the essential method call: chooseTemplate. Without it the answer will not work. Read https://stackoverflow.com/a/33875491/2973534 for a thorough explanation; that post contains the proper answer.

Related

Magento: Append block to before_body_end

I'm wondering why the method given here https://magento.stackexchange.com/a/3471 doesn't work for the xml block <reference name="before_body_end"/>?
I know the block type for before_body_end is core/text_list but Mage_Core_Block_Text still inherits Mage_Core_Block_Abstract which has the append method, so my understanding of Magento is that it should work, but I'm obviously missing something here?
EDIT:
This is an example of what is being attempted:
<block type="core/template" name="myblock" template="path/to/myblock.phtml" />
<reference name="before_body_end">
<action method="append" ifconfig="mymodule/settings/enabled">
<block>myblock</block>
</action>
</reference>

Magento template for each category/product

I need to change category and product view for each category/product, for change category list I have add into local.xml:
<layouts>
<CATEGORY_3>
<reference name="product_list">
<action method="setTemplate">
<name>catalog/product/list-1.phtml</name>
</action>
</reference>
</CATEGORY_3>
</layouts>
but I don't know how to change layout from product of category_3, I try adding
<reference name="product.info">
<action method="setTemplate">
<action method="setTemplate">
<template>catalog/product/view-1.phtml</template>
</action>
</action>
</reference>
inside tag but nothing, where is the mistake?
First off, your second XML config block seems to be missing a .phtml extension inside <template></template>.
Second, your action method="setTemplate" is nested twice. Remove the first one
<reference name="product.info">
<!-- action method="setTemplate" REMOVED-->
<action method="setTemplate">
<template>catalog/product/view-1.phtml</template>
</action>
<!-- /action REMOVED-->
</reference>
Also the template you're trying to call
Additionally, Please don't do this from local.xml. You will have caching issues. I guarantee it. This is probably one of the reasons why you're not seeing changes. We did a similar thing last month and it bit us in the arse.
Instead go to Catalog > Manage Categories > (Click on/Select a Category) > Custom Design Tab and then enter your XML layout changes at the Custom Layout Update box. This worked for us better and thus it might give you a better chance of success, too.

What is preventing my layout updates from being displayed

I am trying to display a simple message on my Magento site using a special block that I have created. I have been able to easily unset blocks and insert them in other places on the home page, but I am running into trouble when I try to do the same thing on one of the product pages. I have created a file at app/design/frontend/base/default/layout/packagename/modulename.xml
with the following contents:
<?xml version="1.0"?>
<layout>
<default>
<reference name="product.info">
<block type="core/text" name="free_shipping">
<action method="setText"><text><![CDATA[<div>Free Shipping!</div>]]> </text></action>
</block>
</reference>
<reference name="header">
<action method="unsetChild">
<name>top.search</name>
</action>
</reference>
</default>
</layout>
It seems to me like the code above would remove the search bar from a product page and add a block in the product info section that says "Free shipping!" but when I load the page there are no changes. I have tried using "remove" to alter some of the blocks on the page and it works, so the file is definitely being loaded into the layout.xml. I have also tried making my changes in the local.xml file instead, with the same results. Other than that, I am kind of at a loss for things to try to get this to work correctly.
Edit: To provide some more information on the problem, if I were to replace my changes with something like
<reference name="root">
<action method="unsetChild">
<name>header</name>
</action>
</reference>
The header is sucessfully removed. So I guess the question now is, why does calling unset child work as expected when used on the "root" block but not on "header"?
I think you need to be more specific with your layout handler, you are setting it as and that means all pages, i recommend you change that handler by
<?xml version="1.0"?>
<layout>
<catalog_product_view>
<reference name="product.info">
<block type="core/text" name="free_shipping">
<action method="setText"><text><![CDATA[<div>Free Shipping!</div>]]> </text></action>
</block>
</reference>
<reference name="product.info">
<block name="header">
<action method="unsetChild">
<name>top.search</name>
</action>
</block>
</reference>
</catalog_product_view>
</layout>
Greetings.
First of all, never put your stuff in the base/default folder.
On to your question. What if you try it like this:
<reference name="header">
<action method="unsetChild">
<name>top.search</name>
</action>
</reference>
To answer your other question:
The header is sucessfully removed. So I guess the question now is, why does calling unset child work as expected when used on the "root" block but not on "header"?
It's not the fact it's on the root block, it's that you should use unsetChild within the <reference/> part.

Updating custom block in CMS page

I'm having a bit of trouble understanding how to update a custom block that I include in a CMS page.
I am using the standard shortcode in the CMS page, which works fine:
{{block type="catalog/product_list" category_id="16"
template="catalog/product/slider_list.phtml"}}
I am trying to set the column count of this custom custom block, for which I've found that I need something like the following piece of code:
<block type="catalog/product_list" name="catalog.product.slider_list"
template="catalog/product/slider_list.phtml">
<action method="setColumnCount"><columns>4</columns></action>
</block>
I'm not exactly sure under which <reference /> block I should place the code... I looked in catalog.xml, and if I try to place it between <reference name="root" />, I do not get the correct behavior.
Thank you.
Edit: use of incorrect terminology; I was calling the block static, where in fact it is a custom block.
if you want to call it on home page where the reference name should be like in your local.xml or any of the xml of your extension. just add it like below
<cms_index_index>
<reference name="content">
// your custom block
<block type="catalog/product_list" name="catalog.product.slider_list"
template="catalog/product/slider_list.phtml">
<action method="setColumnCount"><columns>4</columns></action>
</block>
</reference>
</cms_index_index>
hope this will sure help you.

Magento: Change the block template in local.xml

I would like the product reviews page to use a different template instead of:
catalog/product/view.phtml
In review.xml, I see the file being called:
<block type="review/product_view" name="product.info" template="catalog/product/view.phtml">
Is there a way I can override that in local.xml and create a new file (ex: view2.phtml) and use that for this page?
<review_product_list>
<reference name="product.info">
<action method="setTemplate"><template>catalog/product/view2.phtml</template></action>
</reference>
</review_product_list>
Yes, you can definitely do that by writing the following code in local.xml:-
<reference name="product.info">
<action method="setTemplate"><template>catalog/product/view2.phtml</template></action>
</reference>
Here view2.phtml is your new file in the proper folder structure.
Hope it helps.

Resources