Active
Project:
Rules
Version:
7.x-2.x-dev
Component:
Documentation
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
9 Nov 2011 at 18:35 UTC
Updated:
12 Jan 2013 at 05:07 UTC
Jump to comment: Most recent file
I have a whole bunch of products with similar SKUs that all need the same shipping rule applied. As far as I can tell, the only way to set up this logic is by manually adding a separate "or" condition for each SKU. Entering multiple SKUs in the field -- even though it's a textarea much larger than necessary for a single SKU -- does not appear to work. It would be really really helpful to support wildcards for matching SKUs. Thank you!
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | vv_postcode.zip | 1.13 KB | roman_pro |
Comments
Comment #1
googletorp commentedMoving to commerce, since wildcards in SKUs is not related to shipping
Comment #2
rszrama commentedLet's move this to Rules, as it's a simple data comparison condition - I wonder if text fields already support wildcard comparison.
Comment #3
mitchell commentedYes, it does. I just tested it with ".", which according to the utility RegExr linked in the text comparison condition help text, "Matches any character, except for line breaks if dotall is false."
Comment #5
roman_pro commentedHas anyone managed to make the wildcards work? I can't figure out how to use them for postal code shipping quotes - have tried asterisks and dot as suggested above with no luck.
Comment #6
kbk commentedOne thing to do is go onto the regex IRC channel and ask for help.
Another thing to do is visit the website recommended by Rules http://gskinner.com/RegExr/ and beat you head against the keyboard until you get what you need.
After following those two steps, I used data/\d+/summary to match data/*/summary where * was an NID (i.e., any series of numbers.)
Comment #7
mitchell commented@kbk: I agree that RegExr isn't good enough. Let's discuss what we can do about that in another issue...
If anyone has time to add a page to the site-building handbook starting with this info, that'd be a big help in making Rules more awesome.
Comment #8
mitchell commentedSee also: #1665202: Regex: include a pattern builder.
Comment #9
Matt Habermehl commentedI needed a similar functionality. I wanted to check if the user's cart contained one and only one product where a sku contained some string X. This way 123Xf, 124X23, 125X, etc. would all trigger the condition.
This should work in your case if you want the same shipping rule applied if the product's sku contains a particular string.
I'm using Commerce 1.3
So I modified the file commerce_order.rules.inc found in /modules/commerce/modules/order/
Here is the full file as I have modified it: http://pastebin.com/vEhFssCL
Back up your original commerce_order.rules.inc first, then modify it as I have done.
Then you need to run cron through the Drupal admin interface to get it to work.
Now you will have an additional condition called "Order has one or more products where the sku contains..."
When you add the condition in your rule, put the text you want to search a SKU for in the PRODUCT SKU field. No need for any wildcard characters. The program just checks all the SKUs in the cart to see if any (and how many) of the SKUs contain the text you enter into the PRODUCT SKU field.
I basically hacked this together using the existing "Order contains particular product" code. So it may be buggy. I'd be very happy if others wanted to modify this to be a robust solution, perhaps even committing it to the Commerce code (IMO it's a very useful condition).
Best,
Matt
Comment #10
Matt Habermehl commentedI have found that you can also use the Data->Text comparison condition and compare the text on commerce-product:sku data selector.
However, this data selector is not available for all Events. For example, it is available for "After adding a product to the cart" but not for "Calculating the sell price of a product". What I have posted above should work for both cases.
Comment #11
Chris CharltonCommerce 7.x-1.3 has a "regular expression" option. I was able to run any complex RegEx for multiple SKU's. But I do agree with this could be easier and an interface enhancement is needed to help others (somewhat similar to the patch from @Matt above).
Comment #12
roman_pro commentedI’m actually using ubercart and still looking for the solution. Have the first two letters of London postcodes and need to match all combinations for different shipping price. Regex doesn’t seem to work either as it takes it as a string rather than regular expression.
Anyone has an idea, where in rules are the strings checked/matched so I could maybe take it from there (as a short term solution)?
Comment #13
roman_pro commentedI've written a tiny module-code which allows to compare first two letters of postcode (or any selected data) against a list of postcodes (in my case it was a list of the first two letters of all London postcodes) to set different shipping for London costumers. Thought it might be useful to someone facing similar issue - it should be relatively easy to modify for similar use cases... The code is attached. Was tested only minimally.
Comment #14
mitchell commentedRegex Quick Reference