Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Target rule upsells
 
tzyganu
Mentor
 
Avatar
Total Posts:  2205
Joined:  2009-11-18
Bucharest, Romania
 

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.

Any ideas on where I should start?

Marius.

 
Magento Community Magento Community
Magento Community
Magento Community
 
tzyganu
Mentor
 
Avatar
Total Posts:  2205
Joined:  2009-11-18
Bucharest, Romania
 

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.

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

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.

Any idea will do.
Thanks,
Marius.

 
Magento Community Magento Community
Magento Community
Magento Community
 
tzyganu
Mentor
 
Avatar
Total Posts:  2205
Joined:  2009-11-18
Bucharest, Romania
 

aaaa....bump?

 
Magento Community Magento Community
Magento Community
Magento Community
 
tzyganu
Mentor
 
Avatar
Total Posts:  2205
Joined:  2009-11-18
Bucharest, Romania
 

come on...still no one?

 
Magento Community Magento Community
Magento Community
Magento Community
 
tzyganu
Mentor
 
Avatar
Total Posts:  2205
Joined:  2009-11-18
Bucharest, Romania
 

Ok. I’ve got some news.
After digging deep It comes to this:
After a product is saved an event is triggered in the Enterprise_TargetRule module.

Enterprise_TargetRule_Model_Observer::catalogProductSaveCommitAfter()
This one triggers a reindex that ends up here
Enterprise_TargetRule_Model_Index::_reindex()
This method loops through all the rules and calls
Enterprise_TargetRule_Model_Resource_Index::saveProductIndex($ruleId$productId$storeId);
This one calls
Enterprise_TargetRule_Model_Resource_Rule::bindRuleToEntity($ruleId, array($productId), 'product');
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?

Thanks
Marius.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top