public function testGetAllChildren()
 {
     $this->_model->load(4);
     $this->assertEquals('4,5', $this->_model->getAllChildren());
     $this->_model->load(5);
     $this->assertEquals('5', $this->_model->getAllChildren());
 }
Exemple #2
0
 public function move(Mage_Catalog_Model_Category $category, $newParentId)
 {
     $oldStoreId = $category->getStoreId();
     $parent = Mage::getModel('catalog/category')->setStoreId($category->getStoreId())->load($category->getParentId());
     $newParent = Mage::getModel('catalog/category')->setStoreId($category->getStoreId())->load($newParentId);
     $oldParentStores = $parent->getStoreIds();
     $newParentStores = $newParent->getStoreIds();
     $category->setParentId($newParentId)->save();
     $parent->save();
     $newParent->save();
     // Add to new stores
     $addToStores = array_diff($newParentStores, $oldParentStores);
     foreach ($addToStores as $storeId) {
         $newCategory = clone $category;
         $newCategory->setStoreId($storeId)->save();
         $children = $category->getAllChildren();
         if ($children && ($arrChildren = explode(',', $children))) {
             foreach ($arrChildren as $childId) {
                 if ($childId == $category->getId()) {
                     continue;
                 }
                 $child = Mage::getModel('catalog/category')->setStoreId($oldStoreId)->load($childId)->setStoreId($storeId)->save();
             }
         }
     }
     return $this;
 }
 /**
  * For a given category, get all ids to other categories related to it.
  *
  * For a normal category, add ids of all it's parents
  * For an anchor - also add all it's children
  *
  * @param Mage_Catalog_Model_Category $category
  * @return array
  */
 protected function _getValidIdsForCategory(Mage_Catalog_Model_Category $category)
 {
     return explode(',', $category->getAllChildren());
 }
Exemple #4
0
 public function addCategoryFilter(Mage_Catalog_Model_Category $category, $renderAlias = false)
 {
     if ($category->getIsAnchor()) {
         $categoryCondition = $this->getConnection()->quoteInto('{{table}}.category_id IN (?)', explode(',', $category->getAllChildren()));
         $this->getSelect()->group('e.entity_id');
     } else {
         $categoryCondition = $this->getConnection()->quoteInto('{{table}}.category_id=?', $category->getId());
     }
     if ($renderAlias) {
         $alias = 'category_' . $category->getId();
     } else {
         $alias = 'position';
     }
     $this->joinField($alias, 'catalog/category_product', 'position', 'product_id=entity_id', $categoryCondition);
     return $this;
 }