I don't have a solution but I have a place you can start debugging.
The query looks very similar to the one generated by the method Mage_Rule_Model_Resource_Abstract::getProductFlatSelect()
public function getProductFlatSelect($storeId, $condition)
{
$select = $this->_getReadAdapter()->select();
$select->from(
array('p' => $this->getTable('catalog/product')),
array(new Zend_Db_Expr('DISTINCT p.entity_id'))
)
->joinInner(
array('cpf' => $this->getTable('catalog/product_flat') . '_' . $storeId),
'cpf.entity_id = p.entity_id',
array()
)->joinLeft(
array('ccp' => $this->getTable('catalog/category_product')),
'ccp.product_id = p.entity_id',
array()
);
$where = $condition->prepareConditionSql();
if (!empty($where)) {
$select->where($where);
}
return $select;
}
For some reason (unknown to me) the $where
variable does not come up as empty, but it comes up as ()
or (())
.
$where
is generated either by Mage_Rule_Model_Condition_Product_Abstract::prepareConditionSql()
(but I doubt it in your case, but it still could be it) either Mage_Rule_Model_Condition_Combine::prepareConditionSql()
(my money is on this one).
This last one looks like this:
public function prepareConditionSql()
{
$wheres = array();
foreach ($this->getConditions() as $condition) {
/** @var $condition Mage_Rule_Model_Condition_Abstract */
$wheres[] = $condition->prepareConditionSql();
}
if (empty($wheres)) {
return '';
}
$delimiter = $this->getAggregator() == "all" ? ' AND ' : ' OR ';
return ' (' . implode($delimiter, $wheres) . ') ';
}
This means that when a product is saved, the catalog rules are indexed to see if the product matches the criteria.
And for each rule, the conditions are parsed recursively (if a condition is a group of other conditions the method is called again).
But for some reason your $wheres
array is empty, but it acts like it's not empty.
That's all I have for now.
I would start investigating from the points I mentioned above. Also check if you have some extension that might affect the catalog rules.
Or maybe you had an extension and disabled it, but the rules that were already there still think that extension exists.