Jump to content

Minimal order amount by country


Neo_odessa

Recommended Posts

I`m trying change minimal amount in cart different for one country. I`m using module advancedcheckous so i`m doing modifications not in orderOpcController.php I`m found code in advancedcheckout.php

I`ve added for country that I need:

		$id_country = Tools::GetValue('id_country');
				if ($id_country = 216){
		$minimal_purchase = Tools::convertPrice((float)Configuration::get('PS_PURCHASE_MINIMUM'), $currency);} 

For other countries I need Increase minimal amount up to 1.66667

 

Please check my code why it not working:

 public function cartListErrors()
    {
        $err = array();
        $errors = array();
        $arr = array();
        $arr = $this->checkQuantitiesAlt();
        $currency = Currency::getCurrency((int)$this->context->cart->id_currency);
		$id_country = Tools::GetValue('id_country');
				if ($id_country = 216){
		$minimal_purchase = Tools::convertPrice((float)Configuration::get('PS_PURCHASE_MINIMUM'), $currency);}
		else {
		$minimal_purchase = Tools::convertPrice((float)Configuration::get('PS_PURCHASE_MINIMUM')*1.6666667, $currency);}
        
        if ($this->context->cart->getOrderTotal(true, Cart::ONLY_PRODUCTS) < $minimal_purchase) {
            $err[] = sprintf(
                $this->l(
                    'A minimum purchase total of %1s (tax excl.) is required to validate'.
                    ' your order, current purchase total is %2s (tax excl.).'
                ),
                Tools::displayPrice($minimal_purchase, $currency),
                Tools::displayPrice(
                    $this->context->cart->getOrderTotal(true, Cart::ONLY_PRODUCTS),
                    $currency
                )
            );
        }

Edited by Neo_odessa (see edit history)
Link to comment
Share on other sites

To check the customer delivery address (id) you can try with

$this->context->cart->id_address_delivery

Then you can access to all customer address object 

$customer_delivery = new Address($this->context->cart->id_address_delivery);

and check the customer country id with

$customer_delivery->id_country 

 

Link to comment
Share on other sites

I`ve tried do how you suggested but nothing works Please check the code

I`ve added your suggestions on lines 272-274

    public function cartListErrors()
    {
        $err = array();
        $errors = array();
        $arr = array();
        $arr = $this->checkQuantitiesAlt();
        $currency = Currency::getCurrency((int)$this->context->cart->id_currency);
		$this->context->cart->id_address_delivery;
		$customer_delivery = new Address($this->context->cart->id_address_delivery);
				if ($customer_delivery->id_country = '216'){
		$minimal_purchase = Tools::convertPrice((float)Configuration::get('PS_PURCHASE_MINIMUM'), $currency);}
		else {
		$minimal_purchase = Tools::convertPrice((float)Configuration::get('PS_PURCHASE_MINIMUM')*1.6666667, $currency);}
        
        if ($this->context->cart->getOrderTotal(true, Cart::ONLY_PRODUCTS) < $minimal_purchase) {
            $err[] = sprintf(
                $this->l(
                    'A minimum purchase total of %1s (tax excl.) is required to validate'.
                    ' your order, current purchase total is %2s (tax excl.).'
                ),
                Tools::displayPrice($minimal_purchase, $currency),
                Tools::displayPrice(
                    $this->context->cart->getOrderTotal(true, Cart::ONLY_PRODUCTS),
                    $currency
                )
            );
        }

And strange when I`m adding this line

$customer_delivery->id_country = '216'

It showing in cart $minimal_purchase for all countries same as I`ve added in back office

 

and when I`m changing this line to

$customer_delivery->id_country == '216'

In cart showing $minimal_purchase *1.6 

Edited by Neo_odessa (see edit history)
Link to comment
Share on other sites

The red color code that you use it´s not necesary

 

$currency = Currency::getCurrency((int)$this->context->cart->id_currency);

$this->context->cart->id_address_delivery;

$customer_delivery = new Address($this->context->cart->id_address_delivery);

if ($customer_delivery->id_country == '216'){

$minimal_purchase = Tools::convertPrice((float)Configuration::get('PS_PURCHASE_MINIMUM'), $currency);}

else {

$minimal_purchase = Tools::convertPrice((float)Configuration::get('PS_PURCHASE_MINIMUM')*1.6666667, $currency);}

 

 

 

Keep in mind the module´s overrides or controllers that include.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...