Discussions

Check Address Zip Code Against a List of Zip Codes

I am trying to use rules to test the customer's zip code against a list of zip codes, and I cannot see to make this happen no matter what I try. What is the best way with rules to test a piece of date against on array?

Posted: Jan 20, 2012

Comments

rfay Randy Fay on January 20, 2012

You would use the "List contains item" condition, under "data". However, it looks like you'd have to provide that list programatically, as there's no "literal value" option there.

You also might consider creating your own rules condition. It's not too hard. [Itangalo has a great screencast series](http://dev.nodeone.se/en/coding-for-rules-2) on coding for Rules that explains how to make a condition, and the rules docs (when you find the right ones) are not bad either.

tyreldenison on January 21, 2012

Thank you for your input. I will try doing this. Another method I am looking at was creating a condition similar to this.

If product has tag AND costumer is from city this OR city that.

I have not been able to make this work either. Though I have watched your tutorial on adding tags to conditions, I cannot seem to make it work. When I follow the tutorial step by step I seem to have different information in my data selector. Also, When I and the two city or conditions, it breaks the rule. I can match it to a static sku and one city and it works fine, but if I add an or city it doesn't work. Is there some sort of required nesting structure I am unaware of? Thanks again for your advice on how to proceed with this project.

Tyrel

tyreldenison on January 21, 2012

I will use this information. Thank you. Is there are reason I cannot have a condition with an AND and an OR? IS rules not meant to do this?

tyreldenison on January 23, 2012

I am confused by the fact that when I drill down to line item, I am given the following options.
line-items:0
line-items:1
line-items:2

Why is it I have multiple line items when none of the support material suggests I should. BTW, your tutorial on Weekend sales is what made it happen for me. Thanks so much.

rfay Randy Fay on January 23, 2012

You're really in the wrong place when looking at the individual line items. You have chosen a list of line items I think. You need to have a list of zipcodes instead.

tyreldenison on January 23, 2012

Agreed. If I were drilling into line items for the zip codes I would be way off base. I am just making a rule for each city at this point as it seems more efficient (time wise). I am drilling into line items to find the tags I have added to products to apply rules to. I navigate the following way in the data selector.
commerce-order:line-items:0:products

It is there that I use the components to look for the tags. The issue is that it is only applying to the first line item (I assume because I am telling it to with the 0). The problem is that I cannot seem to drill down to

commerce-order:line-item:products

It won't let me without specifying a specific line item. Do you know where I could have possibly gone wrong. I need this function on my site in a bad way. Thanks for all your help.

rfay Randy Fay on January 23, 2012

I see ... is this an entirely new question? You need to use "Entity has field = commerce_product" or "Entity is of type product" to get the product into scope for the existing line, and then you'll have access to the product fields you need. There are lots of explanations of how to get related fields into scope. There's no reason to be looking into the order's line item fields.

It might be time for some refresher. The [Commerce Canadian Taxes](http://vimeo.com/29725767) video might help. Also, the [Commerce Discount Campaign Feature](http://www.commerceguys.com/resources/articles/252). Note that discounts and taxes are almost the same thing.

But as far as I can tell you've gone aground by not knowing [how to tell rules to extend scope to related entities.](http://www.drupalcommerce.org/faq/rules-field-data-selection)

tyreldenison on January 23, 2012

I mentioned the use of tags as part of my second post thinking it would be a breeze. Since I have figured out a work around for the zip code question and got hung on the tags, I mentioned the tag issues here. Should I start a new question regarding the tags to better benefit others who may have this issue?

tyreldenison on January 25, 2012

So it appears the event dictates the data selector options. I was using the event "Select available payment methods for an order" and when I tried to pull the tag into scope it would give me multiple line items. Once I changed the event to "Calculating the sell price of a product" they pulled into scope just as you mentioned.

Sadly, this has produced a new issue. One of the two actions I have given when the conditions are met is an url redirect. Due to (i assume) the way the price event works, I am now put into an infinite redirect loop. I have created a new topic for this issue as the only thing it shares with the original question of this thread is that it is a part of the same overall site requirement. The new thread is here.

avery on April 26, 2013

rfay, you wrote "You would use the "List contains item" condition, under "data". However, it looks like you'd have to provide that list programatically, as there's no "literal value" option there."
How would I provide that list programatically?