Jump to content

Display Total discount in cart summary [SOLVED]


Gowtham

Recommended Posts

Hello Friends,

 

I want my customers to know how much money they had saved buying in my store. So i tried adding Discounts column in cart summary. So i modified shopping-cart-product-line.tpl and it worked great for me. I also want to sum up the total discount and display it near total bill amount. So i tried it in the same tpl. But it gets called for each products and the variables gets reset. So i tried it in shopping-cart.tpl and it also didn't work for me. Pl. help me do it.

post-558093-0-15778500-1376373710_thumb.jpg

 

Thanks in advance

Gowtham

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

Hi,

You can edit shoping-cart.tpl to have a variable sum up all the "discount amount" you already have in the "Discounted price" column, and display the value.

What version of PS are you using ? Default / custom theme ?

You can share your shopping-cart.tpl if you like, to help us understand your theme structure.

  • Like 2
Link to comment
Share on other sites

Hi,

You can edit shoping-cart.tpl to have a variable sum up all the "discount amount" you already have in the "Discounted price" column, and display the value.

What version of PS are you using ? Default / custom theme ?

You can share your shopping-cart.tpl if you like, to help us understand your theme structure.

 

Thanks swsindonesia for your reply,

 

I already tried that and the variables are not working in shopping-cart.tpl.

 

I am trying to find the php file which has the variables initiated. Can you help me with that ?

 

I am using prestashop 1.5.4.1 and i am using a custom theme.

 

My shopping-cart.tpl code is

 

shopping-cart.txt

 

Thanks,

Gowtham

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

Hi, it seemed you don't have to go to the controller (php) to achieve this, even your template calculates the discounted price by itself.

You might wanna do this:

1. initiate a counter variable (around line 358/360) just before {foreach $discounts as $discount}

 {assign var=you_saved value=0} {* initiate counter *}
 {foreach $discounts as $discount}

 

2. increment each discount price of the items into that variable (around line 402/404), add the increment statement after your template display the individual discount

from this:

      <div class="floatL">{if !$priceDisplay}{convertPrice price=(($product.price_without_specific_price)-$product.price)}{/if}

add some code to this:

      <div class="floatL">{if !$priceDisplay}{convertPrice price=(($product.price_without_specific_price)-$product.price)}{$you_saved=$you_saved+(($product.price_without_specific_price)-$product.price)}{/if}

 

3. Last, you surely wanna display that variable, around line 665/660

change

<span id="total_discount_price">{displayPrice price={$smarty.capture.mytotal[spam-filter]</span>

to

<span id="total_discount_price">{displayPrice price=$you_saved}</span>

 

best of luck.

Link to comment
Share on other sites

I believe in GetSummaryDetails() (Cart.php) a variable:

$total_discounts and $total_discounts_tax_exc are set. Try to use these directy.

 

(Maybe need to be added in protected function _assignPayment():

$this->context->smarty->assign(array(

'total_price' => (float)($orderTotal),

'taxes_enabled' => (int)(Configuration::get('PS_TAX'))

ADD HERE DISCOUNTED VARS

));

 

 

 

My 2 cents,

pascal

Link to comment
Share on other sites

Hi sws,

First of all thanks for all your input on the forum! Well knowledged, clear explanations! :-)

 

 

The Vars get their value from a function: (see Cart.php, public function getSummaryDetails($id_lang = null, $refresh = false)

(Which gives a summary for the current cart.

 

$total_discounts = $this->getOrderTotal(true, Cart::ONLY_DISCOUNTS);

$total_discounts_tax_exc = $this->getOrderTotal(false, Cart::ONLY_DISCOUNTS);

 

 

Which points to this function, also in Cart.php:

 

public function getOrderTotal($with_taxes = true, $type = Cart::BOTH, $products = null, $id_carrier = null, $use_cache = true)

 

A lengthy function with loads of details. Maybe have a look if you're interested what really happens here. :-)

 

My 2 cents,

pascal

  • Like 1
Link to comment
Share on other sites

Hi Pascal,

Glad I can contribute to this awesome shopping cart :)

 

Gowtham,

Why don't you try to enable the Smarty debug console to see what are the variable available to use.

1. Go to Advanced Parameters -> Performance, Always enable smarty debug console

2. reload your checkout page, a pop-up window will show (make sure your browser doesn't block it).

3. examine the available variables there, or share with us in this thread :)

4. don't forget to turn your smarty debug console off again.

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

Hi swsindonesia,

 

I tried your method to calculate discount in shopping-cart.tpl, but it didn't work. I will enable Smarty Debug Console and let you know if there is any positive response.

 

Pascal,

I also tried your Method and printed $total_discounts and $total_discounts_tax_exc. But the value displayed is 0.

Can you please explain it in more detail, So that i can solve this?

 

 

Thanks,

Gowtham

Link to comment
Share on other sites

Well, Finally worked out what sws said and made the discount to display in the specified place. But it don't refresh when a single product from cart summary is deleted. Any Suggestions ??

 

Hi Gowtham,

My solution was just for setting up the discount for the first time using smarty calculation.

If you delete the product, it won't do any recalculation, unless you force refresh the page (using javascript invocation upon delete), but we need to know which way of product deletion you're doing.

 

@Pascal,

I thought yours would be a better way to do it, I'll dive into the code to see what's wrong with those total variables.

If you look at the smarty debug console, both $total_discounts, and $total_discounts_tax_exc have 0 values, which is unexpected

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

Hi pascal & swsindonesia,

 

I have solved the problem.

The problem is the variable don't refresh in both the scenarios.

The solution is to edit the cartsummary.js. The tpl calculated variable should be refreshed using js.

 

Thanks for your support guys,

Gowtham

Link to comment
Share on other sites

Hi Frnds,

 

Add the variable initialization around 574 in shopping-cart.js

var total_disc =0;
var price_disc =0;

 

Add the below code around line 652 in shopping-cart.js

 

total_disc +=(product_list[i].price_without_quantity_discount*product_list[i].quantity_without_customization   - product_list[i].price*product_list[i].quantity_without_customization );
price_disc =((product_list[i].price_without_quantity_discount  - product_list[i].price )*product_list[i].quantity_without_customization);
$('#price_disc_'+key_for_blockcart).html(formatCurrency(price_disc ,currencyFormat, currencySign, currencyBlank));

}

$('#total_discount_price').html(formatCurrency(total_disc ,currencyFormat, currencySign, currencyBlank));

 

use total_discount_price as id in shopping-cart.tpl for total discount and use

price_disc_{$product.id_product}_{$product.id_product_attribute}{if $quantityDisplayed > 0}_nocustom{/if}_{$product.id_address_delivery|intval}{if !empty($product.gift)}_gift{/if}

as id in shopping-cart-product-line.tpl for product discount. The above shown code is the representation of key_for_blockcart in js.

 

Hope it helps,

Gowtham

Edited by Gowtham (see edit history)
  • Like 1
Link to comment
Share on other sites

Hello Support,

 

I was reading this topic from start and assume that i might jump inbetween you. Though i already raised that question here but i was not clear enough to understand and i even don't understood prestashop 1.5.

 

I have created module same as like screenshot attached in first post. Voucher textbox and ok as submit .. then user will put voucher code and discount take place but for that we have to first create Cart rules and set price etc.. but here my requirement is when user enter voucher code then it will connect to third party and get the discount amt and then show discounted amount in shopping cart page.. but its seems not possible in prestashop we have to create rules first.. so my question is can i made module on that part if yes please please help me how..

 

Thanks

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

Hi PrestaShop Apprentice,

 

Thanks atleast you have replied me.. really feel good ... actually i am near to complete module created Cartrules from module through Ajax and now want to apply same CartRules on Customer order like normal system putting vocher code and then it show discounted amount in shopping cart page same way..

 

Please reply i have created new topic here http://www.prestashop.com/forums/topic/269743-module-to-apply-cartrules-or-voucher-code-on-shopping-order-through-ajax-php/

 

Please reply thanks waiting for your reply.

Link to comment
Share on other sites

  • 5 months later...

This is exactly what I'm trying to do too!

I checked your Smarty Debug .pdf and it looks like you have MEGASHOP by templatin?
What a coincidence - me too!

I'm a complete beginner to both php and Smarty.

Can you please help me in achieving what you managed to do in your cart?
I want to display to my customers how much they have saved, by shopping discounted products in my shop.

 

Which files must I change, and what must I add?

I also want it to work with the ajaxcart.

Regards,
Roger, Norway
 

Link to comment
Share on other sites

Hi Frnds,

 

Add the variable initialization around 574 in shopping-cart.js

var total_disc =0;
var price_disc =0;
Add the below code around line 652 in shopping-cart.js

 

total_disc +=(product_list[i].price_without_quantity_discount*product_list[i].quantity_without_customization   - product_list[i].price*product_list[i].quantity_without_customization );
price_disc =((product_list[i].price_without_quantity_discount  - product_list[i].price )*product_list[i].quantity_without_customization);
$('#price_disc_'+key_for_blockcart).html(formatCurrency(price_disc ,currencyFormat, currencySign, currencyBlank));

}

$('#total_discount_price').html(formatCurrency(total_disc ,currencyFormat, currencySign, currencyBlank));
use total_discount_price as id in shopping-cart.tpl for total discount and use
price_disc_{$product.id_product}_{$product.id_product_attribute}{if $quantityDisplayed > 0}_nocustom{/if}_{$product.id_address_delivery|intval}{if !empty($product.gift)}_gift{/if}
as id in shopping-cart-product-line.tpl for product discount. The above shown code is the representation of key_for_blockcart in js.

 

Hope it helps,

Gowtham

 

 

What do you mean by

use total_discount_price as id in shopping-cart.tpl for total discount

 

and

 

use

price_disc_{$product.id_product}_{$product.id_product_attribute}{if $quantityDisplayed > 0}_nocustom{/if}_{$product.id_address_delivery|intval}{if !empty($product.gift)}_gift{/if}

as id in shopping-cart-product-line.tpl for product discount. The above shown code is the representation of key_for_blockcart in js.

 

Link to comment
Share on other sites

  • 1 year later...
  • 9 months later...
  • 2 years later...

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