Jump to content

Show Remaining amount to free shipping in cart


sJakub

Recommended Posts

Hi,

 

Im really not sure why this dissapeared from 1.5..

 

even if I try use same code from presta 1.4 template

 

  <tr class="cart_free_shipping">
 <td colspan="5" style="white-space: normal;">{l s='Remaining amount to be added to your cart in order to obtain free shipping:'}</td>
 <td> </td>
 <td id="free_shipping" class="price">{displayPrice price=$free_ship}</td>
</tr>

 

it is showing 0 till the amount a 1 when you reach the amount... so seems like it works only like true / false

 

Please is here anybody who can help with this? I will very appreciate your help!

Link to comment
Share on other sites

  • 4 weeks later...

Did you get this solved? 

 

I can get it in my template by adding this in my blockcart.php:

//get shipping cost quota
$shipping_cost_quota= Tools::convertPrice((float)(Configuration::get('PS_SHIPPING_FREE_PRICE')));

And then adding this piece of code in my template where needed:

{if ($shipping_cost_quota - $total)>0}
<p id='envioQuota'>	
<span id="envioQuotaText">How much left till free shipping</span>
<span id="envioQuotaPrice" class="price">{$shipping_cost_quota - $total}€</span>
</p>
{/if}

The problem i have know that i cannot seem to update it with javascript... i don't get it in my response from the ajax call. And i'm already stuck a few days searching where the query comes from... but unable to find it. Since it's my first project in Prestashop, i'm a bit of a noob :P

 

Has someone got a better solution or a fix? Or at least tell me what function creates the response for the ajax call when adding a product to cart?

 

Thanks in advance :)

 

 

EDIT: 

 

Found it just give the Smarty variable to blockcart json template file and then you can use it in js file :) This should be standard available in Prestashop :P

Edited by toStephen (see edit history)
Link to comment
Share on other sites

  • 3 weeks later...

I managed to show that: ...Remaining to spend for free shipping:..

 

here's what I figured out...

 

step 1 in blockcart.php (at line70) add

//get shipping cost quota
        $shipping_cost_quota= Tools::convertPrice((float)(Configuration::get('PS_SHIPPING_FREE_PRICE')));


and
at line 120

'shipping_cost_quota' => > $shipping_cost_quota,


step 2.
in the blockcart-json.tpl
line96 add

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


step 3.
to blockcart.tpl line 80,  add the formula, (can add it anywhere inside $products) ...

{if ($shipping_cost_quota - $total)>0}
        <p id="envioQuota">
            Remaining to spend for free shipping:<span class="ship-free">{$shipping_cost_quota-$product.total_wt}€</span>
        </p>
    {else}
        <p id="envioQuota">
            If you spend<span class="ship-free">{$shipping_cost_quota}€</span> free shipping!!!
        </p>    
    {/if}

cheers !!

Link to comment
Share on other sites

OK, 'summarizing' some code above and adding the real time update in the shopping cart using ajax, we can do as follows:

(Code taken from PrestaShop 1.5.5.0.)

We'll go throughout the whole cycle. From getting the (fixed) value to get free shipping to showing and real-time updating the value when adding/deleting products to/from the shopping cart.

Preparation:
Check if you have the following files in place:
/modules/blockcart/blockcart.php  (if not, install the block cart module)
/themes/<your theme folder>/modules/blockcart/blockcart.tpl   (if not, copy from /modules/blockcart/)
/themes/<your theme folder>/modules/blockcart/blockcart-json.tpl   (if not, copy from /modules/blockcart/)
/themes/<your theme folder>/js/modules/blockcart/ajax-cart.js   (if not, copy from /modules/blockcart/)


The "free shipping starts at"-value we talk about can be changed in Shipping->Shipping. "Free shipping starts at":


Edit file modules/blockcart/blockcart.php: (Always make backup of original files, just in case…)

in function:   public function assignContentVars($params) 

add this:

          ...

          $shipping_cost = Tools::displayPrice($base_shipping, $currency);
          $shipping_cost_float = Tools::convertPrice($base_shipping, $currency);
          $wrappingCost = (float)($params['cart']->getOrderTotal($useTax, Cart::ONLY_WRAPPING));
          $totalToPay = $params['cart']->getOrderTotal($useTax);
          $shipping_free_price= Tools::convertPrice((float)(Configuration::get('PS_SHIPPING_FREE_PRICE')), $currency);

          if ($useTax && Configuration::get('PS_TAX_DISPLAY') == 1)
              …



What it does: 
We get the value out of the ps_configuration table and convert it whenever needed to another currency.



Then scroll a little down, until you see a block of code assigning values to smarty variables

          $this->smarty->assign(array(
               ... 
               'product_total' => $params['cart']->getOrderTotal($useTax, Cart::BOTH_WITHOUT_SHIPPING),
               'total' => Tools::displayPrice($totalToPay, $currency),
               'shipping_free_price' => $shipping_free_price,
               'amount_until_free_shipping' => ($shipping_free_price - $params['cart']->getOrderTotal($useTax, Cart::BOTH_WITHOUT_SHIPPING)),
               '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)
               ...


What it does:
Here we calculate the actual difference of how much the customer needs to spend to get free shipping, and make the value available to the cart. Also the free shipping amount we will make available, to inform him/her how much he/she needs to spend at least to KEEP the free shipping, when there's put enough in the cart already.

Save the file


Edit file themes/<your theme folder>/modules/blockcart/blockcart-json.tpl: (Backup the original file...)

Almost at the end of the file, add the two red lines:

"wrappingCost": "{$wrapping_cost|html_entity_decode:2:'UTF-8'}",
"productTotal": "{$product_total|html_entity_decode:2:'UTF-8'}",
"nbTotalProducts": "{$nb_total_products}",
"total": "{$total|html_entity_decode:2:'UTF-8'}",

"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'}",


What it does:
We add the variable $product_total (sum of all products, including discounts, but excluding shipping) to compare the free shipping-amount to and we make our $shipping_free_price available in our ajax cart

Save the file.



Edit the file themes/<your theme folder/modules/blockcart/blockcart.tpl. (Again, make backup!)


almost at the end of the file, add the red code:


 <p id="cart-prices">
  <p id="amount_fee_shipping">
  <span class = "ajax_shipping_free_price_span {if ($amount_until_free_shipping) <= 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) > 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"}
 </p>

 <span id="cart_block_shipping_cost" class="price ajax_cart_shipping_cost">{$shipping_cost}</span>
 <span>{l s='Shipping' mod='blockcart'}</span>
 <br/>
 {if $show_wrapping}
 ...


What it does:
Here we put the values in the page. You can choose where to put it, but I put it just above the shipping price line, to keep it nicely together.

We put it in a div, to make css activity possible on the whole block, and to make it a separate line.
then we add two lines, of which only one of them is only shown at any single time. The other one will be hidden.
The first line will be shown when there's not enough product's price in the cart to get free shipping. It informs how much they need to spend more to get there.
The second line will be shown when they DO have enough in their shopping cart already to qualify for free shipping. It informs how much the have to spend at least to keep the free shipping (whenever they want to delete any product later), so they don't have to guess.

One of each will be hidden, dependent of the $amount_until_free_shipping:
- when it's value is <=0 (they passed the threshold). The first line is hidden, the second line is shown.
- when it's value is >0 (they didn't pass the threshold yet). The first line is shown, the second line is hidden.
N.B. Hiding is done by adding the class "hidden" to the encompassing <span> of each line.

 

All displayed text lines are made translatable (localization->translations, installed modules translations) for when other languages (or other English wording) is preferred. A translatable field before and after the price gives flexibility

The price has a separate span around it to separate the css decoration from the text, to make it possible to give it another colour, change the font size etc.

Save the file.


By now, the value is shown correctly, whenever you do a refresh of your screen. But when adding products, you don't want to refresh the whole page, but only update the cart block.

That's where the ajax-cart.js kicks in:
We prepared our json file so that the values will be made available in javascript.
So now we let our ajax-cart handle the hiding/showing of the appropriate line, and update the value in the block:

Edit file: themes/<your theme folder>/js/modules/blockcart/ajax-cart.js (As always, backup…)

To update the values (and hide/show lines accordingly), we edit the function  updateCart : function(jsonData)
or more precisely a function within this function:

     updateCartEverywhere : function(jsonData) :
 

add the red code:

     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 if (typeof(freeShippingTranslation) != 'undefined')
                    $('.ajax_cart_shipping_cost').html(freeShippingTranslation);
          $('.ajax_cart_tax_cost').text(jsonData.taxCost);
          $('.cart_block_wrapping_cost').text(jsonData.wrappingCost);
          $('.ajax_block_cart_total').text(jsonData.total);

          $('.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');
               });
          }


          this.nb_total_products = jsonData.nbTotalProducts;
         
          if (parseInt(jsonData.nbTotalProducts) > 0)
          {
           ...


What it does:
The line:
          $('.ajax_shipping_free_price').text(jsonData.amount_until_free_shipping);

updates the value of how much the customer needs to buy more.
The rest of the lines checks if there is enough in the cart or not,a nd displays/hides one of the two lines accordingly, as explained above.


Save the file.


Reload your page (Ctrl-F5 (Windows/Command-R (Mac) ) and see if it works. add more products to reach the free shipping level and see if the line changes. Delete one or more products and see if the old line comes back and the amount left to get to free shipping is correct.

You may need to (TEMPORARILY!!):  - turn OFF your smarty cache and - 'Template cache' set to "Recompile templates if the files have been updated" in Advanced Parameters->Performance
to see the changes. (Don't forget to turn cache back ON afterwards!)
 

I didn't add any suggestion for css decoration, as this you can all do according to your own preference (look at the class ="xxx" to get the class names, or id="yyy" to get the id names). If any question about this, do ask though.

 

Hope this helps,
pascal

  • Like 3
Link to comment
Share on other sites

that's what I call "smooth solution....."

I'm trying it out and so far it looks perfect....

 

 

one thing, in your tpl code, in order for it to work , I had to change:

($amount_until_free_shipping) <= 0}

to

($amount_until_free_shipping) le 0}
Link to comment
Share on other sites

also I changed :

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

to:

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

in this way the output is price,

 

version 1.5.4.1,

and so far it's working fine,

 

ajax smooth,

 

Good job pascal!

Link to comment
Share on other sites

Hi all,

 

it works perfect with 1.5.5.0 - thank you!

 

There is just one small thing. If you want to be able to translate the texts in the template you should use ' instead of " for the strings.

 

So use rather this code in the blockcart.tpl, if your site is using translations:

<p id="cart-prices">
  <p id="amount_fee_shipping">
  <span class = "ajax_shipping_free_price_span {if ($amount_until_free_shipping) <= 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) > 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'}
</p>

With this code you will be able to translate the message with the PrestaShop built in translation tool for modules.

 

k3rn3l3rr0r

Link to comment
Share on other sites

Just implemented this in our shop.

 

Works perfect!

 

Maybe anyone does know how to print/show customers telephone number on the packing slip.

And i mean not below the address, but anywhere i want it on the packing slip.

Link to comment
Share on other sites

Weckie,

was this the same question we answered here:

http://www.prestashop.com/forums/topic/279177-solved-customer-phone-number-on-delivery-slip/?do=findComment&comment=1403628

 

Let me know if you need anything else.

pascal

 

Yes Pascal,  it was.

 

And you helped me perfectly. This mod and the Phone mod both work great.

 

Later today i will have a look at modding the email adress also on the delivery slip.

Already saw your reply...  just didnt have time for it yet :(

 

Thx

weckie

Link to comment
Share on other sites

Hi ,

http://www.prestasho...p/#entry1403628

I read the post , really well explained;

 

___________________________________________________

 

I have a question about the blockcart subject for you Pascal:

 

what's the point in having default theme show order-info in  shopping_cart (-> user_info_block)

and then having block_cart as a different module just for ajax animations?

 

wouldn't it be better to just have block_cart display all order info?

with a little css work this could be achieved easily;

I haven't done it yet, but I think I'll do it....

 

From your experience,

is there any countereffects on deleting shopping_cart and just using the blockcart??

Link to comment
Share on other sites

 

 <p id="cart-prices">

 

{if $shipping_free_price > 0}

  <p id="amount_fee_shipping">

  <span class = "ajax_shipping_free_price_span {if ($amount_until_free_shipping) <= 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) > 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"}

 </p>

{/if}

 <span id="cart_block_shipping_cost" class="price ajax_cart_shipping_cost">{$shipping_cost}</span>

 <span>{l s='Shipping' mod='blockcart'}</span>

 <br/>

 {if $show_wrapping}

 ...

 

I have added a little modification for those who doesnt always have free shipping amount set.

 

If free shipping starts at is set to 0  the line will still show up in the blockcart. To solve this add the lines in blue addionally.

 

 

regards

Weckie

Link to comment
Share on other sites

  • 2 weeks later...

Pascal I got it, it has to do with .js file:

 

with

.removeClass('hidden')

and

.addClass('hidden')

 

 

the output looks like:

<span class="ajax_shipping_free_price_span hidden">

.....

 

and while  firefox and chrome interpret it correctly

explorer gets stuck (not so strange ...)

Link to comment
Share on other sites

my workaround is

 

in the tpl use

{if ($amount _until_free_ship) le 0} style="display:none;" {/if}

instead of

{if ($amount_until_free_shipping) <= 0} hidden{/if}

 

while in the .js I found no workaround....

 

with this solution I managed the explorer browser non to "break"

it's not pefrect but at least the page can be visualized

 

with mozilla and chrome it's OK

Link to comment
Share on other sites

  • 3 weeks later...

Free shipping in the cart displays.

But what added to the file shopping-cart.tpl that the remaining amount of free shipping to appear here?

I try added this code:

<tr class="cart_free_shipping">
<td colspan="5">{l s='Remaining amount to be added to your cart in order to obtain free shipping:'}</td>
<td colspan="2" class="price" id="free_shipping">{displayPrice price=$free_ship}</td>
</tr>

but instead amounts to free shipping is here 0.

When you change the number of products line disappears :wacko:

please advise me

Edited by sparhawk (see edit history)
Link to comment
Share on other sites

Free shipping in the cart displays.

But what added to the file shopping-cart.tpl that the remaining amount of free shipping to appear here?

I try added this code:

<tr class="cart_free_shipping">
<td colspan="5">{l s='Remaining amount to be added to your cart in order to obtain free shipping:'}</td>
<td colspan="2" class="price" id="free_shipping">{displayPrice price=$free_ship}</td>
</tr>

but instead amounts to free shipping is here 0.

When you change the number of products line disappears :wacko:

 

please advise me

This would've also needed.

No one knows ?

Edited by johny77 (see edit history)
Link to comment
Share on other sites

Hi Pascal,

I modified files according to your post #7.

The shopping cart shows me free shipping. But after clicking the checkout and the redirection to the shopping-cart summary

still displays in free shipping 0.00 €.

I added to the file themes>default>shopping-cart.tpl code:

<tr class="cart_free_shipping">
<td colspan="5">{l s='Remaining amount to be added to your cart in order to obtain free shipping:'}</td>
<td colspan="2" class="price" id="free_shipping">{displayPrice price=$free_ship}</td>
</tr>

just do not know if this code is correct - displayPrice price=$free_ship ?

Could you advise me please ?

 

Link to comment
Share on other sites

Hi SparHawk,

 

I wonder where you got the variable $free_ship from? As far as I know this is variable is not set anywhere, so will be shown as 0 (which in turn will be shown as 'free shipping')

 

in my code I used this in the tpl file:

Edit the file themes/<your theme folder/modules/blockcart/blockcart.tpl. (Again, make backup!)


almost at the end of the file, add the red code:


 <p id="cart-prices">
  <p id="amount_fee_shipping">
  <span class = "ajax_shipping_free_price_span {if ($amount_until_free_shipping) <= 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) > 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"}
 </p>

 <span id="cart_block_shipping_cost" class="price ajax_cart_shipping_cost">{$shipping_cost}</span>
 <span>{l s='Shipping' mod='blockcart'}</span>
 <br/>
 {if $show_wrapping}
 ...

So I use:

{$amount_until_free_shipping} for the amount needed to get free shipping.

{$shipping_free_price} for the price you set to get free shipping.

{$shipping_cost}the shipping cost.

 

Try one more time to implement my code fully, and see if that makes it work.

 

pascal.

Link to comment
Share on other sites

Hi Pascal,

 

thank you for your answer.

In the shopping cart is displayed free shipping.

I have modified code correctly in themes/<your theme folder/modules/blockcart/blockcart.tpl.

 

just do not know how to get the remaining amount for free shipping to the file:

themes/<your theme folder/shopping-cart.tpl

I attach a screenshot

Edited by sparhawk (see edit history)
Link to comment
Share on other sites

Hi Sparhawk,

Ah, I see, you want to show it in the summary as well.

Can you copy the contents of your :

/themes/<your theme folder>/modules/blockcart/shopping-cart.tpl    (I assume you meant the shopping-cart.tpl directly in the <your theme folder>, right? )

(please use the <> icon in the menu to format the code neatly.)

 

thx,

pascal

Link to comment
Share on other sites

Hi Pascal,

 

thank you for your answer.

Yes I meant this file themes/<your theme folder>/shopping-cart.tpl

 

To a file shopping-cart.tpl i tried to add this code (I took the code from prestashop 1.4 - file shopping-cart.tpl)

                {if $use_taxes}
                <td colspan="2" class="price total_price_container" id="total_price_container">
                    <p>{l s='Total'}</p>
                    <span id="total_price">{displayPrice price=$total_price}</span>
                </td>
                {else}
                <td colspan="2" class="price total_price_container" id="total_price_container">
                    <p>{l s='Total'}</p>
                    <span id="total_price">{displayPrice price=$total_price_without_tax}</span>
                </td>
                {/if}
            </tr>
            <tr class="cart_free_shipping">
                 <td colspan="5" style="white-space: normal;">{l s='Remaining amount to be added to your cart in order to obtain free shipping:'}</td>
                 <td colspan="2" id="free_shipping" class="price">{displayPrice price=$free_ship}</td>
            </tr>
        </tfoot>
        <tbody>

this code i added to the file shopping-cart.tpl

<tr class="cart_free_shipping">
<td colspan="5" style="white-space: normal;">{l s='Remaining amount to be added to your cart in order to obtain free shipping:'}</td>
<td colspan="2" id="free_shipping" class="price">{displayPrice price=$free_ship}</td>
</tr>
But this code in Prestashop version 1.5 does not work
 
thx
Petr
Edited by sparhawk (see edit history)
Link to comment
Share on other sites

Petr,

 

please attach the full file shopping-cart.tpl, so I can see where to add some code precisely.

 

(As said before,  the $free_ship is unknown, so that doesn't work...

If you want to try yourself one more time, replace $free_ship with {$amount_until_free_shipping} )

 

pascal

Link to comment
Share on other sites

Pascal, thank you for your response.

I attach the full code shopping-cart.tpl. I tried to change $free_ship with $amount_until_free_shipping but it did not work.

Now does not display zero in the remaining amount for free shipping.

Can you please advise me.

many thanks

Petr

{*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <[email protected]>
*  @copyright  2007-2013 PrestaShop SA
*  @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*}

{capture name=path}{l s='Your shopping cart'}{/capture}
{include file="$tpl_dir./breadcrumb.tpl"}

<h1 id="cart_title">{l s='Shopping-cart summary'}</h1>

{if isset($account_created)}
	<p class="success">
		{l s='Your account has been created.'}
	</p>
{/if}
{assign var='current_step' value='summary'}
{include file="$tpl_dir./order-steps.tpl"}
{include file="$tpl_dir./errors.tpl"}

{if isset($empty)}
	<p class="warning">{l s='Your shopping cart is empty.'}</p>
{elseif $PS_CATALOG_MODE}
	<p class="warning">{l s='This store has not accepted your new order.'}</p>
{else}
	<script type="text/javascript">
	// <![CDATA[
	var currencySign = '{$currencySign|html_entity_decode:2:"UTF-8"}';
	var currencyRate = '{$currencyRate|floatval}';
	var currencyFormat = '{$currencyFormat|intval}';
	var currencyBlank = '{$currencyBlank|intval}';
	var txtProduct = "{l s='product' js=1}";
	var txtProducts = "{l s='products' js=1}";
	var deliveryAddress = {$cart->id_address_delivery|intval};
	// ]]>
	</script>
	<p style="display:none" id="emptyCartWarning" class="warning">{l s='Your shopping cart is empty.'}</p>
{if isset($lastProductAdded) AND $lastProductAdded}
	<div class="cart_last_product">
		<div class="cart_last_product_header">
			<div class="left">{l s='Last product added'}</div>
		</div>
		<a  class="cart_last_product_img" href="{$link->getProductLink($lastProductAdded.id_product, $lastProductAdded.link_rewrite, $lastProductAdded.category, null, null, $lastProductAdded.id_shop)|escape:'htmlall':'UTF-8'}"><img src="{$link->getImageLink($lastProductAdded.link_rewrite, $lastProductAdded.id_image, 'small_default')|escape:'html'}" alt="{$lastProductAdded.name|escape:'htmlall':'UTF-8'}"/></a>
		<div class="cart_last_product_content">
			<p class="s_title_block"><a href="{$link->getProductLink($lastProductAdded.id_product, $lastProductAdded.link_rewrite, $lastProductAdded.category, null, null, null, $lastProductAdded.id_product_attribute)|escape:'htmlall':'UTF-8'}">{$lastProductAdded.name|escape:'htmlall':'UTF-8'}</a></p>
			{if isset($lastProductAdded.attributes) && $lastProductAdded.attributes}<a href="{$link->getProductLink($lastProductAdded.id_product, $lastProductAdded.link_rewrite, $lastProductAdded.category, null, null, null, $lastProductAdded.id_product_attribute)|escape:'htmlall':'UTF-8'}">{$lastProductAdded.attributes|escape:'htmlall':'UTF-8'}</a>{/if}
		</div>
		<br class="clear" />
	</div>
{/if}
<p>{l s='Your shopping cart contains:'} <span id="summary_products_quantity">{$productNumber} {if $productNumber == 1}{l s='product'}{else}{l s='products'}{/if}</span></p>
<div id="order-detail-content" class="table_block">
	<table id="cart_summary" class="std">
		<thead>
			<tr>
				<th class="cart_product first_item">{l s='Product'}</th>
				<th class="cart_description item">{l s='Description'}</th>
				<th class="cart_ref item">{l s='Ref.'}</th>
				<th class="cart_unit item">{l s='Unit price'}</th>
				<th class="cart_quantity item">{l s='Qty'}</th>
				<th class="cart_total item">{l s='Total'}</th>
				<th class="cart_delete last_item"> </th>
			</tr>
		</thead>
		<tfoot>
		{if $use_taxes}
			{if $priceDisplay}
				<tr class="cart_total_price">
					<td colspan="5">{if $display_tax_label}{l s='Total products (tax excl.)'}{else}{l s='Total products'}{/if}</td>
					<td colspan="2" class="price" id="total_product">{displayPrice price=$total_products}</td>
				</tr>
			{else}
				<tr class="cart_total_price">
					<td colspan="5">{if $display_tax_label}{l s='Total products (tax incl.)'}{else}{l s='Total products'}{/if}</td>
					<td colspan="2" class="price" id="total_product">{displayPrice price=$total_products_wt}</td>
				</tr>
			{/if}
		{else}
			<tr class="cart_total_price">
				<td colspan="5">{l s='Total products'}</td>
				<td colspan="2" class="price" id="total_product">{displayPrice price=$total_products}</td>
			</tr>
		{/if}
			<tr{if $total_wrapping == 0} style="display: none;"{/if}>
				<td colspan="5">
				{if $use_taxes}
					{if $display_tax_label}{l s='Total gift wrapping (tax incl.):'}{else}{l s='Total gift-wrapping cost:'}{/if}
				{else}
					{l s='Total gift-wrapping cost:'}
				{/if}
				</td>
				<td colspan="2" class="price-discount price" id="total_wrapping">
				{if $use_taxes}
					{if $priceDisplay}
						{displayPrice price=$total_wrapping_tax_exc}
					{else}
						{displayPrice price=$total_wrapping}
					{/if}
				{else}
					{displayPrice price=$total_wrapping_tax_exc}
				{/if}
				</td>
			</tr>
			{if $total_shipping_tax_exc <= 0 && !isset($virtualCart)}
				<tr class="cart_total_delivery" style="{if !isset($carrier->id) || is_null($carrier->id)}display:none;{/if}">
					<td colspan="5">{l s='Shipping'}</td>
					<td colspan="2" class="price" id="total_shipping">{l s='Free Shipping!'}</td>
				</tr>
			{else}
				{if $use_taxes && $total_shipping_tax_exc != $total_shipping}
					{if $priceDisplay}
						<tr class="cart_total_delivery" {if $total_shipping_tax_exc <= 0} style="display:none;"{/if}>
							<td colspan="5">{if $display_tax_label}{l s='Total shipping (tax excl.)'}{else}{l s='Total shipping'}{/if}</td>
							<td colspan="2" class="price" id="total_shipping">{displayPrice price=$total_shipping_tax_exc}</td>
						</tr>
					{else}
						<tr class="cart_total_delivery"{if $total_shipping <= 0} style="display:none;"{/if}>
							<td colspan="5">{if $display_tax_label}{l s='Total shipping (tax incl.)'}{else}{l s='Total shipping'}{/if}</td>
							<td colspan="2" class="price" id="total_shipping" >{displayPrice price=$total_shipping}</td>
						</tr>
					{/if}
				{else}
					<tr class="cart_total_delivery"{if $total_shipping_tax_exc <= 0} style="display:none;"{/if}>
						<td colspan="5">{l s='Total shipping'}</td>
						<td colspan="2" class="price" id="total_shipping" >{displayPrice price=$total_shipping_tax_exc}</td>
					</tr>
				{/if}
			{/if}
			<tr class="cart_total_voucher" {if $total_discounts == 0}style="display:none"{/if}>
				<td colspan="5">
				{if $display_tax_label}
					{if $use_taxes && $priceDisplay == 0}
						{l s='Total vouchers (tax incl.):'}
					{else}
						{l s='Total vouchers (tax excl.)'}
					{/if}
				{else}
					{l s='Total vouchers'}
				{/if}
				</td>
				<td colspan="2" class="price-discount price" id="total_discount">
				{if $use_taxes && $priceDisplay == 0}
					{assign var='total_discounts_negative' value=$total_discounts * -1}
				{else}
					{assign var='total_discounts_negative' value=$total_discounts_tax_exc * -1}
				{/if}
				{displayPrice price=$total_discounts_negative}
				</td>
			</tr>
			{if $use_taxes && $show_taxes}
			<tr class="cart_total_price">
				<td colspan="5">{l s='Total (tax excl.)'}</td>
				<td colspan="2" class="price" id="total_price_without_tax">{displayPrice price=$total_price_without_tax}</td>
			</tr>
			<tr class="cart_total_tax">
				<td colspan="5">{l s='Total tax'}</td>
				<td colspan="2" class="price" id="total_tax">{displayPrice price=$total_tax}</td>
			</tr>
			{/if}
			<tr class="cart_total_price">
				<td colspan="5" id="cart_voucher" class="cart_voucher">
				{if $voucherAllowed}
					{if isset($errors_discount) && $errors_discount}
						<ul class="error">
						{foreach $errors_discount as $k=>$error}
							<li>{$error|escape:'htmlall':'UTF-8'}</li>
						{/foreach}
						</ul>
					{/if}
					<form action="{if $opc}{$link->getPageLink('order-opc', true)}{else}{$link->getPageLink('order', true)}{/if}" method="post" id="voucher">
						<fieldset>
							<p class="title_block"><label for="discount_name">{l s='Vouchers'}</label></p>
							<p class="discount_name_block">
								<input type="text" class="discount_name" id="discount_name" name="discount_name" value="{if isset($discount_name) && $discount_name}{$discount_name}{/if}" />
							</p>
							<p class="submit"><input type="hidden" name="submitDiscount" /><input type="submit" name="submitAddDiscount" value="{l s='OK'}" class="button" /></p>
						</fieldset>
					</form>
					{if $displayVouchers}
						<p id="title" class="title_offers">{l s='Take advantage of our exclusive offers:'}</p>
						<div id="display_cart_vouchers">
						{foreach $displayVouchers as $voucher}
							{if $voucher.code != ''}<span onclick="$('#discount_name').val('{$voucher.code}');return false;" class="voucher_name">{$voucher.code}</span> - {/if}{$voucher.name}<br />
						{/foreach}
						</div>
					{/if}
				{/if}
				</td>
				{if $use_taxes}
				<td colspan="2" class="price total_price_container" id="total_price_container">
					<p>{l s='Total'}</p>
					<span id="total_price">{displayPrice price=$total_price}</span>
				</td>
				{else}
				<td colspan="2" class="price total_price_container" id="total_price_container">
					<p>{l s='Total'}</p>
					<span id="total_price">{displayPrice price=$total_price_without_tax}</span>
				</td>
				{/if}
			</tr>
			<tr class="cart_free_shipping">
	 			<td colspan="5" style="white-space: normal;">{l s='Remaining amount to be added to your cart in order to obtain free shipping:'}</td>
	 			<td colspan="2" id="free_shipping" class="price">{displayPrice price=$amount_until_free_shipping}</td>
			</tr>
		</tfoot>
		<tbody>
		{assign var='odd' value=0}
		{foreach $products as $product}
			{assign var='productId' value=$product.id_product}
			{assign var='productAttributeId' value=$product.id_product_attribute}
			{assign var='quantityDisplayed' value=0}
			{assign var='odd' value=($odd+1)%2}
			{assign var='ignoreProductLast' value=isset($customizedDatas.$productId.$productAttributeId) || count($gift_products)}
			{* Display the product line *}
			{include file="$tpl_dir./shopping-cart-product-line.tpl" productLast=$product@last productFirst=$product@first}
			{* Then the customized datas ones*}
			{if isset($customizedDatas.$productId.$productAttributeId)}
				{foreach $customizedDatas.$productId.$productAttributeId[$product.id_address_delivery] as $id_customization=>$customization}
					<tr id="product_{$product.id_product}_{$product.id_product_attribute}_{$id_customization}_{$product.id_address_delivery|intval}" class="product_customization_for_{$product.id_product}_{$product.id_product_attribute}_{$product.id_address_delivery|intval}{if $odd} odd{else} even{/if} customization alternate_item {if $product@last && $customization@last && !count($gift_products)}last_item{/if}">
						<td></td>
						<td colspan="3">
							{foreach $customization.datas as $type => $custom_data}
								{if $type == $CUSTOMIZE_FILE}
									<div class="customizationUploaded">
										<ul class="customizationUploaded">
											{foreach $custom_data as $picture}
												<li><img src="{$pic_dir}{$picture.value}_small" alt="" class="customizationUploaded" /></li>
											{/foreach}
										</ul>
									</div>
								{elseif $type == $CUSTOMIZE_TEXTFIELD}
									<ul class="typedText">
										{foreach $custom_data as $textField}
											<li>
												{if $textField.name}
													{$textField.name}
												{else}
													{l s='Text #'}{$textField@index+1}
												{/if}
												{l s=':'} {$textField.value}
											</li>
										{/foreach}
										
									</ul>
								{/if}

							{/foreach}
						</td>
						<td class="cart_quantity" colspan="2">
							{if isset($cannotModify) AND $cannotModify == 1}
								<span style="float:left">{if $quantityDisplayed == 0 AND isset($customizedDatas.$productId.$productAttributeId)}{$customizedDatas.$productId.$productAttributeId|@count}{else}{$product.cart_quantity-$quantityDisplayed}{/if}</span>
							{else}
								<div class="cart_quantity_button">
								<a rel="nofollow" class="cart_quantity_up" id="cart_quantity_up_{$product.id_product}_{$product.id_product_attribute}_{$id_customization}_{$product.id_address_delivery|intval}" href="{$link->getPageLink('cart', true, NULL, "add=1&id_product={$product.id_product|intval}&ipa={$product.id_product_attribute|intval}&id_address_delivery={$product.id_address_delivery}&id_customization={$id_customization}&token={$token_cart}")|escape:'html'}" title="{l s='Add'}"><img src="{$img_dir}icon/quantity_up.gif" alt="{l s='Add'}" width="14" height="9" /></a><br />
								{if $product.minimal_quantity < ($customization.quantity -$quantityDisplayed) OR $product.minimal_quantity <= 1}
								<a rel="nofollow" class="cart_quantity_down" id="cart_quantity_down_{$product.id_product}_{$product.id_product_attribute}_{$id_customization}_{$product.id_address_delivery|intval}" href="{$link->getPageLink('cart', true, NULL, "add=1&id_product={$product.id_product|intval}&ipa={$product.id_product_attribute|intval}&id_address_delivery={$product.id_address_delivery}&id_customization={$id_customization}&op=down&token={$token_cart}")|escape:'html'}" title="{l s='Subtract'}">
									<img src="{$img_dir}icon/quantity_down.gif" alt="{l s='Subtract'}" width="14" height="9" />
								</a>
								{else}
								<a class="cart_quantity_down" style="opacity: 0.3;" id="cart_quantity_down_{$product.id_product}_{$product.id_product_attribute}_{$id_customization}" href="#" title="{l s='Subtract'}">
									<img src="{$img_dir}icon/quantity_down.gif" alt="{l s='Subtract'}" width="14" height="9" />
								</a>
								{/if}
								</div>
								<input type="hidden" value="{$customization.quantity}" name="quantity_{$product.id_product}_{$product.id_product_attribute}_{$id_customization}_{$product.id_address_delivery|intval}_hidden"/>
								<input size="2" type="text" value="{$customization.quantity}" class="cart_quantity_input" name="quantity_{$product.id_product}_{$product.id_product_attribute}_{$id_customization}_{$product.id_address_delivery|intval}"/>
							{/if}
						</td>
						<td class="cart_delete">
							{if isset($cannotModify) AND $cannotModify == 1}
							{else}
								<div>
									<a rel="nofollow" class="cart_quantity_delete" id="{$product.id_product}_{$product.id_product_attribute}_{$id_customization}_{$product.id_address_delivery|intval}" href="{$link->getPageLink('cart', true, NULL, "delete=1&id_product={$product.id_product|intval}&ipa={$product.id_product_attribute|intval}&id_customization={$id_customization}&id_address_delivery={$product.id_address_delivery}&token={$token_cart}")|escape:'html'}">{l s='Delete'}</a>
								</div>
							{/if}
						</td>
					</tr>
					{assign var='quantityDisplayed' value=$quantityDisplayed+$customization.quantity}
				{/foreach}
				{* If it exists also some uncustomized products *}
				{if $product.quantity-$quantityDisplayed > 0}{include file="$tpl_dir./shopping-cart-product-line.tpl" productLast=$product@last productFirst=$product@first}{/if}
			{/if}
		{/foreach}
		{assign var='last_was_odd' value=$product@iteration%2}
		{foreach $gift_products as $product}
			{assign var='productId' value=$product.id_product}
			{assign var='productAttributeId' value=$product.id_product_attribute}
			{assign var='quantityDisplayed' value=0}
			{assign var='odd' value=($product@iteration+$last_was_odd)%2}
			{assign var='ignoreProductLast' value=isset($customizedDatas.$productId.$productAttributeId)}
			{assign var='cannotModify' value=1}
			{* Display the gift product line *}
			{include file="$tpl_dir./shopping-cart-product-line.tpl" productLast=$product@last productFirst=$product@first}
		{/foreach}
		</tbody>
	{if sizeof($discounts)}
		<tbody>
		{foreach $discounts as $discount}
			<tr class="cart_discount {if $discount@last}last_item{elseif $discount@first}first_item{else}item{/if}" id="cart_discount_{$discount.id_discount}">
				<td class="cart_discount_name" colspan="3">{$discount.name}</td>
				<td class="cart_discount_price"><span class="price-discount">
					{if !$priceDisplay}{displayPrice price=$discount.value_real*-1}{else}{displayPrice price=$discount.value_tax_exc*-1}{/if}
				</span></td>
				<td class="cart_discount_delete">1</td>
				<td class="cart_discount_price">
					<span class="price-discount price">{if !$priceDisplay}{displayPrice price=$discount.value_real*-1}{else}{displayPrice price=$discount.value_tax_exc*-1}{/if}</span>
				</td>
				<td class="price_discount_del">
					{if strlen($discount.code)}<a href="{if $opc}{$link->getPageLink('order-opc', true)}{else}{$link->getPageLink('order', true)}{/if}?deleteDiscount={$discount.id_discount}" class="price_discount_delete" title="{l s='Delete'}">{l s='Delete'}</a>{/if}
				</td>
			</tr>
		{/foreach}
		</tbody>
	{/if}
	</table>
</div>

{if $show_option_allow_separate_package}
<p>
	<input type="checkbox" name="allow_seperated_package" id="allow_seperated_package" {if $cart->allow_seperated_package}checked="checked"{/if} autocomplete="off"/>
	<label for="allow_seperated_package">{l s='Send available products first'}</label>
</p>
{/if}
{if !$opc}
	{if Configuration::get('PS_ALLOW_MULTISHIPPING')}
		<p>
			<input type="checkbox" {if $multi_shipping}checked="checked"{/if} id="enable-multishipping" />
			<label for="enable-multishipping">{l s='I would like to specify a delivery address for each individual product.'}</label>
		</p>
	{/if}
{/if}

<div id="HOOK_SHOPPING_CART">{$HOOK_SHOPPING_CART}</div>

{* Define the style if it doesn't exist in the PrestaShop version*}
{* Will be deleted for 1.5 version and more *}
{if !isset($addresses_style)}
	{$addresses_style.company = 'address_company'}
	{$addresses_style.vat_number = 'address_company'}
	{$addresses_style.firstname = 'address_name'}
	{$addresses_style.lastname = 'address_name'}
	{$addresses_style.address1 = 'address_address1'}
	{$addresses_style.address2 = 'address_address2'}
	{$addresses_style.city = 'address_city'}
	{$addresses_style.country = 'address_country'}
	{$addresses_style.phone = 'address_phone'}
	{$addresses_style.phone_mobile = 'address_phone_mobile'}
	{$addresses_style.alias = 'address_title'}
{/if}

{if ((!empty($delivery_option) AND !isset($virtualCart)) OR $delivery->id OR $invoice->id) AND !$opc}
<div class="order_delivery clearfix">
	{if !isset($formattedAddresses) || (count($formattedAddresses.invoice) == 0 && count($formattedAddresses.delivery) == 0) || (count($formattedAddresses.invoice.formated) == 0 && count($formattedAddresses.delivery.formated) == 0)}
		{if $delivery->id}
		<ul id="delivery_address" class="address item">
			<li class="address_title">{l s='Delivery address'} <span class="address_alias">({$delivery->alias})</span></li>
			{if $delivery->company}<li class="address_company">{$delivery->company|escape:'htmlall':'UTF-8'}</li>{/if}
			<li class="address_name">{$delivery->firstname|escape:'htmlall':'UTF-8'} {$delivery->lastname|escape:'htmlall':'UTF-8'}</li>
			<li class="address_address1">{$delivery->address1|escape:'htmlall':'UTF-8'}</li>
			{if $delivery->address2}<li class="address_address2">{$delivery->address2|escape:'htmlall':'UTF-8'}</li>{/if}
			<li class="address_city">{$delivery->postcode|escape:'htmlall':'UTF-8'} {$delivery->city|escape:'htmlall':'UTF-8'}</li>
			<li class="address_country">{$delivery->country|escape:'htmlall':'UTF-8'} {if $delivery_state}({$delivery_state|escape:'htmlall':'UTF-8'}){/if}</li>
		</ul>
		{/if}
		{if $invoice->id}
		<ul id="invoice_address" class="address alternate_item">
			<li class="address_title">{l s='Invoice address'} <span class="address_alias">({$invoice->alias})</span></li>
			{if $invoice->company}<li class="address_company">{$invoice->company|escape:'htmlall':'UTF-8'}</li>{/if}
			<li class="address_name">{$invoice->firstname|escape:'htmlall':'UTF-8'} {$invoice->lastname|escape:'htmlall':'UTF-8'}</li>
			<li class="address_address1">{$invoice->address1|escape:'htmlall':'UTF-8'}</li>
			{if $invoice->address2}<li class="address_address2">{$invoice->address2|escape:'htmlall':'UTF-8'}</li>{/if}
			<li class="address_city">{$invoice->postcode|escape:'htmlall':'UTF-8'} {$invoice->city|escape:'htmlall':'UTF-8'}</li>
			<li class="address_country">{$invoice->country|escape:'htmlall':'UTF-8'} {if $invoice_state}({$invoice_state|escape:'htmlall':'UTF-8'}){/if}</li>
		</ul>
		{/if}
	{else}
		{foreach from=$formattedAddresses key=k item=address}
			<ul class="address {if $address@last}last_item{elseif $address@first}first_item{/if} {if $address@index % 2}alternate_item{else}item{/if}">
				<li class="address_title">{if $k eq 'invoice'}{l s='Invoice address'}{elseif $k eq 'delivery' && $delivery->id}{l s='Delivery address'}{/if}{if isset($address.object.alias)} <span class="address_alias">({$address.object.alias})</span>{/if}</li>
				{foreach $address.ordered as $pattern}
					{assign var=addressKey value=" "|explode:$pattern}
					<li>
					{foreach $addressKey as $key}
						<span class="{if isset($addresses_style[$key])}{$addresses_style[$key]}{/if}">
							{if isset($address.formated[$key])}
								{$address.formated[$key]|escape:'htmlall':'UTF-8'}
							{/if}
						</span>
					{/foreach}
					</li>
				{/foreach}
				</ul>
		{/foreach}
		<br class="clear"/>
	{/if}
</div>
{/if}
<p class="cart_navigation">
	{if !$opc}
		<a href="{if $back}{$link->getPageLink('order', true, NULL, 'step=1&back={$back}')}{else}{$link->getPageLink('order', true, NULL, 'step=1')}{/if}" class="exclusive standard-checkout" title="{l s='Next'}">{l s='Next'} »</a>
		{if Configuration::get('PS_ALLOW_MULTISHIPPING')}
			<a href="{if $back}{$link->getPageLink('order', true, NULL, 'step=1&back={$back}')}{else}{$link->getPageLink('order', true, NULL, 'step=1')}{/if}&multi-shipping=1" class="multishipping-button multishipping-checkout exclusive" title="{l s='Next'}">{l s='Next'} »</a>
		{/if}
	{/if}
	<a href="{if (isset($smarty.server.HTTP_REFERER) && strstr($smarty.server.HTTP_REFERER, 'order.php')) || isset($smarty.server.HTTP_REFERER) && strstr($smarty.server.HTTP_REFERER, 'order-opc') || !isset($smarty.server.HTTP_REFERER)}{$link->getPageLink('index')}{else}{$smarty.server.HTTP_REFERER|escape:'htmlall':'UTF-8'|secureReferrer}{/if}" class="button_large" title="{l s='Continue shopping'}">« {l s='Continue shopping'}</a>
</p>
	{if !empty($HOOK_SHOPPING_CART_EXTRA)}
		<div class="clear"></div>
		<div class="cart_navigation_extra">
			<div id="HOOK_SHOPPING_CART_EXTRA">{$HOOK_SHOPPING_CART_EXTRA}</div>
		</div>
	{/if}
{/if}
Link to comment
Share on other sites

  • 2 weeks later...

Hmmm,

 

that means we have to go through the whole process of preparing the variables and define it, so that we can use it in the summary. That's not a little task. Comes with it that the summary has up and down buttons, delete buttons, so the amount should be updated on the fly, just like the blockcart... which means ajax file (and json?) needs modification. Actually somewhat similar to my post #7, but then for cart.php and some additional ajax carts, shopping-cart.tpl etc

 

When I have some free day, I might have a look at it, but I am afraid not anywhere soon...

 

Anyone feels the urge to pick it up??

 

pascal

Link to comment
Share on other sites

  • 2 weeks later...

Hi,

I tried this and it works really good, thank you all for your advices.

I only found one little problem that I'm not able to solve: when the variable $amount_until_free_shipping is greater than zero but less than one, the displayed message is "Buying more than..." instead of the other one.

 

Is there something i'm doing wrong? Thank you all.

Link to comment
Share on other sites

Hmm, code that decides which one is like this:

 

 

<p id="cart-prices">
  <p id="amount_fee_shipping">
  <span class = "ajax_shipping_free_price_span {if ($amount_until_free_shipping) <= 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>

 

 

I.e. When $amount_until_free_shipping <=0, hide the message, otherwise show: Spend xx for free shipping!

 

  <span class = "ajax_shipping_free_price_free_span {if ($amount_until_free_shipping) > 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"}
 </p>

I.e. When $amount_until_free_shipping >0, hide the message, otherwise show: Buying more than xx earned you free shipping!!!

 
Not sure where this can go wrong...
 
Do you have an URL to your site?
 
pascal
Link to comment
Share on other sites

  • 1 month later...

As you said in that post, I also had the automatically update problem, in the backoffice I disabled the javascript files cache and set it to use the original source files (In preferences -> performance) and that solved the problem. Then I simply waited a few days and enabled the cache again and currently it works perfect.

Link to comment
Share on other sites

As you said in that post, I also had the automatically update problem, in the backoffice I disabled the javascript files cache and set it to use the original source files (In preferences -> performance) and that solved the problem. Then I simply waited a few days and enabled the cache again and currently it works perfect.

 

I just added the code that was missing to themes/<your theme>/js/cart-summary.js and updated my post. Check it out! ;)

Link to comment
Share on other sites

Hi.

 

This is a bit off-topic, but can you help me on this?: I need the javascript of the blockcart module to recognize when the cart only has virtual products (virtual cart).

 

The blockcart.tlp does this well by using {if $virtual_cart}, but it does not work in ajax-cart.js.

 

Help please!...

 

 

Anyone???

Link to comment
Share on other sites

Thank you for the code it works.

Can one change also the color when we arrive at offered cool of delivery?

I have another problem, I have to confirm the page to see my products bought in the basket

How to remedy it? .Merci of your answer.

Link to comment
Share on other sites

ILoveKutch,

 

did you find a way to check if the car was virtual or not in javascript already?

 

There is a function:

public function isVirtualCart($strict = false)
 
in classes/Cart.php

 

Which you can call either this way:

  !$this->context->cart->isVirtualCart()

 

or if you know the cart:

  $cart->isVirtualCart()

 

or so. 

 

Maybe that helps,

pascal.

Link to comment
Share on other sites

ILoveKutch,

 

did you find a way to check if the car was virtual or not in javascript already?

 

There is a function:

public function isVirtualCart($strict = false)
 
in classes/Cart.php

 

Which you can call either this way:

  !$this->context->cart->isVirtualCart()

 

or if you know the cart:

  $cart->isVirtualCart()

 

or so. 

 

Maybe that helps,

pascal.

 

Many thanks PascalIVG!

Link to comment
Share on other sites

  • 3 weeks later...

ILoveKutch,

 

did you find a way to check if the car was virtual or not in javascript already?

 

There is a function:

public function isVirtualCart($strict = false)
 
in classes/Cart.php

 

Which you can call either this way:

  !$this->context->cart->isVirtualCart()

 

or if you know the cart:

  $cart->isVirtualCart()

 

or so. 

 

Maybe that helps,

pascal.

 

Hi Pascal.

 

I'm afraid the code you gave is to be used in .tlp files.

 

I need a code for .js (ajax-cart.js), so it detects and updates when a cart is virtual.

 

For example, cart-summary.js uses "if (json.is_virtual_cart)", but this code does not work in ajax-cart.js

 

Thanks!

Link to comment
Share on other sites

Let me think.

a product has an attribute is_virtual

 

So we probably need to add this one to the json product in blockcart-json.tpl: (Backup file first!!!)

{ldelim}
"products": [
{if $products}
{foreach from=$products item=product name='products'}
{assign var='productId' value=$product.id_product}
{assign var='productAttributeId' value=$product.id_product_attribute}
{assign var="product_link" value=$link->getProductLink($product.id_product, $product.link_rewrite, $product.category, null, null, $product.id_shop, $product.id_product_attribute)|escape:'htmlall':'UTF-8'}
{if $product_link|strpos:'?' === false}
	{assign var="awp_product_link" value="?"}
{else}
	{assign var="awp_product_link" value="&"}
{/if}
{assign var="awp_product_link" value=$awp_product_link|cat:'ipa='|cat:$productAttributeId|cat:'&ins='|cat:$product.instructions_valid}
{if $product_link|strpos:'#' > 0}
	{assign var='amp_pos' value=$product_link|strpos:'#'}
	{assign var='product_link' value=$product_link|substr:0:$amp_pos}
{/if}
{assign var='product_link' value=$product_link|cat:$awp_product_link}
	{ldelim}
		"id":            {$product.id_product},
		"id_image":       "{$link->getImageLink($product.link_rewrite, $product.id_image, $img_name.medium)}",
		"link":          "{$product_link|addslashes|replace:'\\\'':'\''}",
		"quantity":      {$product.cart_quantity},
		"priceByLine":   "{if $priceDisplay == $smarty.const.PS_TAX_EXC}{displayWtPrice|html_entity_decode:2:'UTF-8' p=$product.total}{else}{displayWtPrice|html_entity_decode:2:'UTF-8' p=$product.total_wt}{/if}",
		"name":          "{$product.name|html_entity_decode:2:'UTF-8'|escape:'htmlall'|truncate:15:'...':true}",
		"price":         "{if $priceDisplay == $smarty.const.PS_TAX_EXC}{displayWtPrice|html_entity_decode:2:'UTF-8' p=$product.total}{else}{displayWtPrice|html_entity_decode:2:'UTF-8' p=$product.total_wt}{/if}",
		"price_float":   "{$product.total}",
		"idCombination": {if isset($product.attributes_small)}{$productAttributeId}{else}0{/if},
		"idAddressDelivery": {if isset($product.id_address_delivery)}{$product.id_address_delivery}{else}0{/if},

so insert on a line just below de "price_float": ... line:

"is_virtual": "$product.is_virtual",

 

This should give the is_virtual value in the ajax-cart; but we need to scan through all products of the cart to see if the cart has any virtual product:

 

so add just above the following code:   (Backup ajax-cart.js first!!!)

	displayNewCustomizedDatas : function(product)
	{
		var content = '';
		var productId = parseInt(product.id);
		var productAttributeId = typeof(product.idCombination) == 'undefined' ? 0 : parseInt(product.idCombination);
		var hasAlreadyCustomizations = $('#customization_' + productId + '_' + productAttributeId).length;

		if (!hasAlreadyCustomizations)
		{
			if (!product.hasAttributes)
				content += '<dd id="cart_block_combination_of_' + productId + '" class="hidden">';
			if ($('#customization_' + productId + '_' + productAttributeId).val() == undefined)
				content += '<ul class="cart_block_customizations" id="customization_' + productId + '_' + productAttributeId + '">';
		}

a block something like this: (Didn't check the code, really hope it works....)

	isVirtualCart : function(jsonData) {
		//walk through all products of the cart
		var is_virtual = true;

		$(jsonData.products).each(function(){
			//fix ie6 bug (one more item 'undefined' in IE6)
			if (this.id != undefined)
			{
				if (!this.is_virtual)
					is_virtual = false;
					return false;
			}
		});
		return (is_virtual);
	},

Then you should have the function isVirtualCart() available...

 

 

Make backups first, as I didn't check the code. Hope it helps, fingers crossed!

 

pascal.

Link to comment
Share on other sites

  • 1 month later...

I have little problem.

 

In shopping-cart.tpl i have this error

Notice: Undefined index: shipping_free_price in /var/www/vhosts/pikante.cz/httpdocs/cache/smarty/compile/ce/12/01/ce1201ff99c0a695bf1609d41b181aba0097c8aa.file.shopping-cart.tpl.php on line 597 Notice: Trying to get property of non-object in /var/www/vhosts/pikante.cz/httpdocs/cache/smarty/compile/ce/12/01/ce1201ff99c0a695bf1609d41b181aba0097c8aa.file.shopping-cart.tpl.php on line 597

In shopping-cart.tpl i have this code

<p id="amount_fee_shipping">
  <span class = "ajax_shipping_free_price_span {if ($amount_until_free_shipping) <= 0} hidden{/if}">{l s="Do dopravy zdarma zbývá:" mod="blockcart"}<span class="ajax_shipping_free_price">{$amount_until_free_shipping}</span><span class="kc">kč</span></span>


  <span class = "ajax_shipping_free_price_free_spans {if ($amount_until_free_shipping) > 0} hidden {/if}"> <span class="ajax_shipping_free_price_free">{$shipping_free_price}</span> {l s="DOPRAVA ZADARMO!" mod="blockcart"}
 </p>

 

Any idea?

Edited by tozi (see edit history)
Link to comment
Share on other sites

  • 3 weeks later...

OK, 'summarizing' some code above and adding the real time update in the shopping cart using ajax, we can do as follows:

 

(Code taken from PrestaShop 1.5.5.0.)

 

We'll go throughout the whole cycle. From getting the (fixed) value to get free shipping to showing and real-time updating the value when adding/deleting products to/from the shopping cart.

 

Preparation:

Check if you have the following files in place:

/modules/blockcart/blockcart.php  (if not, install the block cart module)

/themes/<your theme folder>/modules/blockcart/blockcart.tpl   (if not, copy from /modules/blockcart/)

/themes/<your theme folder>/modules/blockcart/blockcart-json.tpl   (if not, copy from /modules/blockcart/)

/themes/<your theme folder>/js/modules/blockcart/ajax-cart.js   (if not, copy from /modules/blockcart/)

 

 

The "free shipping starts at"-value we talk about can be changed in Shipping->Shipping. "Free shipping starts at":

 

 

Edit file modules/blockcart/blockcart.php: (Always make backup of original files, just in case…)

 

in function:   public function assignContentVars($params) 

 

add this:

          ...

          $shipping_cost = Tools::displayPrice($base_shipping, $currency);

          $shipping_cost_float = Tools::convertPrice($base_shipping, $currency);

          $wrappingCost = (float)($params['cart']->getOrderTotal($useTax, Cart::ONLY_WRAPPING));

          $totalToPay = $params['cart']->getOrderTotal($useTax);

          $shipping_free_price= Tools::convertPrice((float)(Configuration::get('PS_SHIPPING_FREE_PRICE')), $currency);

 

          if ($useTax && Configuration::get('PS_TAX_DISPLAY') == 1)

              …

 

 

What it does: 

We get the value out of the ps_configuration table and convert it whenever needed to another currency.

 

 

 

Then scroll a little down, until you see a block of code assigning values to smarty variables

 

          $this->smarty->assign(array(

               ... 

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

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

               'shipping_free_price' => $shipping_free_price,

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

               '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)

               ...

 

What it does:

Here we calculate the actual difference of how much the customer needs to spend to get free shipping, and make the value available to the cart. Also the free shipping amount we will make available, to inform him/her how much he/she needs to spend at least to KEEP the free shipping, when there's put enough in the cart already.

 

Save the file

 

 

Edit file themes/<your theme folder>/modules/blockcart/blockcart-json.tpl: (Backup the original file...)

 

Almost at the end of the file, add the two red lines:

"wrappingCost": "{$wrapping_cost|html_entity_decode:2:'UTF-8'}",
"productTotal": "{$product_total|html_entity_decode:2:'UTF-8'}",
"nbTotalProducts": "{$nb_total_products}",
"total": "{$total|html_entity_decode:2:'UTF-8'}",

"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'}",

 

What it does:

We add the variable $product_total (sum of all products, including discounts, but excluding shipping) to compare the free shipping-amount to and we make our $shipping_free_price available in our ajax cart

 

Save the file.

 

 

 

Edit the file themes/<your theme folder/modules/blockcart/blockcart.tpl. (Again, make backup!)

 

 

almost at the end of the file, add the red code:

 

 

 <p id="cart-prices">

  <p id="amount_fee_shipping">

  <span class = "ajax_shipping_free_price_span {if ($amount_until_free_shipping) <= 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) > 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"}

 </p>

 

 <span id="cart_block_shipping_cost" class="price ajax_cart_shipping_cost">{$shipping_cost}</span>

 <span>{l s='Shipping' mod='blockcart'}</span>

 <br/>

 {if $show_wrapping}

 ...

 

What it does:

Here we put the values in the page. You can choose where to put it, but I put it just above the shipping price line, to keep it nicely together.

 

We put it in a div, to make css activity possible on the whole block, and to make it a separate line.

then we add two lines, of which only one of them is only shown at any single time. The other one will be hidden.

The first line will be shown when there's not enough product's price in the cart to get free shipping. It informs how much they need to spend more to get there.

The second line will be shown when they DO have enough in their shopping cart already to qualify for free shipping. It informs how much the have to spend at least to keep the free shipping (whenever they want to delete any product later), so they don't have to guess.

 

One of each will be hidden, dependent of the $amount_until_free_shipping:

- when it's value is <=0 (they passed the threshold). The first line is hidden, the second line is shown.

- when it's value is >0 (they didn't pass the threshold yet). The first line is shown, the second line is hidden.

N.B. Hiding is done by adding the class "hidden" to the encompassing <span> of each line.

 

All displayed text lines are made translatable (localization->translations, installed modules translations) for when other languages (or other English wording) is preferred. A translatable field before and after the price gives flexibility

The price has a separate span around it to separate the css decoration from the text, to make it possible to give it another colour, change the font size etc.

Save the file.

 

 

By now, the value is shown correctly, whenever you do a refresh of your screen. But when adding products, you don't want to refresh the whole page, but only update the cart block.

 

That's where the ajax-cart.js kicks in:

We prepared our json file so that the values will be made available in javascript.

So now we let our ajax-cart handle the hiding/showing of the appropriate line, and update the value in the block:

 

Edit file: themes/<your theme folder>/js/modules/blockcart/ajax-cart.js (As always, backup…)

 

To update the values (and hide/show lines accordingly), we edit the function  updateCart : function(jsonData)

or more precisely a function within this function:

 

     updateCartEverywhere : function(jsonData) :

 

add the red code:

 

     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 if (typeof(freeShippingTranslation) != 'undefined')

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

          $('.ajax_cart_tax_cost').text(jsonData.taxCost);

          $('.cart_block_wrapping_cost').text(jsonData.wrappingCost);

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

 

          $('.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');

               });

          }

 

 

          this.nb_total_products = jsonData.nbTotalProducts;

         

          if (parseInt(jsonData.nbTotalProducts) > 0)

          {

           ...

 

What it does:

The line:

          $('.ajax_shipping_free_price').text(jsonData.amount_until_free_shipping);

 

updates the value of how much the customer needs to buy more.

The rest of the lines checks if there is enough in the cart or not,a nd displays/hides one of the two lines accordingly, as explained above.

 

 

Save the file.

 

 

Reload your page (Ctrl-F5 (Windows/Command-R (Mac) ) and see if it works. add more products to reach the free shipping level and see if the line changes. Delete one or more products and see if the old line comes back and the amount left to get to free shipping is correct.

 

You may need to (TEMPORARILY!!):  - turn OFF your smarty cache and - 'Template cache' set to "Recompile templates if the files have been updated" in Advanced Parameters->Performance

to see the changes. (Don't forget to turn cache back ON afterwards!)

 

I didn't add any suggestion for css decoration, as this you can all do according to your own preference (look at the class ="xxx" to get the class names, or id="yyy" to get the id names). If any question about this, do ask though.

 

Hope this helps,

pascal

Hello, I am now on 1.606 and files are different. Can use me ? Thank you .

Link to comment
Share on other sites

Have you tried this also? I think it's easier, but i don't know it's better :S

http://blog.belvg.com/the-minimal-order-amount-for-free-shipping.html

Could you clarify me?

Notice that for me I have 3 languages(spanish,english and french)

Notice I use theme695 instead original

Notice I use module 1 step check out

It will work for me either?

 

Thanks

 

www.ladolcevitashop.com

Link to comment
Share on other sites

  • 1 month later...

Hi Pascal,

 

Thanks for the reply. I have now managed to fix this.

The problem was in the comparison in the blockcart.tpl file it didn't seem to like the formatted variable. 

The workaround was to create a new unformatted float variable in the blockcart.php file alongside the currency formatted variable:

$amount_until_free_shipping_float = ($shipping_free_price - $params['cart']->getOrderTotal($useTax, Cart::BOTH_WITHOUT_SHIPPING));

 

then assign it

'amount_until_free_shipping_float' => (float)($amount_until_free_shipping_float)

 

then use that variable for the comparison in the tpl file

<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>
 
I hope this is self explanatory.
 
Rick
Link to comment
Share on other sites

  • 5 months later...
  • 4 months later...
  • 5 months later...
  • 6 months later...

I have Prestashop 1.6 and i tried this solution, and it works a little!

 

But there is one problem:

When you are going to the shopping cart, (wathever the amount is), he shows: You earned free shipping!

 

But when you are using then the quantity buttons (and here kicks ajax in i gues) he shows the correct amount until free shipping.

Also when you are reload the shopping cart page, he shows again the wrong notice: 'you earned free shipping'

 

Can someone help me with the rest of the code to fix it?

 

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

			'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');
               });
          }
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...