Last active
August 4, 2016 00:29
-
-
Save tuanphpvn/e1cb798df2129707bca0 to your computer and use it in GitHub Desktop.
Add display setting for category #Magento #Category #DisplaySettings
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 | |
| /** | |
| * RootCategoryName is the name of root for store. | |
| * Level: Level 1 child of root, Level2 child of level 1, Level is relative with rootCategoryLevel | |
| * Display Mode: | |
| * | |
| * @param $rootCategoryName | |
| * @param $level | |
| * @param $displayMode | |
| * @param $pageLayout | |
| * @return string | |
| */ | |
| $changeDisplaySettingAndCustomDesignOfLevel1Category = function($rootCategoryName, $level, $arrDisplaySettings, $arrCustomDesign) { | |
| $rootCategoryObj = Mage::getModel('catalog/category')->loadByAttribute('name', $rootCategoryName); | |
| $rootCategoryLevel = $rootCategoryObj->getLevel(); | |
| $collection = Mage::getModel('catalog/category') | |
| ->getCollection() | |
| ->addPathsFilter($rootCategoryObj->getPath().'/'); | |
| $arr = array(); | |
| foreach($collection as $catObj) { | |
| $catLevel = $catObj->getLevel(); | |
| if(($catLevel - $rootCategoryObj) == $level) { | |
| // set attribute Display Settings | |
| foreach($arrDisplaySettings as $key => $value) { | |
| $catObj->setData($key, $value); | |
| } | |
| // set attribute in Custom Design | |
| foreach($arrCustomDesign as $key => $value) { | |
| $catObj->setData($key, $value); | |
| } | |
| $catObj->save(); | |
| } | |
| } | |
| return implode(",", $arr); | |
| }; | |
| $changeDisplaySettingAndCustomDesignOfLevel1Category('AcerEMEA Root', 1, | |
| array( | |
| 'display_mode' => 'PRODUCTS' | |
| ), | |
| array( | |
| 'page_layout' => 'two_columns_right', | |
| ) | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment