使用Smarty或jQuery计算值,不确定是哪个


Using Smarty or jQuery to calculate values, not sure which?

在Smarty中,我获取了以下值;

{$的产品。Bean_bag_quantity_150},在本例中返回1{$的产品。Bean_bag_quantity_300}并返回1

我还有

{$的产品。Bean_bag_filling_150}和{$product。bean_bag_filling_300}返回"N"或"Y"

我需要做什么,但不确定如何最好地做到这一点:我有{$product的条件。Bean_bag_filling_150}和其他

基本上我需要做以下事情:

{$的产品。Bean_bag_quantity_150}和{$product。bean_bag_quantity_300}包含填充量,因此如果150的值为0,则为0,但如果150返回3,我希望它执行3 × 150, 300也是如此。如果它返回1来执行1 × 300,然后将它们相加,但在某些情况下150可能是0,300可能是1,所以我们只需要执行1 × 300。

因此,如果启用了以150或300的倍数获得值,无论数量值是多少,如果设置和/如果将150和300的总和加在一起。

的例子:

如果启用了150并且填充值为:2
如果300被禁用

做2 * 150 = 300

如果启用150且值为4
如果启用300且值为3

4 × 150 = 600, 3 × 300 = 900,所以都是1500

等等……等等…

我的尝试:

如果Y

{if $product.bean_bag_filling_150 == "Y" || $product.bean_bag_filling_300 == "Y"}
                        {assign var="bb_qty_150_total" value=math equation="x * y" x=$product.bean_bag_quantity_150 y="150"}
                        {assign var="bb_qty_300_total" value=math equation="x * y" x=$product.bean_bag_quantity_300 y="300"}
                        <p>DEBUG: Total: {math equation="x + y" x=$bb_qty_150_total y=$bb_qty_300_total}</p>
                    {/if}

我的解决方案如下:

{if $product.bean_bag_filling_150 == "Y" && $product.bean_bag_filling_300 == "Y"}
                    {math assign="bb_qty_150_total" equation="x * y" x=$product.bean_bag_quantity_150 y=150}
                    {math assign="bb_qty_300_total" equation="x * y" x=$product.bean_bag_quantity_300 y=300}
                    <p>DEBUG: Total: {math equation="x + y" x=$bb_qty_150_total y=$bb_qty_300_total}</p>
                {elseif $product.bean_bag_filling_150 == "Y" && $product.bean_bag_filling_300 == "N"}
                    <p>DEBUG: Total: {math equation="x * y" x=$product.bean_bag_quantity_150 y=150}</p>
                {elseif $product.bean_bag_filling_150 == "N" && $product.bean_bag_filling_300 == "Y"}
                    <p>DEBUG: Total: {math equation="x * y" x=$product.bean_bag_quantity_300 y=300}</p>
                {/if}

如果有人知道或更好的解决方案,请随时分享:)