Jump to content

Amount needed to add free shipping in blockcart - 1.4


Recommended Posts

I am trying to indicate the amount needed for free shipping in the blockcart.
I have been successful to the point of having it work on the cart summary page (which is redundant) but shows $0.00 on other pages.

I tried to add:

{if $free_ship > 0}

{l s='Remaining amount to be added to your cart in order to obtain free shipping:'}
{convertPrice price=$free_ship}

{/if}



I found a post for an old version of prestashop, but that don't work for the 1.4 :(

Thanks for any help.

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 year later...

file: modules/blockcart/blockcart.php

info: addin function smartyAssigns()

this code:

	  $total_free_ship = 0;
    if ($free_ship = Tools::convertPrice((float)(Configuration::get('PS_SHIPPING_FREE_PRICE')),
    new Currency((int)($params['cart']->id_currency))))
    {
	    $discounts = $params['cart']->getDiscounts();
	    $total_free_ship =  $free_ship - ($params['cart']->getOrderTotal(true, Cart::ONLY_PRODUCTS)
	    + $params['cart']->getOrderTotal(true, Cart::ONLY_DISCOUNTS));
	    foreach ($discounts as $discount)
		    if ($discount['id_discount_type'] == 3)
		    {
			    $total_free_ship = 0;
			    break;
		    }
    }

    $smarty->assign(array(
	    'free_ship' =>Tools::displayPrice($total_free_ship, $currency),
	    ..... rest code...

 

 

--------------------------

file: themes/YOUR_THEME/modules/blockcart/blockcart.tpl

info: add before line

<p id="cart-buttons" class="clearfix">

this code:

{if $free_ship > 0}
<p id="cart_block_free_ship">
   {l s='Dla darmowej wysyłki dodaj produkty na kwotę:' mod='blockcart'}
   <span  class="price ajax_block_cart_free_ship">{$free_ship}</span>
   <br/>
</p>    
{/if}

 

 

--------------------------

file: modules/blockcart/blockcart-json.tpl

info: add before line

"shippingCost":

this code:

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

 

 

--------------------------

file: modules/blockcart/ajax-cart.js

info: add after line

$('.ajax_block_cart_total').text(jsonData.total);

this code:

   $('.ajax_block_cart_free_ship').text(jsonData.free_ship);

       if(parseInt(jsonData.free_ship) > 0)
       {
           $('#cart_block_free_ship').fadeIn('slow');
       }else{
           $('#cart_block_free_ship').hide();

       }

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

  • 2 months later...

THANKS for the code subey, so useful

 

it worked for me on PS 1.4.5.1

just 2 advices:

the code:

$total_free_ship = 0;
		if ($free_ship = Tools::convertPrice((float)(Configuration::get('PS_SHIPPING_FREE_PRICE')),
		new Currency((int)($params['cart']->id_currency))))
		{
				$discounts = $params['cart']->getDiscounts();
				$total_free_ship =  $free_ship - ($params['cart']->getOrderTotal(true, Cart::ONLY_PRODUCTS)
				+ $params['cart']->getOrderTotal(true, Cart::ONLY_DISCOUNTS));
				foreach ($discounts as $discount)
						if ($discount['id_discount_type'] == 3)
						{
								$total_free_ship = 0;
								break;
						}
		}

		$smarty->assign(array(
				'free_ship' =>Tools::displayPrice($total_free_ship, $currency),
				..... rest code...

 

must be placed correctly to get it working, put this:

$total_free_ship = 0;
if ($free_ship = Tools::convertPrice((float)(Configuration::get('PS_SHIPPING_FREE_PRICE')),
		new Currency((int)($params['cart']->id_currency))))
		{
				$discounts = $params['cart']->getDiscounts();
				$total_free_ship =  $free_ship - ($params['cart']->getOrderTotal(true, Cart::ONLY_PRODUCTS)
				+ $params['cart']->getOrderTotal(true, Cart::ONLY_DISCOUNTS));
				foreach ($discounts as $discount)
						if ($discount['id_discount_type'] == 3)
						{
								$total_free_ship = 0;
								break;
						}
		}

 

just after:

public function smartyAssigns(&$smarty, &$params)
{
 global $errors, $cookie;

(line 46~)

 

and put this:

'free_ship' =>Tools::displayPrice($total_free_ship, $currency),

 

just after:

$smarty->assign(array(

(line 98~ after pasting previous code)

 

2nd advice:

to view correct translation just change

{l s='Dla darmowej wysyłki dodaj produkty na kwotę:' mod='blockcart'}

to

{l s='Remaining amount to be added to your cart in order to obtain free shipping:' mod='blockcart'}

 

and change file _your_language.php (fr.php, es.php, de.php...) from modules/blockcart adding:

$_MODULE['<{blockcart}prestashop>blockcart_67db993438213ca5b77a394bce7d7b41'] = 'your own traduction';

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

  • 2 months later...
  • 2 years later...
×
×
  • Create New...