Search code examples
phpprestashopsmarty

Unable to multiply two variables in Smarty on Prestashop


In my prestashop store, I have two variables per_sqft_price and per_box_price. per_sqft_price is having currency ($) sign before. I am trying to print the multiplied value of those 2 variables. But it is always printing 0.

{assign var = per_sqft_price value = $product.price}
{assign var = per_box_price value = $product.features[0].value}

<meta itemprop="per_sqft_price" content="{$per_sqft_price|replace:'$':''}"/>
{math equation = "x * y" x = $per_sqft_price  y = $per_box_price }

Please help me how can i solve this. Thanks in advance


Solution

  • Use $product.price_amount instead of $product.price, it gives numeric price output without currency sign. And be sure that $product.features[0].value is numeric as well, because it may be a string and may contain just a text. Also, you can use intval for your variables like:

    {math equation = "x * y" x = $per_sqft_price|intval  y = $per_box_price|intval }