Monday , December 11 2017
Home >> All tutorial >> How to use Magento`s category or product design programmatically?

How to use Magento`s category or product design programmatically?

I needed to load a block using AJAX request on catalog/category page. There is no problem to pass the category ID of the current category, but how can i load category’s design? Today we will find the way to solve this problem by this Magento tutorials.
During my research app/core/Mage/Catalog files I found a simple solution:

{code type=html}$category = Mage::getModel(‘catalog/category’)->load($categoryId);
if ($category->getId() && $category->getCustomDesign()) {
Mage::getModel(‘catalog/design’)
->applyDesign($category, Mage_Catalog_Model_Design::APPLY_FOR_CATEGORY);
}{/code}

The main purpose of model catalog/design is to apply category`s or product`s design to current design. If you want to apply product`s design, you must use Mage_Catalog_Model_Design::APPLY_FOR_PRODUCT as the second parameter and Mage_Catalog_Model_Product object as the first one. For example:

{code type=html}$product = Mage::getModel(‘catalog/product’)->load($productId);
if ($product->getId() && $product->getCustomDesign()) {
Mage::getModel(‘catalog/design’)
->applyDesign($product, Mage_Catalog_Model_Design::APPLY_FOR_PRODUCT);
}{/code}

Hope it help you all!

We also contribute great content of Magento Download for FREE (all versions)

DON'T MISS THE CHANCE!

magento download

About Champ

Leave a Reply

Your email address will not be published. Required fields are marked *

Heap | Mobile and Web Analytics