Example #1
0
 /**
  * @param Category $category
  * @return void
  */
 public function processDelete(Category $category)
 {
     /** @var \Magento\Catalog\Model\ResourceModel\Category $resourceModel */
     $resourceModel = $category->getResource();
     /**
      * Update children count for all parent categories
      */
     $parentIds = $category->getParentIds();
     if ($parentIds) {
         $childDecrease = $category->getChildrenCount() + 1;
         // +1 is itself
         $data = ['children_count' => new \Zend_Db_Expr('children_count - ' . $childDecrease)];
         $where = ['entity_id IN(?)' => $parentIds];
         $resourceModel->getConnection()->update($resourceModel->getEntityTable(), $data, $where);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function getChildrenCount()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getChildrenCount');
     if (!$pluginInfo) {
         return parent::getChildrenCount();
     } else {
         return $this->___callPlugins('getChildrenCount', func_get_args(), $pluginInfo);
     }
 }