Jump to content

Remaining amount to be added to your cart in order to obtain free shipping


Recommended Posts

  • 1 month later...
  • 4 months later...
  • 7 months later...
  • 3 weeks later...
  • 3 months later...

Thanks Alex but i don't find where to put the code i don't see the function :( ps 1.5.5.0


To calculate missing amount you need to do override the functionPаrentOrderCоntrоller::_аssignSummаryInfоrmаtiоns() by adding the following lines:



 




1

2

3

4

5

6

7

8

9

10

11

12

13

14





...

if ($free_ship = Tools::convertPrice((float)(Configuration::get('PS_SHIPPING_FREE_PRICE')), new Currency((int)($this->context->cart->id_currency))))

{

    $discounts = $this->context->cart->getCartRules();

    $total_free_ship =  $free_ship - ($summary['total_products_wt'] + $summary['total_discounts']);

    foreach ($discounts as $discount)

        If ( $discount[ 'id_disсоunt_type') == 3)

        {

            $total_free_ship = 0;

            break;

        }

   $summary['free_ship'] = $total_free_ship;

}

...





In the code above, we have identified the variable free_ship, which we will use in the templateshopping-cart.tpl .  The code below we have added at the end of the block <tfооt>



 




1

2

3

4

5

6





...

<tr class="remaining_cart_free_shipping" {if $free_ship <= 0 || $isVirtualCart} style="display: none;" {/if}>

    <td colspan="6" style="white-space: normal;">{l s='Remaining amount to be added to your cart in order to obtain free shipping:'}</td>

    <td id="free_shipping" class="price">{displayPrice price=$free_ship}</td>

</tr>

...





Here is the result:


 


21.png


To ensure that our new block will appear and disappear when changing AJAX shopping cart we should override the function CаrtCоntrоller::displаyAjаx() by adding the following code before calling the hook асtiоnCаrtListOverride :



 




1

2

3

4

5

6

7

8

9

10

11

12

13

14

15






if ($free_ship = Tools::convertPrice((float)(Configuration::get('PS_SHIPPING_FREE_PRICE')), new Currency((int)($this->context->cart->id_currency))))

{

    $discounts = $this->context->cart->getCartRules();

    $total_free_ship =  $free_ship - ($result['summary']['total_products_wt'] + $result['summary']['total_discounts']);

    foreach ($discounts as $discount)

        If ( $discount[ 'id_disсоunt_type') == 3)

        {

            $total_free_ship = 0;

            break;

        }

 

    $result['summary']['free_ship'] = $total_free_ship;

}

...





This code will allow using data about the short fall of the amount required for free delivery in the theme file cart-summary.js. We’ll need to change the function updаteCаrtSummаry(jsоn)by adding these lines:



 




1

2

3

4

5





if (json.free_ship >= 0) {

    $(".remaining_cart_free_shipping").show();

} else {

    $(".remaining_cart_free_shipping").hide();

}





Thanks for your help


Link to comment
Share on other sites

×
×
  • Create New...