Minimum order amount for one country

Open to all! Ask other shopowners for help.
Post Reply
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Minimum order amount for one country

Post by ecartz »

Code: Select all

const TEXT_INSUFFICIENT_CART = <<<'EOT'
Sorry, we cannot ship orders smaller than %s to %s since we are not registered for VAT there.  This order is only %s.
EOT;

class hook_shop_checkout__08a_minimum {

  const MINIMUM = 135;

  public function listen_startApplication() {
    if (('222' === $GLOBALS['customer_data']->get('country_id', $GLOBALS['order']->delivery ?? [])) && (($GLOBALS['order']->info['total'] ?? 0) < static::MINIMUM)) {
      $country = $GLOBALS['customer_data']->get('country', $GLOBALS['order']->delivery ?? []);
      $GLOBALS['messageStack']->add_session('product_action', sprintf(
        TEXT_INSUFFICIENT_CART,
        $GLOBALS['currencies']->format(static::MINIMUM, true, 'GBP'),
        $country['name'],
        $GLOBALS['currencies']->format($GLOBALS['order']->info['total'] ?? 0)));
      tep_redirect(tep_href_link('shopping_cart.php'));
    }
  }

}
This is reference code for preventing checkout when an order is less than a certain amount and destined for a particular country. Feel free to use it if it helps you.

Note: I have no interest in supporting this code. I haven't used it or tested it. It is not really localized (there's a constant but it's here rather than in a separate language file for translation). It only works for shipping to the UK (the 222, 135, and GBP are all UK specific). If you have problems with it, I strongly urge you to contact one of the certified developers for help. They can either write their own version or modify this one to fit your needs. I've done the easy part. If you need help with the hard part, I'm sure they are ready to quote you.

Some of you may ask why I'm willing to write it but not to put it in core.

1. This will only work for stores that want to keep delivering to the UK under the new rules.
2. And who don't want to register for VAT with the UK.
3. In core, we'd have to add more configuration. Because it would need to be optional (particularly for stores that are already UK VAT enabled). As an App though, if you don't like it, just delete it. Or never install it in the first place.
4. I expect it to be not quite what you want. And I expect store owners to have a lot of different ideas about what would be the perfect way to handle this issue. So maintaining this will be a continuous time suck until things stabilize (possibly by coming up with a more realistic system like having the shipper collect the VAT).

Certified developers have a way of handling time sucks. They charge you money based on how much time they lose to the project (or quote you on the expectation). Core doesn't. It's not the programming that's difficult. Here it is. I've coded it (without core changes!). It's making it work for your store. Some of you like stretching your coding skills and can fit this to your store. You're welcome to use it. But for those who are looking for coding/installation/customization help with this, please contact the certified developers for help.

Or just go with one of the no code solutions: stop shipping to the UK or register for VAT there.


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
burt
Core Team
Posts: 4546
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

Re: Minimum order amount for one country

Post by burt »

:thumbsup:

I also have a Supp Code upcoming (probably the next one), which is being tested at the moment. It seems solid.
I went down the Header Tag module route to allow localization and different amounts per country etc.
I am not here to build for you.
I am here to build with you. Let's help each other.


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply