Exemplo n.º 1
0
 /**
  * Process category data before delete
  * update children count for parent category
  * delete child categories
  *
  * @param \Magento\Framework\Object $object
  * @return $this
  */
 protected function _beforeDelete(\Magento\Framework\Object $object)
 {
     parent::_beforeDelete($object);
     /**
      * Update children count for all parent categories
      */
     $parentIds = $object->getParentIds();
     if ($parentIds) {
         $childDecrease = $object->getChildrenCount() + 1;
         // +1 is itself
         $data = array('children_count' => new \Zend_Db_Expr('children_count - ' . $childDecrease));
         $where = array('entity_id IN(?)' => $parentIds);
         $this->_getWriteAdapter()->update($this->getEntityTable(), $data, $where);
     }
     $this->deleteChildren($object);
     return $this;
 }