![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/module-catalog/Model/ResourceModel/Category/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ namespace Magento\Catalog\Model\ResourceModel\Category; use Magento\Catalog\Model\Category; /** * Aggregate count for parent category after deleting child category * * Class AggregateCount */ class AggregateCount { /** * Reduces children count for parent categories * * @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) { $data = ['children_count' => new \Zend_Db_Expr('children_count - 1')]; $where = ['entity_id IN(?)' => $parentIds]; $resourceModel->getConnection()->update($resourceModel->getEntityTable(), $data, $where); } } }