Magento 2 Shipping Rules: Common Mistakes

Table of Content

IS in conditions - wrong variant

Setting Magento Table Rates , Promotions and various restrictions is an important part of managing a fully-functional Magento/Magento 2 shop. That's why our clients ask questions about Amasty module rules very often, and to help them use the rules logic properly, we collected several mistakes that are most often found in Amasty support queries.

 

Magento 2 Rules: Avoid Common ‘Rules Conflict’ Mistake

We call it ‘rules conflict’. Usually, it’s caused by incorrect condition filling and is one of the top-wanted cases in our support dept.

Problem

The problem emerges when you set up 2 non-overlapping restriction rules that are antagonists in nature. Below we address the situation in vivo example.

Say, you need to make Free Shipping available for all US states except Alaska, Hawaii and Puerto Rico. Alaska, Hawaii and Puerto Rico will have the flat rate method displayed instead of the free method. And only the flat rate method will be displayed for Alaska, Hawaii and Puerto Rico, not for other states.

You need to (a) enable Flat Rate and restrict Free Shipping for Alaska, Puerto Rico and Hawaii and (b) restrict Flat Rate and enable Free Shipping for all the states, except Alaska, Puerto Rico and Hawaii.

You go and set up Rule 1 to exclude Free Shipping to Hawaii, Alaska and Puerto Rico. And this works fine. Then you set up Rule 2 to hide Flat Rate shipping to any state except Alaska, Hawaii and Puerto Rico. This is not working at all. It is just hiding the flat rate method for all states.

The case seems logical, however, the conditions repeat the code branches and can return True if all the conditions or one of them is fulfilled. Thus, you messed up.

Analysis

There are no obstacles to restrict Free Shipping for Hawaii, Alaska and Puerto Rico.

And all the steps you made are right:

Thus, you restrict any free shipping to any of the three states.

The problem emerges when you create Rule 2 or Flat Rate restriction for 48 states on the same basis:

The difference between the previous and this screenshot is that you changed True to False. It seems logical, however, this is what you receive, as the result - Rule 2 worked correctly, restricted Flat Rate and returned Free Shipping:

Rule 1 failed, restricted Free Shipping and didn’t activated Flat Rate:

Thus, you see that Rule 1 didn’t work and go to make edits to it. Having disabled Rule 2, you understand that Rule 1 works correctly. Then you proceed with Rule 2, you start sorting conditions or even change False to True and ‘is’ to ‘is not’. As a result, you change nothing in the work of the rules.

Solution

All you need is to go to Rule 2 and change Any to All:

Why is it so simple and so confusing?

When there’s Any the rule returned True for the first condition already and the code doesn’t execute further. Thus, the code partially worked for the first from the 3 states (e.g.: Hawaii) and didn’t at all for Alaska and Puerto Riko. This led to the case when Flat Rates was restricted as for Hawaii and New York that is for any other state.

Magento 1

1. 'IS' in condition with lists

If you use conditions as in the picture above, Magento will search for '17,15,12,44' category ID. Naturally, we don't have such a category, and we actually need another result. Here's the right variant:

IS in conditions - correct

Here Magento will be searching for these IDs: '17', '15', '12', '44' and the stated Amasty rule will work as desired.

2. Compare with zero

Compare with zero in Magento rules - wrong

At first sight this condition looks legit. But there's a technical issue: basically, you should avoid comparing with zero everywhere in Magento, not only in sales or shipping rules.

The following condition is identical logically and, what is more important, it will work correctly.

Compare with zero in Magento rules - correct

 3. 'greater than' condition operator

Sometimes people use > or < symbols to describe amount comparison relations, but Magento won't understand them properly. Use a special conditions operator instead:

Greater than conditions operator in MagentoGreater than conditions operator - correct

4. Range/list

Very often we notice that Magento shop owners use 'range' when they need Magento to apply something to a list of items. This is wrong, and Magento won't understand this combination as a range. You need to list items (in our case - SKUs) one by one using a comma. And yes, 'is/is one of' case shown once again.
Range/list in Magento conditions
Range/list in Magento conditions - correct

However, there are a few clients who use manual listing of all the post-codes, therefore, for post-code ranges we normally use the operator ‘starts from’ and, if needed, ‘ends with’. 

5. Default shipping address vs Shipping state/Province

Names can't be used with default shipping address, you need to use the default shipping ID instead. Literal location names are used with Shipping state/Province entities.

Default shipping address condition in Magento - wrongShipping address condition in Magento - correct

Magento is a powerful rule engine but to use most of it you need to know how to configure it right.

We do hope this information will be helpful for you, and you'll never make these mistakes again!

If you have any other questions on typical conditions logic mistakes, welcome to ask.

 

July 17, 2019
July 25, 2019
July 12, 2019
Comments
Andhi Irawan
December 2, 2015
Can we use Shipping Postcode as Conditions for Shopping Cart Rule in Shopping Cart Page?
Reply
Ksenia Dobreva
December 2, 2015
Yes, you can. Please see the screenshot: <img src="https://amasty.com/blog/wp-content/uploads/2014/04/OkvX309.png" alt="" />
Andhi Irawan
December 4, 2015
Hi, Ksenia, Thank you. It works. I just found out about it (we can use postcode in shopping cart page as condition for rule)
Ksenia Dobreva
December 4, 2015
Great! Was happy to help.
sakis
November 18, 2016
Hello Ksenia very usefull article, We face a probelm with catalogue price rules. After one day rules doesnt work and we need to click apply rules button from backened almost every day. Is this a magento bug or something that we made wrong? Thanks
Reply
Ksenia Dobreva
November 18, 2016
Hey there, please make sure that your cron is working fine.
sakis
November 18, 2016
Thanks for reply, i set the cron every fove minutes like the line below
Reply
Ksenia Dobreva
November 18, 2016
Well, looks like it was our best guess... As the issue isn't connected with any of other extensions, I'm afraid I can't really help you here, it could be anything, and it's hard to tell from there without seeing the settings and stuff. Maybe you should ask a developer to have a look? Good luck with that.
Kenny
January 18, 2018
Can you provide more information about the comparing against zero problem? I googled but couldn't find anything related. I have noticed this problem using another extension that has conditions for an action. Basically I had to use Less than 1.
Reply
Alina Bragina
January 22, 2018
Hi Kenny, thanks for your question! Unfortunately, for the lack of info about your ‘comparing against zero’ problem it’s hard to resolve it from here. Could you, please, spell out the details, so we see what we can do. Cheers!
Dang Ton
June 4, 2019
Hello, I am late to the party but is there any chance that you show us how to set one Shipping Rule triumphs the others ? As of now, it doesn't give any option since it confuses. Thankss
Reply
Alina Bragina
June 18, 2019
Hi Dang, thanks for writing to us! You're not late to the party at all, just this month we're going to update the post and this info will covered this time. So, <a href="http://eepurl.com/Mv5tD" rel="nofollow">subscribe to our newsletters</a> or check the blog updates to find it in time.
Guest
October 29, 2019
3.5
Reply
Guest
October 29, 2019
1.5
Reply
Gianluca
October 1, 2020
Hi I have to check if the shipping address of the second order (and subsequent) is the same as the first one, in this case the shipping will be free.
Reply
Leave your comment

Your email address will not be published

This blog was created with Amasty Blog Pro

This blog was created with Amasty Blog Pro