Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

[SOLVED] Category custom layout update “apply to” bug (missing feature). 
 
tgv
Jr. Member
 
Total Posts:  11
Joined:  2009-01-29
Perth, WA
 

Hi all,

My goal is to apply a custom layout update to a category that will change underlying products template appearance (to list recipes as a products, with all upsell etc. features but with cart/wishlist/price controls removed). Xml code is pretty straightforward:

<reference name="product.info">
<
action method="setTemplate">
<
template>catalog/product/recipe.phtml</template>
</
action>
</
reference>

The “Custom layout update” thing works well if applied to an individual product. It works well for a category if applied to a category. It doesn’t work for the products in the “customised” category at all no matter what “Apply to” option is selected.

I crush-tested this feature by inserting deliberately broken xml into category’s “custom layout update” and applying it to “this category and its products”: category page gets error, product is fine—so I’m pretty sure the update in fact wasn’t applied to category’s children.

I couldn’t find any checks of this setting in product page rendering code (maybe I just didn’t search good enough, it’s quite a mess).

So my question addressed to my dear developers team is what’s wrong here, and to save time you can just choose from the answers I consider possible:

a. “Apply to” isn’t supposed to work with XMLs, so your only way is to paste that code to all 100000000 products.
b. “Apply to” isn’t supposed to work at all, we just forgot to remove it in public release.
c. It’s a bug and we gonna fix it. Thanks for finding it, we’ll let you know when it’s done.
d. Doh!

 
Magento Community Magento Community
Magento Community
Magento Community
 
tgv
Jr. Member
 
Total Posts:  11
Joined:  2009-01-29
Perth, WA
 

Claimed it, fixed it.

Here is the solution (some may call it a hack, whatever).

grab this file: /app/code/core/Mage/Catalog/controllers/ProductController.php

find the function _initProductLayout($product) around line 88

change the code between $this->loadLayoutUpdates(); and if ($root = $this->getLayout()->getBlock(’root’)) { lines this way:

$currentCategory Mage::registry('current_category');
        
if (
$currentCategory->getCustomLayoutUpdate() && in_array((int)$currentCategory->getCustomDesignApply(),array(1,3))) $update->addUpdate($currentCategory->getCustomLayoutUpdate());

$update->addUpdate($product->getCustomLayoutUpdate());
$this->generateLayoutXml()->generateLayoutBlocks();

That’s it (it won’t check higher levels of categories as I don’t need it right now).

Dear developers team, I would still really appreciate if you actually answer the question above, thank you.

And thank you so much for the carefully commented code, it helps a lot.

(And don’t even think of not including my fix in the next release)

Cheers

 
Magento Community Magento Community
Magento Community
Magento Community
 
Paaaaa
Member
 
Total Posts:  50
Joined:  2008-10-30
 

Oh, thank You for the hack. Searched all over the forum. Strange, as this feature should work with magento out of the box. But its not..
Again thanks! smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
mattimck
Jr. Member
 
Total Posts:  2
Joined:  2009-01-06
 

I tried to use this fix today, but recieved the following error once I loaded a product page:

Fatal errorCall to a member function getCustomLayoutUpdate() on a non-object in /home/indexcon/public_html/magento/app/code/core/Mage/Catalog/controllers/ProductController.php on line 109

Any ideas as to what I might be doing wrong?

 
Magento Community Magento Community
Magento Community
Magento Community
 
nchankov
Jr. Member
 
Total Posts:  18
Joined:  2009-02-14
 

If you move that file under appropriate directory in local repository it will use it and the core core will be unchanged.

Although I’ve checked the code and it seems that the magento team get it fixed.

 
Magento Community Magento Community
Magento Community
Magento Community
 
trexr
Jr. Member
 
Total Posts:  3
Joined:  2009-04-01
 

Has anyone else had any luck with fixing this bug? 

I’m using 1.3.2.2 with the blank theme and the fix above does not seem to affect the individual products of the categories no matter what “Apply to” setting I have saved.

Like tgv stated, the layout updates work fine for individual products but do nothing when applied at the category level.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top