Mian Waqas Posted April 12, 2023 Share Posted April 12, 2023 Hello, On product page if the TAX amount for a product is 0 , how i can write IF statement for it , so that if the tax amount is 0 the tax label shall be ABC, and if the tax amount is more then 0 then the label shall be XYZ. i know the tax labeling configs etc on back office, but i am specifically asking about this how to get the tax amount value in IF/Else statment. Thanks Link to comment Share on other sites More sharing options...
Mian Waqas Posted April 13, 2023 Author Share Posted April 13, 2023 Still waiting on this to hear from someone... Link to comment Share on other sites More sharing options...
AddWeb Solution Posted April 14, 2023 Share Posted April 14, 2023 On 4/13/2023 at 5:10 AM, Mian Waqas said: how to get the tax amount value You can get it using $product.price*($product.tax_rate/100) from your product.tpl file In your case, the code will be something like {if $product.tax_rate > 0} {assign var="tax_amount" value=$product.price*($product.tax_rate/100)} {assign var="tax_label" value="XYZ"} {else} {assign var="tax_amount" value=0} {assign var="tax_label" value="ABC"} {/if} <p>{tax_label}</p> Link to comment Share on other sites More sharing options...
Mian Waqas Posted April 14, 2023 Author Share Posted April 14, 2023 (edited) 2 hours ago, AddWeb Solution said: You can get it using $product.price*($product.tax_rate/100) from your product.tpl file In your case, the code will be something like {if $product.tax_rate > 0} {assign var="tax_amount" value=$product.price*($product.tax_rate/100)} {assign var="tax_label" value="XYZ"} {else} {assign var="tax_amount" value=0} {assign var="tax_label" value="ABC"} {/if} <p>{tax_label}</p> Thank you for the reply, however i have tried to test these codes but not getting succeed. this i am doing on product-prices.tpl Edited April 14, 2023 by Mian Waqas (see edit history) Link to comment Share on other sites More sharing options...
AddWeb Solution Posted April 14, 2023 Share Posted April 14, 2023 Are you able to get $product.tax_rate and $product.price values in product-prices.tpl? Link to comment Share on other sites More sharing options...
Mian Waqas Posted April 14, 2023 Author Share Posted April 14, 2023 23 minutes ago, AddWeb Solution said: Are you able to get $product.tax_rate and $product.price values in product-prices.tpl? i can get $product.price but cannot get $product.tax_rate i belive if somehow i can get the tax_rate which will be 0 for some products there i can achieve my goal as follow. {if $product.tax_rate eq "$ 0"} <span> abc </span> {else} <span> xyz</span> {/if} Link to comment Share on other sites More sharing options...
AddWeb Solution Posted April 14, 2023 Share Posted April 14, 2023 May be try using the below snippet and let me know if it helps. {assign var='tax_amount' value=$tax_calculator->getTaxAmount($product.price, $product.tax_rate)} {if $tax_amount == 0} <span> {l s='ABC'} </span> {else} <span> {l s='XYZ'} </span> {/if} Link to comment Share on other sites More sharing options...
Mian Waqas Posted April 14, 2023 Author Share Posted April 14, 2023 4 minutes ago, AddWeb Solution said: May be try using the below snippet and let me know if it helps. {assign var='tax_amount' value=$tax_calculator->getTaxAmount($product.price, $product.tax_rate)} {if $tax_amount == 0} <span> {l s='ABC'} </span> {else} <span> {l s='XYZ'} </span> {/if} Nop, i think this line, which is giving error {assign var='tax_amount' value=$tax_calculator->getTaxAmount($product.price, $product.tax_rate)} need correction Link to comment Share on other sites More sharing options...
AddWeb Solution Posted April 14, 2023 Share Posted April 14, 2023 4 minutes ago, Mian Waqas said: i think this line, which is giving error Could you please share the error message ? Link to comment Share on other sites More sharing options...
Mian Waqas Posted April 14, 2023 Author Share Posted April 14, 2023 1 hour ago, AddWeb Solution said: Could you please share the error message ? error is basically after this line nothing loads on the front. like on this line everything stops Link to comment Share on other sites More sharing options...
Mian Waqas Posted April 15, 2023 Author Share Posted April 15, 2023 `{assign var="tax_amount" value=Context::getContext()->currentLocale- >formatPrice($product.price_tax_exc, $currency.iso_code)} {if {$tax_amount} == {$product.price}} abc {else} xyz {/if}` Here is the Answer how to achieve this. 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