Jump to content

Countdown until free shipping 1.6 problem


newshopholder

Recommended Posts

There is a topic on this forum about a count down until free shipping, but it is for older versions.

 

The count down shows the remaining amount until the free shipping.

For example: spend another 2 dollar to earn free shipping!

Or, when people already have earned the free shipping: You earned free shipping!

 

But i tried it on the 1.6 version and it worked! But there are a few problems..
Does someone now how to fix them?

 

When you are in the shopping cart, and you use the + / - buttons to modify the quantity of a product, or delete a product, the count down works very smooth! Really nice.

 

But when you refresh the shopping cart page, he says: You earned free shipping!

But that is incorrect, because you see it also when you are (far!) under that free shipping amount.

 

Also, when you go from another page to the shopping cart he shows the wrong: 'you earned free shipping!' text.

 

Why does it work with Ajax, and why does it not work with a normal page loading?

 

This is what i have changed:

 

Shoppingcart.tpl:

<p id="amount_free_shipping">
  <span class = "ajax_shipping_free_price_span {if ($amount_until_free_shipping_float) <= 0} hidden {/if}">{l s='Spend' mod="blockcart"} <span class="ajax_shipping_free_price">{$amount_until_free_shipping}</span> {l s='more for FREE SHIPPING!' mod="blockcart"}</span>
 
  <span class = "ajax_shipping_free_price_free_span {if ($amount_until_free_shipping_float) > 0} hidden {/if}">{l s='Buying more than' mod="blockcart"} <span class="ajax_shipping_free_price_free">{$shipping_free_price}</span> {l s='earned you FREE SHIPPING!!!' mod="blockcart"}</span>
  </p>

In modules/blockcart/blockcart.php

$shipping_free_price= Tools::convertPrice((float)(Configuration::get('PS_SHIPPING_FREE_PRICE')), $currency);
		$amount_until_free_shipping_float = ($shipping_free_price - $params['cart']->getOrderTotal($useTax, Cart::BOTH_WITHOUT_SHIPPING));

and also;

'shipping_free_price' => Tools::displayPrice($shipping_free_price),
            'amount_until_free_shipping' => ($shipping_free_price - $params['cart']->getOrderTotal($useTax, Cart::BOTH_WITHOUT_SHIPPING)),
            'amount_until_free_shipping_float' => (float)($amount_until_free_shipping_float),

In blockcart-json.tpl:

"amount_until_free_shipping" : "{$amount_until_free_shipping|html_entity_decode:2:'UTF-8'}",
"product_total": "{$product_total|html_entity_decode:2:'UTF-8'}",
"shipping_free_price": "{$shipping_free_price|html_entity_decode:2:'UTF-8'}",

And in the themes/<your theme folder>/js/modules/blockcart/ajax-cart.js:

$('.ajax_shipping_free_price').text(jsonData.amount_until_free_shipping);
          if (parseFloat(jsonData.amount_until_free_shipping) > 0)
          {
               $('.ajax_shipping_free_price_span').each( function() {
                    $(this).removeClass('hidden');
               });

               $('.ajax_shipping_free_price_free_span').each( function() {
                    $(this).addClass('hidden');
               });
          }
          else
          {
               $('.ajax_shipping_free_price_span').each( function() {
                    $(this).addClass('hidden');
               });

               $('.ajax_shipping_free_price_free_span').each( function() {
                    $(this).removeClass('hidden');
               });
          }

Thanks in advance!

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...