/**
  * 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 '';
     }
 }
Esempio n. 2
0
 /**
  * @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;
 }
Esempio n. 3
0
 public function testGetParentCategoriesEmpty()
 {
     $this->_model->load(1);
     $parents = $this->_model->getParentCategories();
     $this->assertEquals(0, count($parents));
 }