I'm experiencing a weird issue: Let's say category A has a custom design. When I open the product via domain.com/category-a/product.html the custom design applies correctly.

But when I open the product through Magento's canonical/Google sitemap url domain.com/product.html the custom design won't apply.

How can I bypass that behaviour? I suppose that's because Magento doesn't know which category's custom design to apply as a product can have more than one category?

Layout structure is:

  • custom design
  • -> default
  • -> category_custom

The product page is rendered from Mage_Catalog_Helper_Product_View::prepareAndRender(). This method takes into account the current category by calling Mage_Catalog_Helper_Product_View::initProduct() in this piece of code:

$categoryId = $params->getCategoryId(); 
if ($categoryId) {
    $category = Mage::getModel('catalog/category')->load($categoryId);
    Mage::register('current_category', $category);

So the flow is something like this:

  1. init the product with its options (including category id)
  2. Render the product based on the result of init.

You can try to add some logic in the init phase to specify the category.
At the end if the initProduct method, this event is dispatched.

Mage::dispatchEvent('catalog_controller_product_init', array('product' => $product)); 

You can create an observer on this and set the product category (something similar to the code above) and the rendering part should take into account your category.

  • What am I doing wrong? I hardcoded for now the category id but seems that still doesn't work. public function setProductCategory(Varien_Event_Observer $observer) { $categoryId = 39; //echo $categoryId;die; if ($categoryId) { $category = Mage::getModel('catalog/category')->load($categoryId); $observer->setCategory($category); } } – Denisa Oct 9 '14 at 19:40
  • Mage::register('current_product', $observer); if I also try to do this I get 404 not found..I am missing something but I don't know what – Denisa Oct 9 '14 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.