/**
  * Builds a tagging string of the given category including all its parent
  * categories.
  * The categories are sorted by their position in the category tree path.
  *
  * @param Mage_Catalog_Model_Category $category the category model.
  *
  * @return string
  */
 public function buildCategoryString($category)
 {
     $data = array();
     if ($category instanceof Mage_Catalog_Model_Category) {
         /** @var $categories Mage_Catalog_Model_Category[] */
         $categories = $category->getParentCategories();
         $path = $category->getPathInStore();
         $ids = array_reverse(explode(',', $path));
         foreach ($ids as $id) {
             if (isset($categories[$id]) && $categories[$id]->getName()) {
                 $data[] = $categories[$id]->getName();
             }
         }
     }
     if (!empty($data)) {
         return DS . implode(DS, $data);
     } else {
         return '';
     }
 }
Beispiel #2
0
 /**
  * Return parent categories of category
  *
  * @param Mage_Catalog_Model_Category $category
  * @return array
  */
 public function getParentCategories($category)
 {
     $pathIds = array_reverse(explode(',', $category->getPathInStore()));
     $categories = Mage::getResourceModel('Mage_Catalog_Model_Resource_Category_Collection')->setStore(Mage::app()->getStore())->addAttributeToSelect('name')->addAttributeToSelect('url_key')->addFieldToFilter('entity_id', array('in' => $pathIds))->addFieldToFilter('is_active', 1)->load()->getItems();
     return $categories;
 }
 /**
  * Return parent categories of category
  *
  * @param Mage_Catalog_Model_Category $category
  * @return array
  */
 public function getParentCategories($category, $isActive = true)
 {
     $categories = array();
     $select = $this->_getReadAdapter()->select()->from(array('main_table' => $this->getMainStoreTable($category->getStoreId())), array('main_table.entity_id', 'main_table.name'))->joinLeft(array('url_rewrite' => $this->getTable('core/url_rewrite')), 'url_rewrite.category_id=main_table.entity_id AND url_rewrite.is_system=1 AND url_rewrite.product_id IS NULL AND url_rewrite.store_id="' . $category->getStoreId() . '" AND url_rewrite.id_path LIKE "category/%"', array('request_path' => 'url_rewrite.request_path'))->where('main_table.entity_id IN (?)', array_reverse(explode(',', $category->getPathInStore())));
     if ($isActive) {
         $select->where('main_table.is_active = ?', '1');
     }
     $select->order('main_table.path ASC');
     $result = $this->_getReadAdapter()->fetchAll($select);
     foreach ($result as $row) {
         $row['id'] = $row['entity_id'];
         $categories[$row['entity_id']] = AO::getModel('catalog/category')->setData($row);
     }
     return $categories;
 }
Beispiel #4
0
 public function testGetPathInStore()
 {
     $this->_model->load(5);
     $this->assertEquals('5,4,3', $this->_model->getPathInStore());
 }
Beispiel #5
0
 /**
  * Return parent categories of category
  *
  * @param Mage_Catalog_Model_Category $category
  * @param bool $isActive
  * @return array
  */
 public function getParentCategories($category, $isActive = true)
 {
     $categories = array();
     $select = $this->_getReadAdapter()->select()->from(array('main_table' => $this->getMainStoreTable($category->getStoreId())), array('main_table.entity_id', 'main_table.name'))->where('main_table.entity_id IN (?)', array_reverse(explode(',', $category->getPathInStore())));
     if ($isActive) {
         $select->where('main_table.is_active = ?', '1');
     }
     $select->order('main_table.path ASC');
     $urlRewrite = $this->_factory->getCategoryUrlRewriteHelper();
     $urlRewrite->joinTableToSelect($select, $category->getStoreId());
     $result = $this->_getReadAdapter()->fetchAll($select);
     foreach ($result as $row) {
         $row['id'] = $row['entity_id'];
         $categories[$row['entity_id']] = Mage::getModel('catalog/category')->setData($row);
     }
     return $categories;
 }