Gowtham Posted August 13, 2013 Share Posted August 13, 2013 (edited) 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. Thanks in advance Gowtham Edited August 22, 2013 by Gowtham (see edit history) Link to comment Share on other sites More sharing options...
swsindonesia Posted August 13, 2013 Share Posted August 13, 2013 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. 2 Link to comment Share on other sites More sharing options...
Gowtham Posted August 13, 2013 Author Share Posted August 13, 2013 (edited) 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 August 13, 2013 by Gowtham (see edit history) Link to comment Share on other sites More sharing options...
swsindonesia Posted August 14, 2013 Share Posted August 14, 2013 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 More sharing options...
PascalVG Posted August 14, 2013 Share Posted August 14, 2013 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 More sharing options...
swsindonesia Posted August 14, 2013 Share Posted August 14, 2013 Hi Pascal, Do those variables depend on price rule used, or any discount would be stored in those variables ? Link to comment Share on other sites More sharing options...
PascalVG Posted August 14, 2013 Share Posted August 14, 2013 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 1 Link to comment Share on other sites More sharing options...
swsindonesia Posted August 15, 2013 Share Posted August 15, 2013 (edited) 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 August 15, 2013 by swsindonesia (see edit history) Link to comment Share on other sites More sharing options...
Gowtham Posted August 16, 2013 Author Share Posted August 16, 2013 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 More sharing options...
Gowtham Posted August 16, 2013 Author Share Posted August 16, 2013 I have attached the contents of smarty debug console. Pl. go through and help me. Smarty Debug Console.pdf Thanks, Gowtham. Link to comment Share on other sites More sharing options...
Gowtham Posted August 17, 2013 Author Share Posted August 17, 2013 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 ?? Link to comment Share on other sites More sharing options...
PascalVG Posted August 17, 2013 Share Posted August 17, 2013 Gowtham, A quick check. Does it show the correct value when a refresh of the page is done? Please let me know, then we can try to enforce a refresh after deleting the product using javascript:history.go(0) or so. pascal Link to comment Share on other sites More sharing options...
PascalVG Posted August 17, 2013 Share Posted August 17, 2013 (To manually Refresh the page, press F5 or Ctrl-F5 (windows), or on a Mac Ctrl-R.) Link to comment Share on other sites More sharing options...
Gowtham Posted August 17, 2013 Author Share Posted August 17, 2013 Hello Pascal, It shows correct value on refresh. Can you guide me how to refresh when a product is deleted. Thanks Gowtham Link to comment Share on other sites More sharing options...
PascalVG Posted August 17, 2013 Share Posted August 17, 2013 Hi Gowtham, How exactly did you delete the product? (Decrease amount using arrows, press delete button? Link to comment Share on other sites More sharing options...
swsindonesia Posted August 19, 2013 Share Posted August 19, 2013 (edited) 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 August 19, 2013 by swsindonesia (see edit history) Link to comment Share on other sites More sharing options...
PascalVG Posted August 19, 2013 Share Posted August 19, 2013 Gowtham, Also: Do you use one page checkout or 5 step check out? Link to comment Share on other sites More sharing options...
Gowtham Posted August 22, 2013 Author Share Posted August 22, 2013 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 More sharing options...
swsindonesia Posted August 22, 2013 Share Posted August 22, 2013 Hi, Glad you solved the problem. Do you mind sharing your cartsummary.js changes, could be useful for other members. Also, please mark [sOLVED] in your topic subject. Cheers Link to comment Share on other sites More sharing options...
Gowtham Posted August 22, 2013 Author Share Posted August 22, 2013 (edited) 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 August 22, 2013 by Gowtham (see edit history) 1 Link to comment Share on other sites More sharing options...
naal1 Posted August 22, 2013 Share Posted August 22, 2013 (edited) 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 August 22, 2013 by naal1 (see edit history) Link to comment Share on other sites More sharing options...
swsindonesia Posted August 23, 2013 Share Posted August 23, 2013 Hi Gowtham, thanks for sharing your solution! Hi naal1, to avoid confusion, could you post a new topic referring to this one, since this topic already marked [sOLVED], I'm afraid you won't be getting much help here. 1 Link to comment Share on other sites More sharing options...
naal1 Posted August 23, 2013 Share Posted August 23, 2013 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 More sharing options...
Gomlers Posted February 21, 2014 Share Posted February 21, 2014 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 More sharing options...
Gomlers Posted February 21, 2014 Share Posted February 21, 2014 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 More sharing options...
aliaspt Posted May 4, 2015 Share Posted May 4, 2015 Will the solution posted here work in Prestashop 1.6.09? Or it works for any newer version? Thanks. Link to comment Share on other sites More sharing options...
prestashopnew Posted February 26, 2016 Share Posted February 26, 2016 (edited) Hello guys, I am using prestashop 1.6.1.4 I wish I could see the percentage discount for each product at the top right of the image, instead of the word "new" or "sale" I would appreciate your help, it is very important, thanks in advance Edited February 27, 2016 by prestashopnew (see edit history) Link to comment Share on other sites More sharing options...
mariar2019 Posted January 30, 2019 Share Posted January 30, 2019 porque no tengo el archivo shoping-cart.tpl ? mi versión es la 1.7.5.0 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now