Jurist Posted November 18, 2016 Share Posted November 18, 2016 Hello, Just as in the title, I would like to add a module that will look like a language switch but will change the way prices are described. Simply to set all visible prices to tax included or without tax when pressed tax excluded. This would need to be saved in a cookie. Prices should only be displayed as with or without tax they should always be calculated with tax. Does the prestashop support this already or a new module needs to be created? I would appreciate any tip, many thanks. Link to comment Share on other sites More sharing options...
GabrielMota Posted July 30, 2017 Share Posted July 30, 2017 Anyone could help on this? How to save and change a session cookie? {if $includeTax} <div class="tax"> <a href="" onclick="changeTax()" <span> Tax included</span></a> </div> {else} <div class="tax"> <a href="" onclick="changeTax()" <span> Tax excluded </span></a> </div> {/if} Link to comment Share on other sites More sharing options...
Scully Posted July 30, 2017 Share Posted July 30, 2017 the cookie isn't the issue. you need a module together with an override since a simple override wouldn't be enough. the default tax calculation is controlled by tax rules and taxmanager. there you'll need to hook up. Link to comment Share on other sites More sharing options...
GabrielMota Posted July 30, 2017 Share Posted July 30, 2017 (edited) I think i made it In TPL <script> {literal} function setTaxExclude() { var expire = new Date(); expire.setMonth(expire.getMonth() + 12); document.cookie = 'taxDisplay'+ "=" + 'include' + ";path=/;" + ((expire == null) ? "" : ("; expires=" + expire.toGMTString())) } function setTaxInclude() { var expire = new Date(); expire.setMonth(expire.getMonth() + 12); document.cookie = 'taxDisplay' + "=" + 'exclude' + ";path=/;" + ((expire == null) ? "" : ("; expires=" + expire.toGMTString())) } {/literal} </script> {if $tax == 'include'} <div class="TaxDisplay"> <a href="" onclick="setTaxExclude()" <span> Tax included</span></a> </div> {else} <div class="TaxDisplay"> <a href="" onclick="setTaxInclude()" <span> Tax excluded</span></a> </div> {/if} in php $this->smarty->assign(array('tax' => $_COOKIE['tax'])); This is a button to change the var (include/exclude). Then just use {if $tax == 'include'} show price with tax in products.tpl and others... It worked for me but as I am newbie idk about performance... Edited July 30, 2017 by GabrielMota (see edit history) Link to comment Share on other sites More sharing options...
Scully Posted July 30, 2017 Share Posted July 30, 2017 In which tpl did you add this code? Some remarks: -> prestashop has its own cookie function which I would use. -> this is only about setting a cookie. it does nothing with overriding the price display. -> prestashop uses several rules which control price display and calculations. -> the challenge is to override only display but not calculation. Link to comment Share on other sites More sharing options...
GabrielMota Posted July 31, 2017 Share Posted July 31, 2017 (edited) I added in a tpl of module "blockuserinfo" so the button appear at the top. By replacing "public static function getPriceDisplayMethod($id_group)" function code in Group.php with if($_COOKIE['taxDisplay'] == 0) return 1; else return 0; Will make the product display the price with/without tax. Edited July 31, 2017 by GabrielMota (see edit history) Link to comment Share on other sites More sharing options...
Jurist Posted July 31, 2017 Author Share Posted July 31, 2017 (edited) Thanks for your reply. I will test this and let you know if it's works. Much appreciated for your contribution. Edited July 31, 2017 by Jurist (see edit history) Link to comment Share on other sites More sharing options...
Scully Posted July 31, 2017 Share Posted July 31, 2017 Give us a shop link if you have tested the basics. I'd like to see how it looks then. Link to comment Share on other sites More sharing options...
GabrielMota Posted July 31, 2017 Share Posted July 31, 2017 http://www.delikatessen.pt/ Top Left Button, you can see the price changing except for homefeatured/frontpage tabs that stays in cache. Link to comment Share on other sites More sharing options...
Scully Posted July 31, 2017 Share Posted July 31, 2017 I've found it. What I see is that the prices change when in the product details page or in a categoy page. However the prices do not change, when I am on the home page. It might be a caching issue. For example: homefeatured as many other modules write data to a cached file once a page fragment has been built. This helps in terms of performance. The culprit now could be that the cache information is tandomly populated with prices incl. or prices excl. depending on what user last called the page when it was stale or uncached. Link to comment Share on other sites More sharing options...
Jurist Posted July 31, 2017 Author Share Posted July 31, 2017 You said: in php $this->smarty->assign(array('tax' => $_COOKIE['tax'])); but where exactly in php? I am trying to create override for Group.php <?php class Group extends GroupCore { public static function getPriceDisplayMethod($id_group) { $this->smarty->assign(array('tax' => $_COOKIE['tax'])); if($_COOKIE['taxDisplay'] == 0) return 1; else return 0; } } but it gives internal server error. Where should I add that php code? Thanks Link to comment Share on other sites More sharing options...
GabrielMota Posted July 31, 2017 Share Posted July 31, 2017 (edited) In a php to pass the smarty to the tpl. Eg: by adding in blockuserinfo.php module in HookDisplayTop function you coud then use the var $tax in blockuserinfo.tpl to switch the text. Don't assign the smarty in Group.php For Homepage featured modules need to either disable the cache to those modules(via code) or duplicate the caches (with/without tax) by duplicating the tpl in module folder and adding in module php the code with the duplicated tpl if (!$this->isCached('homefeatured.tpl', $this->getCacheId('homefeatured.tpl')) || !$this->isCached('homefeatured.tpl', $this->getCacheId('homefeaturedtax.tpl'))) { ..... module code updating cache } if($_COOKIE['taxDisplay'] == 0) return $this->display(__FILE__, 'homefeatured.tpl', $this->getCacheId('homefeatured.tpl')); else return $this->display(__FILE__, 'homefeatured.tpl', $this->getCacheId('homefeaturedtax.tpl')); Edited July 31, 2017 by GabrielMota (see edit history) Link to comment Share on other sites More sharing options...
samanti Posted September 12, 2020 Share Posted September 12, 2020 Does this work in 1.7? Link to comment Share on other sites More sharing options...
GabrielMota Posted September 13, 2020 Share Posted September 13, 2020 On 9/12/2020 at 5:05 PM, samanti said: Does this work in 1.7? You would need to try, never touched in prestashop again, it was a one time intern work, I don't even remember ever programming in php. 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