Example #1
0
 /**
  * Delete children categories of specific category
  *
  * @param Varien_Object $object
  * @return Mage_Catalog_Model_Resource_Category
  */
 public function deleteChildren(Varien_Object $object)
 {
     $adapter = $this->_getWriteAdapter();
     $pathField = $adapter->quoteIdentifier('path');
     $select = $adapter->select()->from($this->getEntityTable(), array('entity_id'))->where($pathField . ' LIKE :c_path');
     $childrenIds = $adapter->fetchCol($select, array('c_path' => $object->getPath() . '/%'));
     if (!empty($childrenIds)) {
         $adapter->delete($this->getEntityTable(), array('entity_id IN (?)' => $childrenIds));
     }
     /**
      * Add deleted children ids to object
      * This data can be used in after delete event
      */
     $object->setDeletedChildrenIds($childrenIds);
     return $this;
 }
 /**
  * Delete children categories of specific category
  *
  * @param   Varien_Object $object
  * @return  Mage_Catalog_Model_Resource_Eav_Mysql4_Category
  */
 public function deleteChildren(Varien_Object $object)
 {
     /**
      * Recursion use a lot of memmory, that why we run one request for delete children
      */
     /*if ($child = $this->_getTree()->getNodeById($object->getId())) {
           $children = $child->getChildren();
           foreach ($children as $child) {
               $childObject = Mage::getModel('catalog/category')->load($child->getId())->delete();
           }
       }*/
     $select = $this->_getWriteAdapter()->select()->from($this->getEntityTable(), array('entity_id'))->where($this->_getWriteAdapter()->quoteInto('`path` LIKE ?', $object->getPath() . '/%'));
     $childrenIds = $this->_getWriteAdapter()->fetchCol($select);
     if (!empty($childrenIds)) {
         $this->_getWriteAdapter()->delete($this->getEntityTable(), $this->_getWriteAdapter()->quoteInto('entity_id IN (?)', $childrenIds));
     }
     /**
      * Add deleted children ids to object
      * This data can be used in after delete event
      */
     $object->setDeletedChildrenIds($childrenIds);
     return $this;
 }