Amazzing Posted January 22, 2013 Share Posted January 22, 2013 Hello dear community, I am using one page checkout order type. And I am trying to add a duplicate of total price just above the list of payment methods. The tricky part here is to update total value according to the tax rate applied for the selecred state. This information is updated on cart summary in live mode, without reloading the page just after you select the state. But I can't find a way to add copy of that dynamic field with the total amount, that can is changed in live mode. What I have done so far is: added the following code to /order-payment.tpl, just before <div id="HOOK_PAYMENT">{$HOOK_PAYMENT}</div> {displayPrice price=$total_price} So, it displays the total price, but this value doesn't update automatically after state selection. It is only updated when you refresh the page. So the question is: How can I add a duplicate of dynamic field of total price cell of the cart summary table? Link to comment Share on other sites More sharing options...
Amazzing Posted January 22, 2013 Author Share Posted January 22, 2013 here is the solution: open \js\cart-summary.js, line 682 add this just in the next line: $('#total_price_duplicate').html(formatCurrency(json.total_price, currencyFormat, currencySign, currencyBlank)); then wrap your {displayPrice price=$total_price} in a div, or span with id="total_price_duplicate" Link to comment Share on other sites More sharing options...
mmsh Posted January 3, 2014 Share Posted January 3, 2014 (edited) prestashop 1.4.x i have a problem with this... in cart_summary.js if i add $('#total_price_duplicate').html(formatCurrency(json.total_price, currencyFormat, currencySign, currencyBlank)); elements inside the header are not clickable anymore...except everything on the page content why? Edited January 3, 2014 by mmsh (see edit history) Link to comment Share on other sites More sharing options...
mmsh Posted January 3, 2014 Share Posted January 3, 2014 (edited) nevermind... first issue solved with better files check... now another... for a specific payment mode i would to add a fee (e.g. 2%) i tried to do it directly from js but no success...with smarty instead it just shows the correct value the first time page loads... formatCurrency(json.total_price, currencyFormat, currencySign, currencyBlank) is a string or an int(float)? how to do it from the js file and at the end show the final value with comma on the page ? OR inside the tpl can i do a thing like 1) jquery retrieve the #total_price_duplicate content 2) replace comma with dot 3) * .020 4) replace dot with comma 5) write the final value into #another_div ? or is the same thing about the page load ? so, if i choose another carrier it doesn't work anyway? i think that the solution is inside the js... please help Edited January 3, 2014 by mmsh (see edit history) Link to comment Share on other sites More sharing options...
mmsh Posted January 3, 2014 Share Posted January 3, 2014 (edited) OK Solved ps 1.4.x cart-summary.js $('#total_price_one').html(formatCurrency(json.total_price, currencyFormat, currencySign, currencyBlank)); $('#total_price_two').html(formatCurrencyd(json.total_price, currencyFormat, currencySign, currencyBlank)); ... and so on if you have different fees... tools.js (duplicate the formatCurrency function with other name) function formatCurrencyd(price, currencyFormat, currencySign, currencyBlank) { // if you modified this function, don't forget to modify the PHP function displayPrice (in the Tools.php class) blank = ''; //Add the fee price = price * 1.020; price = parseFloat(price.toFixed(6)); price = ps_round(price, priceDisplayPrecision); if (currencyBlank > 0) blank = ' '; if (currencyFormat == 1) return currencySign + blank + formatNumber(price, priceDisplayPrecision, ',', '.'); if (currencyFormat == 2) return (formatNumber(price, priceDisplayPrecision, ' ', ',') + blank + currencySign); if (currencyFormat == 3) return (currencySign + blank + formatNumber(price, priceDisplayPrecision, '.', ',')); if (currencyFormat == 4) return (formatNumber(price, priceDisplayPrecision, ',', '.') + blank + currencySign); return price; } order-payment.tpl YOURTEXT <span id="total_price_one">{displayPrice price=$total_price}</span> | YOURTEXT (+2%) <span id="total_price_two">{displayPrice price=$total_price*1.020}</span> or something like this, note the second {displayPrice price=$total_price*1.020}.. why? because the first time that the page loads, total price must be increased by the correct percentage if you click on other carriers, javascript does the trick, instead, and so replaces the span(div) content hope this helps Edited January 3, 2014 by mmsh (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts