Note there is a huge mistake between Mage_Catalog_Model_Resource_Category_Indexer_Product::_refreshAnchorRelations()
and Mage_Catalog_Model_Resource_Category_Indexer_Product::reindexAll()
methods, which will obviously lead to some strange behaviors:
In _refreshAnchorRelations()
:
$position = 'MIN('.
$adapter->getCheckSql(
'cp.category_id = ce.entity_id',
'cp.position',
'(cc.position + 1) * ('.$adapter->quoteIdentifier('cc.level').' + 1) * 10000 + cp.position'
)
.')';
Note that here we have brackets that are surrounding the expression, which gives us this result: (cc.position + 1) * (cc.level + 1) * 10000 + cp.position
.
_refreshAnchorRelations()
is a protected method called by the following three methods in the same class:
catalogProductSave()
catalogProductMassAction()
catalogCategorySave()
These last are called when you are saving a category or a product in the backend.
In reindexAll()
:
$position = 'MIN('.
$idxAdapter->getCheckSql(
'ca.category_id = ce.entity_id',
$idxAdapter->quoteIdentifier('cp.position'),
'('.$idxAdapter->quoteIdentifier('ce.position').' + 1) * '
.'('.$idxAdapter->quoteIdentifier('ce.level').' + 1 * 10000)'
.' + '.$idxAdapter->quoteIdentifier('cp.position')
)
.')';
Here, the brackets surrounding the expression are positioned differently, which give us: (ce.position + 1) * (ce.level + 1 * 10000) + cp.position
.
With the priority of the operators, the result obtained here will not be the same at all than with _refreshAnchorRelations()
method.
As its name may suggest, the reindexAll()
method occurs when you launch the reindexing of catalog_category_product
index ("Category Products").