Every so often, a unique request comes to my desk. Today it was to prohibit the sale of a specific designer from countries known for knock-offs. To accomplish this we must first find out if any restricted products exist in the cart, then catch the address used during the checkout process and determine if the country used in the shipping address is on the banned list.
For this example, we already have a highly custom checkout process, so we needed it to work after the shipping method was selected during the one page checkout. To do this, I created a module called “Prohibited” which I put in my local code directory “Ip” where all of my custom overrides reside.
I configured this module to rewrite the checkout/type_onepage model so I can override the saveShippingMethod() method.
Then, to get this wrapped up quickly, I added the list of restricted countries, restricted categories, and the error message directly to the extended class.
To customize this further, you could add these custom values to the system > configurations and use a simply category multi-select and the adminhtml/system_config_source_country source model. Additionally, this could be customized to limit sale of products by brand, manufacturer, or other attribute by state or a variety of other conditions!
Fork this extension on GITHUB and feel free to share your thoughts below.
If you’re looking for Magento Services, give us a call!