Jump to content

amount needed to add for free shipping in blockcart


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 added:

{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}



to the blockcart.tpl

Thanks for any help

Harley Bill :coolgrin:

14652_5F2viBSOmGXRxcyKuh0R_t

Link to comment
Share on other sites

Hi Harley Bill
I'm trying to do the same and i also found in shopping-cart.tpl :

{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} 


that i tried to use in blockcart.tpl but it ain't working ! :-S
Did you find a solution ?
Any clue, people ?
Thanks to all good will to help solve this !!
I keep working on it....

Rog'

Link to comment
Share on other sites

  • 2 months later...

This is driving me bonkers as well.

The code above doesn't work on pages other than order.php because the variable $free_ship is assigned in order.php, line 388.

I tried to add similar code to the smartyAssigns function in blockcart.php, but that doesn't work either.

In blockcart.php:

function smartyAssigns(&$smarty, &$params)
{

....

$summary = $cart->getSummaryDetails();
if ($free_shipping = intval(Configuration::get('PS_SHIPPING_FREE_PRICE')))
    $smarty->assign('free_shipping', $free_shipping - ($summary['total_products_wt'] + $summary['total_discounts']));



In blockcart.tpl:



Order {convertPrice price=$free_shipping} more for free shipping!



Any thoughts, code, or progress?

Link to comment
Share on other sites

hi chuko,
I didn't find a nice solution, so here is what i did :
in ajax-cart.js, i added the following code on line 509 i think, just after
updateCartEverywhere : function(jsonData) {
$('.ajax_cart_total').text(jsonData.productTotal);
$('.ajax_cart_shipping_cost').text(jsonData.shippingCost);
$('.cart_block_wrapping_cost').text(jsonData.wrappingCost);
$('.ajax_block_cart_total').text(jsonData.total);

var Free_Delivery = jsonData.productTotal;
       Free_Delivery = Free_Delivery.length-2;
       Free_Delivery =jsonData.productTotal.substring(0, Free_Delivery);
       Free_Delivery = Free_Delivery.replace(",",".");
       Free_Delivery = parseFloat(Free_Delivery);
       if(Free_Delivery > 0){
           if(Free_Delivery >= 98){ // 98 is the amount to have free shipping
               $('.Free_Delivery_Offer').text("We offer shipping!");
           }else{
               var left_amount;
               left_amount =parseFloat(left_amount);
               Free_Delivery = parseFloat(Free_Delivery);
               left_amount = 98-Free_Delivery;
               left_amount = Math.round(left_amount*100)/100;
               $('.Free_Delivery_Offer').text("you have to phurchase "+ left_amount +"€ more to get free shipping");
           }
       }else{
           $('.Free_Delivery_Offer').text("");
       }




And i added this in blockcart.tpl where i want the text to appear :




That's not a nice code, but couldn't find another solution. Well, i didn't want to spend to long on that, i had more to do !
The problem here, is that if you change the amount for free shipping in your administration, you must change it manually in ajax-cart.js. (here i choose 98€)

if someone find a proper solution which get automatically the amount from PS, it would be nice.

I hope you understand everything as english ain't my language.

Good luck !

Link to comment
Share on other sites

Thanks Rog'!

I also came up with a not-so-beautiful way to do it. It works, but one has to modify blockcart.php in the shop/modules directory, rather than at the theme level.

blockcart-jsn.tpl
Add the line, line 72:

'freeShipping': '{$free_shipping|html_entity_decode:2:'UTF-8'}',


in context:

'shippingCost': '{$shipping_cost|html_entity_decode:2:'UTF-8'}',
'wrappingCost': '{$gift_wrapping_price|html_entity_decode:2:'UTF-8'}',
'nbTotalProducts': '{$nb_total_products}',
'total': '{$total|html_entity_decode:2:'UTF-8'}',
'productTotal': '{$product_total|html_entity_decode:2:'UTF-8'}',
'freeShipping': '{$free_shipping|html_entity_decode:2:'UTF-8'}',



ajax-cart.js
add these lines to the updateCartEverywhere function, starting at line 467

               $('.ajax_block_cart_free_shipping').text(jsonData.freeShipping);
       if(jsonData.freeShipping > 0)
       {
           $('#cart_block_free_shipping:hidden').show();
       }
       else
       {
           $('#cart_block_free_shipping:visible').hide();
       }


in context:

   //update general cart informations everywere in the page
   updateCartEverywhere : function(jsonData) {
       $('.ajax_cart_total').text(jsonData.productTotal);
       $('.ajax_cart_shipping_cost').text(jsonData.shippingCost);
       $('.cart_block_wrapping_cost').text(jsonData.wrappingCost);
       $('.ajax_block_cart_total').text(jsonData.total);
       $('.ajax_block_cart_free_shipping').text(jsonData.freeShipping);
       if(jsonData.freeShipping > 0)
       {
           $('#cart_block_free_shipping:hidden').show();
       }
       else
       {
           $('#cart_block_free_shipping:visible').hide();
       }



/shop/modules/blockcart.php
Add these lines to the smartyAssigns function, line 33

       $summary = $params['cart']->getSummaryDetails();
       if ($free_shipping = intval(Configuration::get('PS_SHIPPING_FREE_PRICE')))
           $smarty->assign('free_shipping', $free_shipping 
                         - ($summary['total_products_wt'] + $summary['total_discounts']));


in context:

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

       // Set currency
       if (!intval($params['cart']->id_currency))
           $currency = new Currency(intval($params['cookie']->id_currency));
       else
           $currency = new Currency(intval($params['cart']->id_currency));
       if (!Validate::isLoadedObject($currency))
           $currency = new Currency(intval(Configuration::get('PS_DEFAULT_CURRENCY')));

       $summary = $params['cart']->getSummaryDetails();
       if ($free_shipping = intval(Configuration::get('PS_SHIPPING_FREE_PRICE')))
           $smarty->assign('free_shipping', $free_shipping - ($summary['total_products_wt'] + $summary['total_discounts']));

       $smarty->assign(array(
           'products'=> $params['cart']->getProducts(true),
           'customizedDatas' => Product::getAllCustomizedDatas(intval($params['cart']->id)),
           'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_,
           'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_,
           'discounts' => $params['cart']->getDiscounts(),
           'nb_total_products' =>$params['cart']->nbProducts(),
           'shipping_cost' => Tools::displayPrice($params['cart']->getOrderTotal(true, 5), $currency),
           'show_wrapping' => floatval($params['cart']->getOrderTotal(true, 6)) > 0 ? true : false,
           'wrapping_cost' => Tools::displayPrice($params['cart']->getOrderTotal(true, 6), $currency),
           'product_total' => Tools::displayPrice($params['cart']->getOrderTotal(true, 4), $currency),
           'total' => Tools::displayPrice($params['cart']->getOrderTotal(), $currency),
           'id_carrier' => $params['cart']->id_carrier,
           'ajax_allowed' => intval(Configuration::get('PS_BLOCK_CART_AJAX')) == 1 ? true : false
       ));
       if (sizeof($errors))
           $smarty->assign('errors', $errors);
       if(isset($params['cookie']->ajax_blockcart_display))
           $smarty->assign('colapseExpandStatus', $params['cookie']->ajax_blockcart_display);
   }



blockcart.tpl
add at line 108



Order ${$free_shipping} more and get free shipping!


in context:

           {if $show_wrapping}
{l s='Wrapping' mod='blockcart'}
{$wrapping_cost}


           {/if}
{l s='Total' mod='blockcart'}
{$total}




Order ${$free_shipping} more and get free shipping!




{l s='Cart' mod='blockcart'}
{l s='Check out' mod='blockcart'}



global.css

#cart_block_free_shipping {
   padding-bottom:0.8em;
}
#cart_block #cart_block_free_shipping span{
   text-align: left;
   float: none;
}



Hope this is helpful to someone!

Link to comment
Share on other sites

  • 1 year later...

Hello,

 

Thanx for your work in this.. I think your fix, or an improved one, should been a standart option on Prestashop.

 

I tried to do this for PS 1.4.4 but, to bad, it gives errors.

 

It's showing correctly the amount that needs to be spent. But the errors comes up when i tried to add some products to the cart.

It gives an parsererror.

 

Is there any chance you want to have a look at this?

 

I think the basics of your code still works.

 

Greetings, thanks in advance, Jos

Link to comment
Share on other sites

  • 8 months later...

file: modules/blockcart/blockcart.php

info: add in 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)
Link to comment
Share on other sites

  • 4 weeks later...

file: modules/blockcart/blockcart.php

info: add in 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();

	}

 

I'm very sorry but after adding this code my page is not loading at all. Anyone has any other suggestions than this?

Link to comment
Share on other sites

×
×
  • Create New...