October 17, 2014

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

Target rules are a killer feature of the Magento Enterprise Solutions 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.

    SELECT * FROM Enterprise Solutions_targetrule, Enterprise Solutions_targetrule_product WHERE Enterprise Solutions_targetrule.rule_id = Enterprise Solutions_targetrule_product.rule_id AND ### replace with your product_id Enterprise Solutions_targetrule_product.product_id = 6731 AND ### 1=related, 2=up-sells, 3=cross-sells Enterprise Solutions_targetrule.apply_to = 2 ORDER BY Enterprise Solutions_targetrule.sort_order; 
    Now you have a list of all the rules that will apply to this product. Turn them off one at a time:
    UPDATE Enterprise Solutions_targetrule SET ### 0 to de-activate, 1 to activate is_active = 0 WHERE ### 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 datatypes! 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.

Paul Weinert
Author

Paul Weinert is our founder, managing principal and spirit animal. He’s one of those odd people you meet that was born in Portland, grew up here and still lives here for some reason. If you had two words to describe Paul after meeting him, we’d bet you’d use “charmingly quirky”.

Paul started GRAYBOX in February 2009, and for the first four years, GRAYBOX had a blend of a contract staffing firm and a traditional agency. GRAYBOX then hired our first employees in 2012 and has been growing ever since. Professionally, Paul has a background in internet business consulting, working especially with mid-market ecommerce, healthcare, and tech companies. He worked as a user experience designer, web developer and internet marketer. Nowadays, Paul serves as our company visionary, team mentor and head of executive leadership — Paul is extremely proud of the entire team and the company. He’s constantly humbled by the team’s awesomeness and the caring community that’s sprung up from his initial ideas.

Beyond GRAYBOX, Paul is married, has two young boys and lives in NE Portland. He’s also an active foster parent, mentors other local entrepreneurs, and volunteers on local non-profit boards. Businesswise, aside from GRAYBOX, Paul has started a few other businesses and is an active investor in the local startup scene.

For the sheer joy of it, let’s play 2 truths and a lie:

  1. Paul firmly believes that any activity would be better if on a boat.
  2. Other than this whole Internet thing, Paul has basically no other skills or expertise in anything.
  3. Paul is rare unicorn, actually born and raised in Portland.