Show Remaining amount to free shipping in cart

In the blockcart module, display the amount remaining to the free shipping.

This solution was tested on several prestashop 1.5 websites, should work for 1.6 as well.

 

Be sure to change the correct files. The .tpl and .js files of blockcart module are frequently overriden by files located in subfolders of the theme folder. If present, change the appropriate files in the /themes/mytheme/ subfolders.

 

1) /modules/blockcart/blockcart.php

add two separated blocks of code as indicated

public function assignContentVars(&$params)

{

global $errors;

 

// Set currency

if ((int)$params['cart']->id_currency && (int)$params['cart']->id_currency != $this->context->currency->id)

$currency = new Currency((int)$params['cart']->id_currency);

else

$currency = $this->context->currency;

 

$taxCalculationMethod = Group::getPriceDisplayMethod((int)Group::getCurrent()->id);

 

$useTax = !($taxCalculationMethod == PS_TAX_EXC);

// add these lines

$zaprodukty=(int)$params['cart']->getOrderTotal($useTax, Cart::ONLY_PRODUCTS);

$shippingFree=Configuration::get('PS_SHIPPING_FREE_PRICE') - $zaprodukty;

if($zaprodukty == 0) {

$shippingFree1='';

$shippingFree2='';

}

elseif($shippingFree < 0) {

$shippingFree1=$this->l('Shipping free');

$shippingFree2='';

}

else {

$shippingFree1 = $this->l('Remains to free shipping: ');

$shippingFree2 = Tools::displayPrice($shippingFree, $currency);

}

..............

.............

$this->smarty->assign(array(

'products' => $products,

'customizedDatas' => Product::getAllCustomizedDatas((int)($params['cart']->id)),

'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_,

'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_,

'discounts' => $cart_rules,

'nb_total_products' => (int)($nbTotalProducts),

'shipping_cost' => $shipping_cost,

'shippingFree1' => $shippingFree1,

'shippingFree2' => $shippingFree2,

'shipping_cost_float' => $shipping_cost_float,

'show_wrapping' => $wrappingCost > 0 ? true : false,

'show_tax' => (int)(Configuration::get('PS_TAX_DISPLAY') == 1 && (int)Configuration::get('PS_TAX')),

'wrapping_cost' => Tools::displayPrice($wrappingCost, $currency),

'product_total' => Tools::displayPrice($params['cart']->getOrderTotal($useTax, Cart::BOTH_WITHOUT_SHIPPING), $currency),

'total' => Tools::displayPrice($totalToPay, $currency),

'order_process' => Configuration::get('PS_ORDER_PROCESS_TYPE') ? 'order-opc' : 'order',

'ajax_allowed' => (int)(Configuration::get('PS_BLOCK_CART_AJAX')) == 1 ? true : false,

'static_token' => Tools::getToken(false)

));

if (count($errors))

$this->smarty->assign('errors', $errors);

if (isset($this->context->cookie->ajax_blockcart_display))

$this->smarty->assign('colapseExpandStatus', $this->context->cookie->ajax_blockcart_display);

 

}

 

2) in the theme folder find /js/modules/blockcart/ajax-cart.js (if not present check the /modules/blockcart folder)

add two lines as indicated

//update general cart informations everywhere in the page

updateCartEverywhere : function(jsonData) {

$('.ajax_cart_total').text(jsonData.productTotal);

 

if (parseFloat(jsonData.shippingCostFloat) > 0 || jsonData.nbTotalProducts < 1)

$('.ajax_cart_shipping_cost').text(jsonData.shippingCost);

else

$('.ajax_cart_shipping_cost').html(freeShippingTranslation);

 

$('.ajax_shippingFree1').text(jsonData.shippingFree1);

$('.ajax_shippingFree2').text(jsonData.shippingFree2);

 

3) in the theme folder find /modules/blockcart/blockcart-json.tpl (if not present check the /modules/blockcart folder)

add two lines as indicated

"wrappingCost": "{$wrapping_cost|html_entity_decode:2:'UTF-8'}",

"nbTotalProducts": "{$nb_total_products}",

"shippingFree1": "{$shippingFree1|html_entity_decode:2:'UTF-8'}",

"shippingFree2": "{$shippingFree2|html_entity_decode:2:'UTF-8'}",

"total": "{$total|html_entity_decode:2:'UTF-8'}",

 

4) in the theme folder find /modules/blockcart/blockcart.tpl (if not present check the /modules/blockcart folder)

add several lines just above the "cart-buttons" section

{if isset($shippingFree1)}


{$shippingFree1}


{$shippingFree2}



{/if}

 

 

webdnes.cz
®2016