Tags/topics: 
1
Answers
Vote up!
0
Vote down!

How do I exclude a taxonomy term on discount

I add a discount on all my products via Product Pricing Rule. But there's a category that I don't want to add the discount for. How do I add a condition to exclude a taxonomy term? I tried to choose "Entity exists by property", then selecting "Taxonomy Term" then I select "Term ID"...but then I don't know what the term ID is? And i don't know if this is the best way to do it?

Thanks for the help.

Asked by: Hendrik Martens
on August 26, 2013

1 Answer

Vote up!
0
Vote down!

The "Entity exists by property" condition will tell you whether or not a taxonomy term exists, but it doesn't have anything to do with whether or not the product is in that category. Instead, you're going to want to use the "Data comparison" condition on the taxonomy term reference field, which first requires you to use "Entity has field" on whatever entity it is whose taxonomy terms you want to check.

The bigger problem, though, is that your taxonomy terms are likely on your product display nodes, not your products themselves. If the terms were on your products, it would be a simple matter of checking the product referenced by the line item to find the taxonomy term reference field and see if it had been tagged with that term. (Or, realistically, negating such a condition since you want to avoid applying a discount if a term is found.)

However, if your tags are on your product display nodes, you're going to have to figure out how to get from the product line item to the product display node to then check its taxonomy terms. If each of your products is referenced by only one node, then you should be able to "Fetch an entity" to load the node that references the product in question and then do the taxonomy check. That will involve passing the node to a separate price component along with the line item and applying the discount in the component if the node passes the condition check.

If you don't have that relationship, it'll be much harder, and I'd just as soon recommend writing a custom condition to embed all the logic. In fact, you might want to do that anyway if you are able, as the Rules setup described above is hardly non-trivial either.

Ryan Szrama
Answer by: Ryan Szrama
Posted: Sep 9, 2013

Comments

Hi Ryan

This sounds like no easy feat...I thought it would be so easy as Rules are so powerful! I actually thought that this usecase is a regular need :)

- Hendrik Martens on December 2, 2013

Hi Ryan

I've checked out Commerce Rules Extra and added the "line item product has term" but it doesn't seem to add the discount to that Term's products :(

I really hope I can get this thing working somehow ;) Thanks for all your help!

- Hendrik Martens on December 2, 2013