Question

I have a strange issue with the Magento Target rule up-sells.

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 current 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. (the table is truncated when saving a rule) 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.

+-----------+----------+-------------------+---------------------------------------------------------------------+---------------------+
| entity_id | store_id | customer_group_id | product_ids                                                         | customer_segment_id |
+-----------+----------+-------------------+---------------------------------------------------------------------+---------------------+
|     17372 |        2 |                 0 | 17373,350,583,487,17664,29737,14719,443,445,29502,17666,17667,17668 |                   0 |
|     17372 |        5 |                 0 | 17373,350,583,487,17664,29737,14719,443,445,29502,17666,17667,17668 |                   0 |
|     17372 |       17 |                 0 | 17373,350,583,487,17664,29737,14719,443,445,29502,17666,17667,17668 |                   0 |
|     17372 |       18 |                 0 | 17373,350,583,487,17664,29737,14719,443,445,29502,17666,17667,17668 |                   0 |
|     17372 |       19 |                 0 | 17373,350,583,487,17664,29737,14719,443,445,29502,17666,17667,17668 |                   0 |
|     17372 |       20 |                 0 |                                                                     |                   0 |
|     17372 |       21 |                 0 | 17373,350,583,487,17664,29737,14719,443,445,29502,17666,17667,17668 |                   0 |
|     17372 |       22 |                 0 | 17373,350,583,487,17664,29737,14719,443,445,29502,17666,17667,17668 |                   0 |
|     17372 |       23 |                 0 | 17373,350,583,487,17664,29737,14719,443,445,29502,17666,17667,17668 |                   0 |

As you can see the upsells for product with id 17372 are all the same on all the store views 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.

Any idea?

Thanks. Marius.

Was it helpful?

Solution

In EE 1.13, this bug seem to be fixed (but EE 1.13 is gone)

In Enterprise_TargetRule_Model_Resource_Index::saveProductIndex, line with problem was replaced with (hint: 4th param "false")

$targetRule->bindRuleToEntity($ruleId, $productId, 'product', false);

and, in Mage_Rule_Model_Resource_Abstract, function bindRuleToEntity was changed to:

public function bindRuleToEntity($ruleIds, $entityIds, $entityType, $deleteOldResults = true)

and line $adapter->delete(...) was wrapped into

if ($deleteOldResults) {
    $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)
    );
 }

Another bug, shell/indexer.php --reindex targetrule does nothing, so, you cannot reindex via cron/console, fix by adding in Enterprise_TargetRule_Model_Index:

public function reindexAll() {
    return $this->_getResource()->cleanIndex();
}

LATER: see this patch https://github.com/magendooro/targetrulefix

OTHER TIPS

I decided to add what I found as an answer so this question will not be marked as unasnwered.

when saving a product the target rules are indexed for that product and it ends up doing this:(Mage_Rule_Model_Resource_Abstract::bindRuleToEntity() )

$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); 

This deletes all the other products from the affected product list. If I set the mode for the targetrule index to 'manual' the issue is not reproducing. But this does not solve it. It just hides it.

From my point of view this is a serious Magento EE bug.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top