-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #377 from magento-troll/MAGETWO-43102
[Troll] Sprint 52
- Loading branch information
Showing
11 changed files
with
121 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
app/code/Magento/Catalog/Model/ResourceModel/Category/AggregateCount.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Catalog\Model\ResourceModel\Category; | ||
|
||
use Magento\Catalog\Model\Category; | ||
|
||
/** | ||
* Class AggregateCount | ||
*/ | ||
class AggregateCount | ||
{ | ||
/** | ||
* @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); | ||
} | ||
} | ||
} |
Oops, something went wrong.