9

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.

  • 1
    Is your cron configured properly. IIRC the rules are re-built nightly and without an active cron will produce odd behaviour – Ben Lessani - Sonassi Mar 5 '13 at 12:06
  • The cron is active and runs each morning without issues. – Marius Mar 5 '13 at 12:28
  • I found one other thing. After saving the rule, the table 'enterprise_targetrule_product' contains all the products but after some time all of them are gone except one, not always the same one. As long as the product ids are in the table above, everything works. – Marius Mar 5 '13 at 12:54
  • 1
    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. – Marius Mar 5 '13 at 15:01
  • Any reason for someone downvoting this? – FlorinelChis Mar 6 '13 at 15:48
7

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

  • I'm on 1.13.1 and I'm having a Integrity constraint violation:for key '5B1C775075460366570ABDA2839BC68A' -> this key comes from enterprise_targetrule_index_related ... do you have any idea if it is related to the mentioned changes ? – Fra Jun 4 '14 at 22:44
1

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.

  • Did accepted answer solve your issue? I'm having the same issue in EE 1.11.1.0 – dchayka Apr 11 '16 at 20:02
  • It did for me.. – Marius Apr 11 '16 at 20:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.