Hello.
Here is an other strange one.
Scenario:
Magento EE 1.12.
30+ store views on the same Magento instance.
30k+ products.
Most of the products have the same settings on all the store views.
I’ve created a rule for showing upsells as follows.
“Show products from the same category with price 100% or more that the selected product”.
Settings for showing upsells: ‘Rule based only’ (the issue reproduces for ‘Rule based and selected’).
I’ve saved the rule. reindexed everything.
Everything seams to look OK, upsells appear (for the products I tested) as defined by the rule, BUT…
After some time for the same product on one store view the upsells appear and on other store views they don’t.
The product has the same settings on all the store views. (and it should have the same upsells.)
If I modify something in the rule and save it again the upsells start appearing on all store views but after some time the issue reproduces.
After digging in the code I found out that the upsells generated by target rule are kept in the table enterprise_targetrule_index_upsell to avoid parsing all the rules each time.
Here is how it works.
If there are any ‘target rule’ upsells in the table I mentioned then they are retrieved. If they are not then the rules are parsed and the result is put in the index table.
Here are some records from that table for a specific product.
As you can see the upsells for product with id 17372 are all the same on all the store view except store_id 20 which is blank.
There is nothing special about store 20. All the products involved here are available on all the stores.
Here comes the issue
This methods falls into the parent class that is a Community edition class: Mage_Rule_Model_Resource_Abstract.
And bindRuleToEntity from this class, at the end deletes the products that are not passed as the second parameter:
It has this:
$adapter->delete($this->getTable($entityInfo['associations_table']), $adapter->quoteInto($entityInfo['rule_id_field'] . ' IN (?) AND ', $ruleIds) . $adapter->quoteInto($entityInfo['entity_id_field'] . ' NOT IN (?)', $entityIds)
What this does is:
DELETE FROM enterprise_targetrule_product WHERE rule_id IN ($ruleId) AND product_id NOT IN ($productId);
This removes all the other products that should be affected by my upsell target rule.
That’s why everything worked nice for a while without any issues. As soon as a product was saved my rule was rendered useless (except for the product I was saving).
Does anyone have any ideas why this piece of code is there?
Magento Team?