/** * Apply category filter to layer * * @param Zend_Controller_Request_Abstract $request * @param Mage_Core_Block_Abstract $filterBlock * @return Mage_Catalog_Model_Layer_Filter_Category */ public function apply(Zend_Controller_Request_Abstract $request, $filterBlock) { $filter = (int) $request->getParam($this->getRequestVar()); if (!$filter) { return $this; } // load data for applied category $this->_appliedCategory = Mage::getModel('catalog/category')->setStoreId(Mage::app()->getStore()->getId())->load($filter); if ($this->_appliedCategory->getId()) { // create join and conditions for additional category filter $tableAlias = 'category_layered_' . $this->_rootCategory->getId(); $conditions = array(); $conditions['category_id'] = $filter; $conditions['store_id'] = Mage::app()->getStore()->getId(); if (!$this->_appliedCategory->getIsAnchor()) { $conditions['is_parent'] = 1; } $this->getLayer()->getProductCollection()->joinTable(array($tableAlias => 'catalog/category_product_index'), "product_id=entity_id", array($tableAlias . '_cat_id' => 'category_id', $tableAlias . '_store_id' => 'store_id'), $conditions, 'inner'); // add filter to layer state $this->getLayer()->getState()->addFilter($this->_createItem($this->_appliedCategory->getName(), $filter)); // if current applied category has no children reset items array (for hiding filter block) if (!$this->_appliedCategory->getChildrenCategories()) { $this->_items = array(); } } return $this; }
/** * Search category by the name from root category or specified one. * Create category when it doesn't exist if $createIfNotExists * parameter is set. * Search category by store-specific name if $store parameter is set. * * @param string $name * @param bool $createIfNotExists * @param Mage_Catalog_Model_Category $parent * @param null|Mage_Core_Model_Store $store * * @return Mage_Catalog_Model_Category|null */ public function getCategory($name, $createIfNotExists = false, $parent = null, $store = null) { $store = $store instanceof Mage_Core_Model_Store ? $store : Mage::app()->getStore(); $collection = $parent && ($parentId = $parent->getId()) ? $parent->setStoreId($store->getId())->getCollection()->addFieldToFilter('parent_id', $parentId) : Mage::getModel('catalog/category')->setStoreId($store->getId())->load($store->getRootCategoryId())->getCollection(); $collection->addAttributeToFilter('name', $name); if ($collection->count()) { return $collection->getFirstItem(); } if (!$createIfNotExists) { return; } if ($parent && $parent->getId()) { $rootCategory = $parent; } else { $collection = Mage::getModel('catalog/category')->getCollection()->addAttributeToFilter('parent_id', 1); if (count($collection) != 1) { return null; } $rootCategory = $collection->getFirstItem(); if (!$rootCategory->getId()) { return null; } } $model = Mage::getModel('catalog/category'); $model->setStoreId($rootCategory->getStoreId())->setData(array('name' => $name, 'is_active' => 1, 'include_in_menu' => 1))->setPath($rootCategory->getPath())->setAttributeSetId($model->getDefaultAttributeSetId()); try { $model->save(); } catch (Exception $e) { return null; } return $model; }
/** * @param Mage_Catalog_Model_Category $category * @param int $level * @return string */ public function drawOpenCategoryItem($category, $level = 0) { if ($this->_isExcluded($category->getId()) || !$category->getIsActive() || !$category->getIncludeInMenu()) { return ''; } $cssClass = array('amshopby-cat', 'level' . $level); $currentCategory = $this->getDataHelper()->getCurrentCategory(); if ($currentCategory->getId() == $category->getId()) { $cssClass[] = 'active'; } if ($this->isCategoryActive($category)) { $cssClass[] = 'parent'; } if ($category->hasChildren()) { $cssClass[] = 'has-child'; } $productCount = ''; if ($this->showProductCount()) { $productCount = $category->getProductCount(); if ($productCount > 0) { $productCount = ' <span class="count">(' . $productCount . ')</span>'; } else { $productCount = ''; } } $html = array(); $html[1] = '<a href="' . $this->getCategoryUrl($category) . '">' . $this->htmlEscape($category->getName()) . $productCount . '</a>'; $showAll = Mage::getStoreConfig('amshopby/advanced_categories/show_all_categories'); $showDepth = Mage::getStoreConfig('amshopby/advanced_categories/show_all_categories_depth'); $hasChild = false; $inPath = in_array($category->getId(), $currentCategory->getPathIds()); $showAsAll = $showAll && ($showDepth == 0 || $showDepth > $level + 1); if ($inPath || $showAsAll) { $children = $this->_getCategoryCollection()->addIdFilter($category->getChildren()); $this->_addCounts($children); $children = $this->asArray($children); if ($children && count($children) > 0) { $hasChild = true; $htmlChildren = ''; foreach ($children as $child) { $htmlChildren .= $this->drawOpenCategoryItem($child, $level + 1); } if ($htmlChildren != '') { $cssClass[] = 'expanded'; $html[2] = '<ol>' . $htmlChildren . '</ol>'; } } } $html[0] = sprintf('<li class="%s">', implode(" ", $cssClass)); $html[3] = '</li>'; ksort($html); if ($category->getProductCount() || $hasChild && $htmlChildren) { $result = implode('', $html); } else { $result = ''; } return $result; }
/** * Save category - post relations * * @access public * @param Mage_Catalog_Model_Category $category * @param array $data * @return Tech_Blog_Model_Resource_Post_Category * @author Ultimate Module Creator */ public function saveCategoryRelation($category, $data) { if (!is_array($data)) { $data = array(); } $deleteCondition = $this->_getWriteAdapter()->quoteInto('category_id=?', $category->getId()); $this->_getWriteAdapter()->delete($this->getMainTable(), $deleteCondition); foreach ($data as $postId => $info) { $this->_getWriteAdapter()->insert($this->getMainTable(), array('post_id' => $postId, 'category_id' => $category->getId(), 'position' => @$info['position'])); } return $this; }
protected function exportData(Mage_Catalog_Model_Category $category, $file, $depth = 0) { $data = array('id' => $category->getId(), 'parent_id' => $category->getParentId(), 'attribute_set_id' => $category->getAttributeSetId(), 'urlPath' => $category->getUrlPath(), 'urlKey' => $category->getUrlKey(), 'path' => $category->getPath(), 'position' => $category->getPosition(), 'page_layout' => $category->getPageLayout(), 'description' => $category->getDescription(), 'display_mode' => $category->getDisplayMode(), 'is_active' => $category->getIsActive(), 'is_anchor' => $category->getIsAnchor(), 'include_in_menu' => $category->getIncludeInMenu(), 'custom_design' => $category->getCustomDesign(), 'level' => $category->getLevel(), 'name' => $category->getName(), 'metaTitle' => $category->getMetaTitle(), 'metaKeywords' => $category->getMetaKeywords(), 'metaDescription' => $category->getMetaDescription()); echo str_repeat(' ', $depth); echo '* ' . $category->getName() . sprintf(' (%s products)', $category->getProductCount()) . PHP_EOL; fputcsv($file, $data); if ($category->hasChildren()) { $children = Mage::getModel('catalog/category')->getCategories($category->getId()); foreach ($children as $child) { $child = Mage::getModel('catalog/category')->load($child->getId()); $this->exportData($child, $file, $depth + 1); } } }
/** * Check if product is inside of the category * * @param Mage_Catalog_Model_Product $product * @param Mage_Catalog_Model_Category $category * @return boolean */ private function _isProductInCategory($product, $category) { $categoryIds = $product->getCategoryIds(); $categoryId = $category->getId(); if (in_array($categoryId, $categoryIds)) { return true; } return false; }
/** * @param Mage_Catalog_Model_Category $category Will be updated according matched Page * @return bool */ protected function _isPageHandled($category) { /** @var Amasty_Shopby_Model_Mysql4_Page $pageResource */ $pageResource = Mage::getResourceModel('amshopby/page'); $page = $pageResource->getCurrentMatchedPage($category->getId()); $this->_handleCanonical($page); if (is_null($page)) { return false; } /** @var Mage_Page_Block_Html_Head $head */ $head = $this->getLayout()->getBlock('head'); // metas $title = $head->getTitle(); // trim prefix if any $prefix = Mage::getStoreConfig('design/head/title_prefix'); $prefix = htmlspecialchars(html_entity_decode(trim($prefix), ENT_QUOTES, 'UTF-8')); if ($prefix) { $title = substr($title, strlen($prefix)); } $suffix = Mage::getStoreConfig('design/head/title_suffix'); $suffix = htmlspecialchars(html_entity_decode(trim($suffix), ENT_QUOTES, 'UTF-8')); if ($suffix) { $title = substr($title, 0, -1 - strlen($suffix)); } $descr = $head->getDescription(); $kw = $head->getKeywords(); $titleSeparator = Mage::getStoreConfig('amshopby/general/title_separator'); $descrSeparator = Mage::getStoreConfig('amshopby/general/descr_separator'); $kwSeparator = ','; if ($page->getUseCat()) { $title = $title . $titleSeparator . $page->getMetaTitle(); $descr = $descr . $descrSeparator . $page->getMetaDescr(); $kw = $page->getMetaKw() . $kwSeparator . $kw; } else { $title = $page->getMetaTitle(); $descr = $page->getMetaDescr(); $kw = $page->getMetaKw(); } $head->setTitle($this->trim($title)); $head->setDescription($this->trim($descr)); $head->setKeywords($this->trim($kw)); // in-page description if ($page->getCmsBlockId()) { $this->setCategoryCmsBlock($category, $page->getCmsBlockId()); } if ($page->getBottomCmsBlockId()) { $this->addBottomCmsBlock($page->getBottomCmsBlockId()); } if ($page->getTitle()) { $category->setData('name', $page->getTitle()); } if ($page->getDescription()) { $category->setData('description', $page->getDescription()); } return true; }
/** * Check unique url_key value in catalog_category_entity_url_key table. * * @param Mage_Catalog_Model_Category $object * @return Mage_Catalog_Model_Category_Attribute_Backend_Urlkey * @throws Mage_Core_Exception */ protected function _validateEntityUrl($object) { $connection = $object->getResource()->getReadConnection(); $select = $connection->select()->from($this->getAttribute()->getBackendTable(), array('count' => new Zend_Db_Expr('COUNT(\'value_id\')')))->where($connection->quoteInto('entity_id <> ?', $object->getId()))->where($connection->quoteInto('value = ?', $object->getUrlKey())); $result = $connection->fetchOne($select); if ((int) $result) { throw new Mage_Core_Exception(Mage::helper('catalog')->__("Category with the '%s' url_key attribute already exists.", $object->getUrlKey())); } return $this; }
/** * Should return list of tags to clean * * @param Mage_Catalog_Model_Category $object * @return string[]|string */ protected function _collectTags($object) { $tags = array(self::TAG_PREFIX . $object->getId()); if ($this->_isForUpdate) { foreach ($object->getParentIds() as $categoryId) { $tags[] = self::TAG_PREFIX . $categoryId; } } return $tags; }
/** * Purge Category * * @param Mage_Catalog_Model_Category $category * @return Phoenix_VarnishCache_Model_Control_Catalog_Category */ public function purge(Mage_Catalog_Model_Category $category) { if ($this->_canPurge()) { $this->_purgeById($category->getId()); if ($categoryName = $category->getName()) { $this->_getSession()->addSuccess(Mage::helper('varnishcache')->__('Varnish cache for "%s" has been purged.', $categoryName)); } } return $this; }
/** * Returns list of subcategories recursively. * * @param Mage_Catalog_Model_Category $category * @return mixed */ protected function getSubcategories(Mage_Catalog_Model_Category $category) { if (!isset($this->subcategories[$category->getId()])) { $list = array(); $categories = $category->getChildrenCategories(); $this->getAllChildCategories($categories, $list); $this->subcategories[$category->getId()] = $list; } return $this->subcategories[$category->getId()]; }
/** * Get products count in category * * @param Mage_Catalog_Model_Category $category * @return integer */ public function getProductCountExcludeOutStock($category) { $read = $this->_getReadAdapter(); $store_data = Mage::getModel('core/store')->load($category->getStoreId()); //load store object $website_id = $store_data->getWebsiteId(); //get website id from the store $select = $read->select()->from(array('main_table' => $this->getTable('catalog/category_product')), "COUNT(main_table.product_id)")->joinLeft(array('stock' => $this->getTable('cataloginventory/stock_status')), 'main_table.product_id=stock.product_id AND ' . $read->quoteInto('stock.website_id=? ', $website_id), array())->where("main_table.category_id = ?", $category->getId())->where("round(stock.qty) > 0 ")->where("stock.stock_status = ? ", 1)->group("main_table.category_id"); //echo $select->__toString(); exit; return (int) $read->fetchOne($select); }
/** * @param Mage_Catalog_Model_Category $category * @return Mage_Catalog_Model_Category */ public function getFirstLevelCategory($category) { if (!isset($this->_firstLevelCategories[$category->getId()])) { $rootId = Mage::app()->getStore()->getRootCategoryId(); $id = $rootId; $rootFound = false; foreach ($category->getPathIds() as $pathId) { if ($rootFound) { $id = $pathId; break; } else { if ($pathId == $rootId) { $rootFound = true; } } } if ($id == $category->getId()) { $this->_firstLevelCategories[$category->getId()] = $category; } elseif ($id == $rootId) { $this->_firstLevelCategories[$category->getId()] = $this->getRootCategory(); } else { $this->_firstLevelCategories[$category->getId()] = Mage::getModel('catalog/category')->setStoreId(Mage::app()->getStore()->getId())->load($id); } } return $this->_firstLevelCategories[$category->getId()]; }
/** * Load url rewrite based on specified category * * @param Mage_Core_Model_Abstract $object * @param Mage_Catalog_Model_Category $category * @return Enterprise_Catalog_Model_Resource_Category */ public function loadByCategory(Mage_Core_Model_Abstract $object, Mage_Catalog_Model_Category $category) { $idField = $this->_getReadAdapter()->getIfNullSql('url_rewrite_cat.id', 'default_urc.id'); $requestPath = $this->_getReadAdapter()->getIfNullSql('url_rewrite.request_path', 'default_ur.request_path'); $select = $this->_getReadAdapter()->select()->from(array('main_table' => $this->getTable('catalog/category')), array($this->getIdFieldName() => $idField))->where('main_table.entity_id = ?', (int) $category->getId())->joinLeft(array('url_rewrite_cat' => $this->getTable('enterprise_catalog/category')), 'url_rewrite_cat.category_id = main_table.entity_id AND url_rewrite_cat.store_id = ' . (int) $category->getStoreId(), array(''))->joinLeft(array('url_rewrite' => $this->getTable('enterprise_urlrewrite/url_rewrite')), 'url_rewrite.url_rewrite_id = url_rewrite_cat.url_rewrite_id', array(''))->joinLeft(array('default_urc' => $this->getTable('enterprise_catalog/category')), 'default_urc.category_id = main_table.entity_id AND default_urc.store_id = 0', array(''))->joinLeft(array('default_ur' => $this->getTable('enterprise_urlrewrite/url_rewrite')), 'default_ur.url_rewrite_id = default_urc.url_rewrite_id', array('request_path' => $requestPath)); $result = $this->_getReadAdapter()->fetchRow($select); if ($result) { $object->setData($result); } $this->unserializeFields($object); $this->_afterLoad($object); return $this; }
/** * Prepare category attribute html output * * @param Mage_Catalog_Model_Category $category * @param string $attributeHtml * @param string $attributeName * @return string */ public function categoryAttribute($category, $attributeHtml, $attributeName) { $isDefaultCategory = $category->getId() == Mage::app()->getStore()->getRootCategoryId(); if ($attributeName == 'name' && $isDefaultCategory) { /** @var Amasty_Shopby_Helper_Attributes $helper */ $helper = Mage::helper('amshopby/attributes'); $setting = $helper->getRequestedBrandOption(); if (is_array($setting)) { return $this->escapeHtml($setting['title']); } } return parent::categoryAttribute($category, $attributeHtml, $attributeName); }
/** * Get Category URL in a specific store * * @param Mage_Catalog_Model_Category $category * @param Mage_Core_Model_Store $store * * @return string */ public function getCategoryUrlInStore($category, $store) { if (!$store instanceof Mage_Core_Model_Store) { $store = Mage::app()->getStore($store); } $idPath = 'category/' . $category->getId(); foreach ($this->getStoreUrls($idPath) as $storeId => $url) { if ($storeId == $store->getId()) { return $url; } } return $category->getUrl(); }
/** */ private function _moveProducts() { $productSourceIds = $this->_source->getProductCollection()->setOrder('position', 'asc')->getAllIds(); $productSourceItems = array_fill_keys($productSourceIds, 1); $productInsert = array_diff_key($productSourceItems, $this->_target->getProductsPosition()); if (!empty($productInsert)) { $data = array(); foreach ($productInsert as $productId => $position) { $data[] = array('category_id' => (int) $this->_target->getId(), 'product_id' => (int) $productId, 'position' => (int) $position); } $this->_getWriteAdapter()->insertMultiple($this->_getTable(), $data); } }
/** * Retrieves product category path to active it * * @param Mage_Catalog_Model_Category $category * @param array $classes * @return array */ public function getProductCategoriesInDirectAccess($category, $classes) { $prodModel = Mage::registry('current_product'); $categories = $prodModel->getCategoryIds(); $catArray = array(); foreach ($categories as $catId) { $catModel = Mage::getModel('catalog/category')->load($catId); $catArray = array_merge_recursive($catArray, explode('/', $catModel->getPath())); } $pathAllCats = array_merge_recursive($catArray, $categories); if (in_array($category->getId(), $pathAllCats)) { $classes[] = 'active'; } return $classes; }
/** * Specify category filter for product collection * * @param Mage_Catalog_Model_Category $category * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection */ public function addCategoryFilter(Mage_Catalog_Model_Category $category) { $this->_productLimitationFilters['category_id'] = $category->getId(); if ($category->getIsAnchor()) { unset($this->_productLimitationFilters['category_is_anchor']); } else { $this->_productLimitationFilters['category_is_anchor'] = 1; } $this->_query->setQuery($this->_queryString); if ($this->getStoreId() == Mage_Core_Model_App::ADMIN_STORE_ID) { //$this->_applyZeroStoreProductLimitations(); } else { // $this->_applyProductLimitations(); } return $this; }
/** * Force the virtual rule to be loaded for a category. * * @param Mage_Catalog_Model_Category $category The category. * * @return Smile_VirtualCategories_Model_Rule */ public function getVirtualRule($category) { $virtualRule = $category->getVirtualRule(); if (!is_object($virtualRule)) { $cacheKey = $category->getId(); if ($category->getStoreId()) { $cacheKey = $cacheKey . '_' . $category->getStoreId(); } if (!isset($this->_categoryRulesCache[$cacheKey])) { $backend = Mage::getSingleton('smile_virtualcategories/category_attributes_backend_virtual'); $backend->afterLoad($category); $this->_categoryRulesCache[$cacheKey] = $category->getVirtualRule(); } $virtualRule = $this->_categoryRulesCache[$cacheKey]; } return $virtualRule; }
/** * Specify category filter for product collection * * @param Mage_Catalog_Model_Category $category * @return Mage_Catalog_Model_Resource_Product_Collection */ public function addCategoryFilter(Mage_Catalog_Model_Category $category) { $this->_productLimitationFilters['category_id'] = $category->getId(); if ($category->getIsAnchor()) { unset($this->_productLimitationFilters['category_is_anchor']); } else { $this->_productLimitationFilters['category_is_anchor'] = 1; } if ($this->getStoreId() == Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID) { //FIXME: apply no store //$this->_applyZeroStoreProductLimitations(); } else { //FIXME: apply stores //$this->_applyProductLimitations(); } return $this; }
/** * @param Mage_Catalog_Model_Category $object * @return $this|Convenient_CategoryCode_Model_Attribute_Backend_Code * * @author Luke Rodgers <*****@*****.**> */ public function beforeSave($object) { $attributeName = $this->getAttribute()->getName(); $code = $object->getData($attributeName); if ($code === false) { return $this; } if ($code == '') { $code = array(); $parents = $object->getParentCategories(); foreach ($parents as $parent) { if ($parent->getLevel() > 1 && $parent->getId() != $object->getId()) { $code[] = $parent->getName(); } } $code[] = $object->getName(); $code = implode('-', $code); } $object->setData($attributeName, $object->formatUrlKey($code)); return $this; }
/** * Process positions of old parent category children and new parent category children. * Get position for moved category * * @param Mage_Catalog_Model_Category $category * @param Mage_Catalog_Model_Category $newParent * @param null|int $afterCategoryId * @return int */ protected function _processPositions($category, $newParent, $afterCategoryId) { $table = $this->getEntityTable(); $adapter = $this->_getWriteAdapter(); $positionField = $adapter->quoteIdentifier('position'); $bind = array('position' => new Zend_Db_Expr($positionField . ' - 1')); $where = array('parent_id = ?' => $category->getParentId(), $positionField . ' > ?' => $category->getPosition()); $adapter->update($table, $bind, $where); /** * Prepare position value */ if ($afterCategoryId) { $select = $adapter->select()->from($table, 'position')->where('entity_id = :entity_id'); $position = $adapter->fetchOne($select, array('entity_id' => $afterCategoryId)); $bind = array('position' => new Zend_Db_Expr($positionField . ' + 1')); $where = array('parent_id = ?' => $newParent->getId(), $positionField . ' > ?' => $position); $adapter->update($table, $bind, $where); } elseif ($afterCategoryId !== null) { $position = 0; $bind = array('position' => new Zend_Db_Expr($positionField . ' + 1')); $where = array('parent_id = ?' => $newParent->getId(), $positionField . ' > ?' => $position); $adapter->update($table, $bind, $where); } else { $select = $adapter->select()->from($table, array('position' => new Zend_Db_Expr('MIN(' . $positionField . ')')))->where('parent_id = :parent_id'); $position = $adapter->fetchOne($select, array('parent_id' => $newParent->getId())); } $position += 1; return $position; }
/** * Specify category filter for product collection * * @param Mage_Catalog_Model_Category $category * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection */ public function addCategoryFilter(Mage_Catalog_Model_Category $category) { $this->_productLimitationFilters['category_id'] = $category->getId(); if ($category->getIsAnchor()) { unset($this->_productLimitationFilters['category_is_anchor']); } else { $this->_productLimitationFilters['category_is_anchor'] = 1; } $this->_applyProductLimitations(); return $this; }
/** * Check if the current category matches the passed in category * * @param Mage_Catalog_Model_Category $category * @return bool */ protected function _isCurrentCategory($category) { return ($cat = $this->getCurrentCategory()) && $cat->getId() == $category->getId(); }
/** * Check is category in list of store categories * * @param Mage_Catalog_Model_Category $category * @return boolean */ public function isInRootCategoryList($category) { $innerSelect = $this->_getReadAdapter()->select()->from($this->getMainStoreTable($category->getStoreId()), new Zend_Db_Expr("CONCAT(path, '/%')"))->where('entity_id = ?', AO::app()->getStore()->getRootCategoryId()); $select = $this->_getReadAdapter()->select()->from($this->getMainStoreTable($category->getStoreId()), 'entity_id')->where('entity_id = ?', $category->getId())->where(new Zend_Db_Expr("path LIKE ({$innerSelect->__toString()})")); return (bool) $this->_getReadAdapter()->fetchOne($select); }
/** * Check whether specified category is allowed * * @param Mage_Catalog_Model_Category $category * @return bool */ protected function _isCategoryAllowed($category) { if (!$category->getId()) { return false; } $categoryPath = $category->getPath(); foreach ($this->_role->getAllowedRootCategories() as $rootPath) { if ($categoryPath === $rootPath || 0 === strpos($categoryPath, "{$rootPath}/")) { return true; } } return false; }
/** * Get products count in category * * @param Mage_Catalog_Model_Category $category * @return integer */ public function getProductCount($category) { $select = $this->_getReadAdapter()->select()->from($this->getTable('catalog/category_product'), "COUNT({$this->getTable('catalog/category_product')}.product_id)")->where("{$this->getTable('catalog/category_product')}.category_id = ?", $category->getId())->group("{$this->getTable('catalog/category_product')}.category_id"); return (int) $this->_getReadAdapter()->fetchOne($select); }
/** * Validate category for be using as filter * * @param Mage_Catalog_Model_Category $category * @return unknown */ protected function _isValidCategory($category) { return $category->getId(); }
public function createCategory() { $catId = $this->getCategoryIdByName($this->categoryName); if ($catId) { return $catId; } $parentId = Mage::app()->getStore($this->storeId)->getRootCategoryId(); $category = new Mage_Catalog_Model_Category(); $category->setName($this->categoryName); $category->setUrlKey('contact-lenses'); $category->setIsActive(1); $category->setDisplayMode('PRODUCTS'); $category->setIsAnchor(0); $parentCategory = Mage::getModel('catalog/category')->load($parentId); $category->setPath($parentCategory->getPath()); $category->save(); //unset($category); return $category->getId(); }