Jump to content

[SOLVED] Minimum purchase total required related to city name or zip code


Recommended Posts

Hello
 
i use p.s 1.5.4.1, default theme, OPC and i have the next situation:
 
I deliver pizza only to 4 specific destinations (e.g. London, Paris, Madrid, Rome). These destinations are defined in "order-opc-new-account.tpl" as follows:
 
<label for="city">{l s='City'} <sup>*</sup></label>
         <select id="city" name="city">
                     <option value="London">London</option>
                     <option value="Paris">Paris</option>
                     <option value="Madrid">Madrid</option>
                     <option value="Rome">Rome</option>
         </select>
 
i need the "Minimum purchase total required" to differ like this: for London and Paris i need to be 10€  (already set in back office) and for the rest 15€
 
i have in /controllers/front/OrderOpcController.php line 471:
 
 

/* Check minimal amount */
        $currency = Currency::getCurrency((int)$this->context->cart->id_currency);

        $minimalPurchase = Tools::convertPrice((float)Configuration::get('PS_PURCHASE_MINIMUM'), $currency);
        if ($this->context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS) < $minimalPurchase)
            return '<p class="warning">'.sprintf(
                Tools::displayError('A minimum purchase total of %s is required in order to validate your order.'),
                Tools::displayPrice($minimalPurchase, $currency)
            ).'</p>';


 
if i reolace this with the next one, would it work? did i miss something?


/* Check minimal amount */
$currency = Currency::getCurrency((int)$this->context->cart->id_currency);

if ($address_delivery->city == 'London' && $address_delivery->city == 'Paris' )
$minimalPurchase = Tools::convertPrice((float)Configuration::get('PS_PURCHASE_MINIMUM'), $currency);
else
$minimalPurchase = 15;

if ($this->context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS) < $minimalPurchase)
return '<p class="warning">'.sprintf(
Tools::displayError('A minimum purchase total of %s is required in order to validate your order.'),
Tools::displayPrice($minimalPurchase, $currency)
).'</p>';

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

i figured out what i was wrong.

This is the code that works for me, maybe it will be helpful for someone else too:

 

/* Check minimal amount */
        $currency = Currency::getCurrency((int)$this->context->cart->id_currency);
        if ($address_delivery->city == 'Madrid' || $address_delivery->city == 'Rome')
            $minimalPurchase = 14;  /*price excl. taxes*/
        else
            $minimalPurchase = Tools::convertPrice((float)Configuration::get('PS_PURCHASE_MINIMUM'), $currency);
        if ($this->context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS) < $minimalPurchase)
            return '<p class="warning">'.sprintf(
                Tools::displayError('A minimum purchase total of %s is required in order to validate your order.'),
                Tools::displayPrice($minimalPurchase, $currency)
            ).'</p>';

Edited by sooroos (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 2 years later...

Hi,

I tried to do the code for 'postcode' but it does not work, 

can you please tell me if the code is right ?

/* Check minimal amount */
        $currency = Currency::getCurrency((int)$this->context->cart->id_currency);


 if ($address_delivery->postcode == 'ZABEEL' || $address_delivery->postcode == 'JVC')
            $minimalPurchase = 200;  /*price excl. taxes*/


        else


        $minimal_purchase = Tools::convertPrice((float)Configuration::get('PS_PURCHASE_MINIMUM'), $currency);
        if ($this->context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS) < $minimal_purchase) {
            return '<p class="warning">'.sprintf(
                Tools::displayError('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(false, Cart::ONLY_PRODUCTS), $currency)
            ).'</p>';
        }

Link to comment
Share on other sites

 

Hi,

I tried to do the code for 'postcode' but it does not work, 

can you please tell me if the code is right ?

/* Check minimal amount */
        $currency = Currency::getCurrency((int)$this->context->cart->id_currency);


 if ($address_delivery->postcode == 'ZABEEL' || $address_delivery->postcode == 'JVC')
            $minimalPurchase = 200;  /*price excl. taxes*/


        else


        $minimal_purchase = Tools::convertPrice((float)Configuration::get('PS_PURCHASE_MINIMUM'), $currency);
        if ($this->context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS) < $minimal_purchase) {
            return '<p class="warning">'.sprintf(
                Tools::displayError('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(false, Cart::ONLY_PRODUCTS), $currency)
            ).'</p>';
        }

 

i see that you use postcode (address_delivery->postcode) and that should be a number, in my example i used the cityname. and that code  was for p.s. 1.5.4.1 or so

Link to comment
Share on other sites

i dont rly know in this situation what the error could be.

do you have any errormessage, what ps version do you use?

does the code work with the city for example??

 

i dont rly know in this situation what the error could be.

do you have any errormessage, what ps version do you use?

does the code work with the city for example??

I just found the error. 

in 1.6 it's  &minimal_purchase   Not  $minimalpurchase

anyways, thank you for your quick reply.

 

now the problem is there is no message for the customer, only the Payment methods are inactive !

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...