2015-08-14 29 views
0

在Smarty中,我獲取以下值:使用Smarty或jQuery來計算值,不知道哪個?

{$ product.bean_bag_quantity_150}在這種情況下返回1 {$ product.bean_bag_quantity_300}並再次返回1

我也有

{$ product.bean_bag_filling_150}和{$ product.bean_bag_filling_300 }返回「N」或「Y」。

我需要做什麼,不確定如何做到最好:我對{$ product.bean_bag_filling_150}和其他條件都有條件。

基本上我需要做到以下幾點:

{$ product.bean_bag_quantity_150}和{$ product.bean_bag_quantity_300}包含填充量,因此,如果150 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} 

回答

0

摸索出我的解決方案,它是如下:

{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} 

如果有人知道或更好的解決方案,請隨時分享:)

相關問題