Jump to content

Modification for Ajax-cart.js in order to calculate the remaining sum until free shipping


Recommended Posts

Hi guys, 

 

I think this would be usefull not only for me. So, I am working now on blockcart module. And I want to make somethink that will calculate how much remains to add to cart until free shipping. I saw this on some websites, it is very usefull, it makes users to get interested and adds some more items to cart.

 

So, by far its not that hard to make it in the blockcart.tpl, however it will work only after user refresh the page. But in my case where all products are on homepage, and there will be no refresh from user side, I really need to get it done through ajax-cart.js and blockcart-json.tpl.

 

1. I use one shipping option only & and one payment method (however I think that is not so important)

2. I configured my carrier so that it will be a fixed price for shipping for order under 200$ and free shipping for orders above 200$

 

In blockcart.tpl I made this:

<span>{l s='Shipping' mod='blockcart'} 
<b class="price cart_block_shipping_cost ajax_cart_shipping_cost{if !($page_name == 'order-opc') && $shipping_cost_float == 0 && (!$cart_qties || $cart->isVirtualCart() || !isset($cart->id_address_delivery) || !$cart->id_address_delivery || $free_ship)} unvisible{/if}">
{if $shipping_cost_float == 0}


{if !($page_name == 'order-opc')} <!-- && (!isset($cart->id_address_delivery) || !$cart->id_address_delivery) -->
{l s='To be determined' mod='blockcart'}
{else}
   {l s='Free shipping!' mod='blockcart'}
{/if}
{else}
{$shipping_cost}


{/if}
</b>
</span>
<span class="small price cart_block_shipping_cost ajax_cart_shipping_cost_2">{l s='For free delivery still needs' mod='blockcart'} - {200 - {$total[spam-filter]</span>

in blockcart-json.tpl, right after line "shippingCost": {$shipping_cost|json_encode}," I added this:

"shippingCost_2": {l s='For free delivery still needs' mod='blockcart'} - {200 - $total|json_encode},

And in ajax-cart.js right after:

//update general cart informations everywhere in the page
updateCartEverywhere : function(jsonData){
$('.ajax_cart_total').text($.trim(jsonData.productTotal));

I added:

$('.ajax_cart_shipping_cost_2').text(jsonData.shippingCost_2);

AND IT'S NOT WORKING! But I am sure I am on the right way. I only need help to fix my mistakes since I am not [spam-filter] in ajax and json.

 

please help me!

Edited by Andron777 (see edit history)
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...