Open loekvangool opened 3 years ago
We could prevent negative values like so:
app/code/core/Mage/Catalog/Model/Resource/Category.php
:
line 137: $data = array('children_count' => new Zend_Db_Expr('MAX(0, children_count - ' . $childDecrease) . ')');
...
line 834: array('children_count' => new Zend_Db_Expr('MAX(0, children_count - ' . $childrenCount) . ')'),
However, it would not prevent a faulty 0
from forming.
I can confirm that above SQL sequence fixes the issue (after the fact, of course).
PR?
Steps to reproduce (*)
Steps are described at https://www.sonassi.com/blog/magento-kb/magento-category-children-count-fix
Fix
A SQL fix is available (from that same blog):
This query seems to work, but it's after-the-fact of course and we would have to build this into an Indexer or Cache clearing button or something like that for it to work.
The impact (afaik) is:
children_count
may even become negative.I'm open to a deeper fix but it seems we can stop negative values, and perhaps we can do something to remove the has-children icon in case
children = []
(fixes point 1).