public function getCategoryName($categoryId, $storeId = null) { if ($categoryId instanceof Mage_Catalog_Model_Category) { $categoryId = $categoryId->getId(); } if ($storeId instanceof Mage_Core_Model_Store) { $storeId = $storeId->getId(); } $categoryId = intval($categoryId); $storeId = intval($storeId); if (is_null(self::$_categoryNames)) { self::$_categoryNames = array(); $resource = Mage::getResourceModel('catalog/category'); /** @var $resource Mage_Catalog_Model_Resource_Category */ if ($attribute = $resource->getAttribute('name')) { /** @var Mage_Core_Model_Resource $coreResource */ $coreResource = Mage::getSingleton('core/resource'); $connection = $coreResource->getConnection('core_read'); $select = $connection->select()->from(array('backend' => $attribute->getBackendTable()), array(new Zend_Db_Expr("CONCAT(backend.store_id, '-', backend.entity_id)"), 'backend.value'))->join(array('category' => $resource->getTable('catalog/category')), 'backend.entity_id = category.entity_id', array())->where('backend.entity_type_id = ?', $attribute->getEntityTypeId())->where('backend.attribute_id = ?', $attribute->getAttributeId())->where('category.level > ?', 1); self::$_categoryNames = $connection->fetchPairs($select); } } $categoryName = null; $key = $storeId . '-' . $categoryId; if (isset(self::$_categoryNames[$key])) { // Check whether the category name is present for the specified store $categoryName = strval(self::$_categoryNames[$key]); } elseif ($storeId != 0) { // Check whether the category name is present for the default store $key = '0-' . $categoryId; if (isset(self::$_categoryNames[$key])) { $categoryName = strval(self::$_categoryNames[$key]); } } return $categoryName; }