When looking through the Prestashop forum I paid attention to this thread. The feature which the user is looking for is quite useful and today we’ll show how to implement it in version 1.5.
The minimal order amount for free shipping can be specified in the back office under the Shipping tab:
To calculate missing amount you need to do override the function PаrentOrderCоntrоller::_аssignSummаryInfоrmаtiоns() by adding the following lines:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
... if ($free_ship = Tools::convertPrice((float)(Configuration::get('PS_SHIPPING_FREE_PRICE')), new Currency((int)($this->context->cart->id_currency)))) { $discounts = $this->context->cart->getCartRules(); $total_free_ship = $free_ship - ($summary['total_products_wt'] + $summary['total_discounts']); foreach ($discounts as $discount) If ( $discount['id_disсоunt_type']) == 3) { $total_free_ship = 0; break; } $summary['free_ship'] = $total_free_ship; } ... |
In the code above, we have identified the variable free_ship, which we will use in the template shopping-cart.tpl . The code below we have added at the end of the block <tfооt>
1 2 3 4 5 6 |
... <tr class="remaining_cart_free_shipping" {if $free_ship <= 0 || $isVirtualCart} style="display: none;" {/if}> <td colspan="6" style="white-space: normal;">{l s='Remaining amount to be added to your cart in order to obtain free shipping:'}</td> <td id="free_shipping" class="price">{displayPrice price=$free_ship}</td> </tr> ... |
Here is the result:
To ensure that our new block will appear and disappear when changing AJAX shopping cart we should override the function CаrtCоntrоller::displаyAjаx() by adding the following code before calling the hook асtiоnCаrtListOverride :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
… if ($free_ship = Tools::convertPrice((float)(Configuration::get('PS_SHIPPING_FREE_PRICE')), new Currency((int)($this->context->cart->id_currency)))) { $discounts = $this->context->cart->getCartRules(); $total_free_ship = $free_ship - ($result['summary']['total_products_wt'] + $result['summary']['total_discounts']); foreach ($discounts as $discount) If ( $discount[ 'id_disсоunt_type') == 3) { $total_free_ship = 0; break; } $result['summary']['free_ship'] = $total_free_ship; } ... |
This code will allow using data about the short fall of the amount required for free delivery in the theme file cart-summary.js. We’ll need to change the function updаteCаrtSummаry(jsоn) by adding these lines:
1 2 3 4 5 |
if (json.free_ship >= 0) { $(".remaining_cart_free_shipping").show(); } else { $(".remaining_cart_free_shipping").hide(); } |
I can’t find a solution for the 1.6.0 version :(
I do not use the default ‘free shipping starts at’, because we ship to different countries.
So for 1 country free shipping starts at € 15,- and for other countries there is no free shipping.
Anyone? I just need it into the cart
Thanks a lot!!!!
Alain DROZD,
Thanks!
Hi Alex,
I forgot to put in right place lines in updаteCаrtSummаry(jsоn) !
Everything is OK now!!!!
Best regards, and thanks for advice !
Hello ! Good news : it work well on 1.6.0.11 !
Great !!! Thanks a lot !
Just one thing : Ajax cart update works, if I remove one product , remaining amount to pay is updated well. If I reach or exceed amount, it disappear.
But, after exceeding amount, if I remove a product and amount become under amount for free shipping, “Remaining amount to be added …xx€ ” does not redisplay. To redisplay, I have to refresh page.
Perhaps something to add in cart-summary.js ?
“It seems that you have a customized theme. The problem can be in JS code that is responsible for these blocks.”
Not a customized theme, on presta 1.5.6 there is a different php code and that’s why not work Alex.
It seems that you have a customized theme. The problem can be in JS code that is responsible for these blocks.
Doesn’t work like it should. I’m using Presta 1.5.6.0. At first the additional info stays hidden. With the helf of Firebug I see that the amount for free shipping isn’t calculated (I see 0.00). It shows and starts calculating only when I start manipulating with quantity of the products. What is more when I go back from next steps (eg. 4 or 5) to the 1st step, the remainig amount sets itself to 1.00 no matter what :| It again starts working when I manipulate with quantity.
Adam S,
Most probably you did something wrong. If you need our help, please contact our support team at [email protected] and they will help you.
Hello,
It is possible, this does not work in version 1.5.4? Coz, after when I edit ParentOrderController.php, get white page. (and of course, fixed If> if)
I confirm that this code works , i just used it on my 1.6 installation of prestashop.
But it still needs a solution for showing the same message on blockcart module.
Anyone already did it?
Julienrezo,
Thanks a lot! I fixed it.
Great job. Just 2 errors this line :
If ( $discount[ ‘id_disсоunt_type’) == 3)
This will be :
if ( $discount[‘id_disсоunt_type’) == 3)
sry i found it just a strange problem form copying and pasting on notepad++, but when I type it it found :S
Hello:
I have 1.5.5.0 version. I have checked the file
controllers/front/CartController.php
I can’t find this function :(
Thanks
Fred,
PаrentOrderCоntrоller is the file controllers/front/ParentOrderController.php
CаrtCоntrоller::displаyAjаx() is placed in controllers/front/CаrtCоntrоller.php file.
Could you write exacly what files that i have to override?
where is that:
function PаrentOrderCоntrоller::_аssignSummаryInfоrmаtiоns()
and that
CаrtCоntrоller::displаyAjаx()
?
Chris,
in controllers/front/CartController.php.
hello, to which file you need to paste this code:
if ($free_ship = Tools::convertPrice((float)(Configuration::get(‘PS_SHIPPING_FREE_PRICE’)), new Currency((int)($this->context->cart->id_currency))))
{
$discounts = $this->context->cart->getCartRules();
$total_free_ship = $free_ship – ($result[‘summary’][‘total_products_wt’] + $result[‘summary’][‘total_discounts’]);
foreach ($discounts as $discount)
If ( $discount[ ‘id_disсоunt_type’) == 3)
{
$total_free_ship = 0;
break;
}
$result[‘summary’][‘free_ship’] = $total_free_ship;
mistake:
If ( $discount[ ‘id_disсоunt_type’) == 3)
correct:
If ( $discount[ ‘id_dis??unt_type’] == 3)