Yireo - Developer training

Open main menu

March 25, 2022

Block Magento 2 sales per geographical region

I'm selling extensions (well, as of yet, only EmailTester2) and trainings (a lot). Once in a while, I find myself seeing an incoming sales order, for which I can't or don't want to provide support because of reasons: Spam, cancel-anything-behaviour, political incorrectness, whatever. In the past, I built the Yireo_SalesBlock2 for this. And in these times, I felt it would be good to mention its ability to block by geographical region.

From commercial to free

The Yireo SalesBlock2 module has a simple task: To prevent an incoming sales order from being placed. The reasons for this might be numerous: Perhaps you don't want the competition to buy from you, perhaps you simply hate a specific person, perhaps you were mailed in the middle of night by a drunk customer, demanding support while cursing a lot, perhaps you see some geopolitical reason to block an entire country.

Actually, all of the above happened to me in the past, even though I'm seeing myself as generally a nice person (though perhaps sometimes a bit too outspoken). In short, I had a good reason to write a module for this. A Magento 1 (what is that?) module was created ages ago. And a Magento 2 version was released as well. I sold these two modules for quite some time. But since Yireo has focused more and more upon live trainings and on-demand courses, last year (2021) I decided to turn most paid extensions into freebie. And this applied to SalesBlock2 as well. I don't know about the success ratio of this, because I never paid much attention to this and I never monitored how many people are using my open source extensions.

But here is a little promotion.

SalesBlock2 architecture

The SalesBlock2 architecture (see github.com/yireo/Yireo_SalesBlock2) is quite straight-forward. In the Magento Admin Panel, you can create rules based on certain conditions. For selecting conditions, add-on modules are required. Currently there are 3 of them:

Once the modules are installed and activated, the main SalesBlock2 extension uses them to extend upon the Magento Admin Panel, and to act upon their functionality in the frontend. Once a specific rule is created in the backend, the corresponding module is used on the frontend to see if a match is made. And if the match is there, sales is blocked. For sales to be blocked, a simple kill-cart strategy is used.

Blocking by geographical location

For instance, with the SalesBlock2ByGeo module, you can block by geographical location: Within a rule, you can enter a 2-letter or 3-letter definition of a country, or a 2-letter definition of an entire continent.

This can be used to block sales from any IP-address that is identified as coming from the Netherlands (NL or NLD). I think you can put it to good use for blocking countries based on (for instance) current geopolitical situations. Or block an entire continent, like Antartica.

Posted on March 25, 2022

Get started with my Magento 2 module by following the documented instructions

Checkout my Yireo SalesBlock2 module

Looking for a training in-house?

Let's get to it!

Do not miss out on what we say

This will be the most interesting spam you've ever read

We don't write too commercial stuff, we focus on the technology (which we love) and we regularly come up with innovative solutions. Via our newsletter, you can keep yourself up to date on all of this coolness. Subscribing only takes seconds.

Sign up for the Yireo newsletter