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!

CommentFileSizeAuthor
#13 vv_postcode.zip1.13 KBroman_pro

Comments

googletorp’s picture

Title: Support wildcards in SKU conditions for shipping rules » Support wildcards in SKU conditions for rules
Project: Commerce Shipping » Commerce Core
Component: Code » Product

Moving to commerce, since wildcards in SKUs is not related to shipping

rszrama’s picture

Title: Support wildcards in SKU conditions for rules » Does the data comparison condition support wildcard text comparison?
Project: Commerce Core » Rules
Version: 7.x-1.x-dev » 7.x-2.x-dev
Component: Product » Rules Engine
Category: feature » support

Let's move this to Rules, as it's a simple data comparison condition - I wonder if text fields already support wildcard comparison.

mitchell’s picture

Status: Active » Fixed

Yes, 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."

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

roman_pro’s picture

Has 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.

kbk’s picture

One 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.)

mitchell’s picture

Title: Does the data comparison condition support wildcard text comparison? » How to: match data with regex
Component: Rules Engine » Documentation
Category: support » task
Status: Closed (fixed) » Active

@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.

mitchell’s picture

Matt Habermehl’s picture

I 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

Matt Habermehl’s picture

I 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.

Chris Charlton’s picture

Commerce 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).

roman_pro’s picture

I’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)?

roman_pro’s picture

StatusFileSize
new1.13 KB

I'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.

mitchell’s picture