Magento Enterprise: Troubleshooting Rule Based Product Relations (aka Target Rules)

Posted on Fri, October 17, 2014 in Web Development, Magento, by Mark Middleton

Target rules are a killer feature of the Magento Enterprise platform, but as with many of the great components in the Magento ecosystem, the documentation is a bit lacking in practical examples and the thorough details necessary to get the results you may be looking for.

Here are some quick resources:

Tip #1 - If you have multiple rules, Isolate the problematic rule

If you are getting results that you are not expecting, first turn off all the rules that apply to this product.

"But how do I know which rules apply to a given product?"

  1. Identify a product you are troubleshooting.  Note the Product ID.
  2. First, in the admin panel, open the product and save it - don't worry about editing anything yet.
    By saving the product, you initiate the re-indexing of the target rules.  
  3. Second, run a quick query to retrieve the rules that apply to this product.

    	enterprise_targetrule.rule_id = enterprise_targetrule_product.rule_id
    	AND<br>        ### replace with your product_id
    	enterprise_targetrule_product.product_id = 6731
            ### 1=related, 2=up-sells, 3=cross-sells
    	enterprise_targetrule.apply_to = 2  
      Now you have a list of all the rules that will apply to this product.  Turn them off one at a time:
    	### 0 to de-activate, 1 to activate
    	is_active = 0  
    	### enter the rule_id from each of the rules from the results above
    	rule_id = 169; 
  4. You now should have all rules turned off for a given product, for a given rule type (related, up-sell, cross-sell).
  5. Turn the first rule on, open and save the product in the admin panel, and check the results.
  6. Now you can either turn that rule off and try the next (to get the discreet results from each rule) or turn on the next one (and see the progressive combination of the rules together).

Tip #2 - "is one of" versus "contains"

Custom product relations can leverage custom product attributes, but don't mix your data types!  The target rule interface is powerful, and, in many cases, will allow you to break the rules if you want.

For example, we have an attribute "Designer" with a pre-defined list of options to select from.  But if I use this attribute for a target rule, it defaults to the operator "contains" and allows me to select an option from this list.  THIS WILL NOT WORK!  "Contains" is only to be used for text attributes you can enter custom strings into. The proper method is to use "is one of..." and select the option from the list.

Tip #3 - Matching by Category can get you into trouble

We have an installation that uses target rules to create up-sell products based on the category of matched products, but all products in the catalog are part of one "All Products" category.

  1. Our selected product was in category 36 and the "all category".
  2. Our desired target was in category 36, category 211 and the "all category".
  3. A product which was showing as a match was part of category 502 and the "all category".

Here is what the config looked like:

How this reads in English:

"Take all products in category 36 and make a list of ALL categories each of those products are in (this will include the "all category").  Now find all products which are in any of these categories".

This simple target rule now has matched EVERY SINGLE PRODUCT IN THE STORE - and caused me a lot of confusion.  How did we solve it?

Because we were matching based on a specific category, we could also set the "products to display" to the same selected category and not fall in the pit of over-matching the target rules.

Tell Us About Your Project