Created
October 5, 2012 16:56
-
-
Save smithweb/3840985 to your computer and use it in GitHub Desktop.
SW/Catalog/Helper/Product/View.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class SW_Catalog_Helper_Product_View extends Mage_Catalog_Helper_Product_View | |
{ | |
public function initProductLayout($product, $controller) | |
{ | |
$design = Mage::getSingleton('catalog/design'); | |
$settings = $design->getDesignSettings($product); | |
if ($settings->getCustomDesign()) { | |
$design->applyCustomDesign($settings->getCustomDesign()); | |
} | |
$update = $controller->getLayout()->getUpdate(); | |
$update->addHandle('default'); | |
$controller->addActionLayoutHandles(); | |
$update->addHandle('PRODUCT_TYPE_' . $product->getTypeId()); | |
//SW - get attribute set name | |
$attributeSetModel = Mage::getModel("eav/entity_attribute_set"); | |
$attributeSetModel->load($product->getAttributeSetId()); | |
$attributeSetName = $attributeSetModel->getAttributeSetName(); | |
//SW - add layout handle for attribute set name | |
$update->addHandle('PRODUCT_ATTRIBUTE_SET_'.$attributeSetName); | |
$update->addHandle('PRODUCT_' . $product->getId()); | |
$controller->loadLayoutUpdates(); | |
// Apply custom layout update once layout is loaded | |
$layoutUpdates = $settings->getLayoutUpdates(); | |
if ($layoutUpdates) { | |
if (is_array($layoutUpdates)) { | |
foreach($layoutUpdates as $layoutUpdate) { | |
$update->addUpdate($layoutUpdate); | |
} | |
} | |
} | |
$controller->generateLayoutXml()->generateLayoutBlocks(); | |
// Apply custom layout (page) template once the blocks are generated | |
if ($settings->getPageLayout()) { | |
$controller->getLayout()->helper('page/layout')->applyTemplate($settings->getPageLayout()); | |
} | |
$currentCategory = Mage::registry('current_category'); | |
$root = $controller->getLayout()->getBlock('root'); | |
if ($root) { | |
$controllerClass = $controller->getFullActionName(); | |
if ($controllerClass != 'catalog-product-view') { | |
$root->addBodyClass('catalog-product-view'); | |
} | |
$root->addBodyClass('product-' . $product->getUrlKey()); | |
if ($currentCategory instanceof Mage_Catalog_Model_Category) { | |
$root->addBodyClass('categorypath-' . $currentCategory->getUrlPath()) | |
->addBodyClass('category-' . $currentCategory->getUrlKey()); | |
} | |
} | |
return $this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment