使用 Smarty 或 jQuery 来计算值,不确定是哪个?
Using Smarty or jQuery to calculate values, not sure which?
在 Smarty 中,我获取了以下值;
{$product.bean_bag_quantity_150} 在本例中 returns 1
{$product.bean_bag_quantity_300} 又一次 returns 1
我也有
{$product.bean_bag_filling_150} 和 {$product.bean_bag_filling_300} 其中 return "N" 或 "Y".
我需要做什么,但不确定如何最好地做到这一点:我在 {$product.bean_bag_filling_150} 和另一个上有条件。
基本上我需要做以下事情:
{$product.bean_bag_quantity_150} 和 {$product.bean_bag_quantity_300} 包含填充量,所以如果 150 有 0 将是 none 但如果 150 returns 3 我希望它做 3 x 150 和 300 相同。如果它 returns 1 做 1 x 300 然后将它们加在一起,但在某些情况下 150 可能是 0 而 300 可能是1 所以只需要做 1 x 300。
因此,如果启用以获取值,有时它们会增加 150 或 300,无论数量值是多少,如果其设置和/如果将 150 和 300 的总数相加。
示例:
如果启用 150 且填充值为:2
如果禁用 300
做 2 x 150 = 300
如果启用 150 且值为 4
如果启用 300 且值为 3
做 4 x 150 = 600、3 x 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}
如果有人知道或有更好的解决方案,请随时分享:)
在 Smarty 中,我获取了以下值;
{$product.bean_bag_quantity_150} 在本例中 returns 1 {$product.bean_bag_quantity_300} 又一次 returns 1
我也有
{$product.bean_bag_filling_150} 和 {$product.bean_bag_filling_300} 其中 return "N" 或 "Y".
我需要做什么,但不确定如何最好地做到这一点:我在 {$product.bean_bag_filling_150} 和另一个上有条件。
基本上我需要做以下事情:
{$product.bean_bag_quantity_150} 和 {$product.bean_bag_quantity_300} 包含填充量,所以如果 150 有 0 将是 none 但如果 150 returns 3 我希望它做 3 x 150 和 300 相同。如果它 returns 1 做 1 x 300 然后将它们加在一起,但在某些情况下 150 可能是 0 而 300 可能是1 所以只需要做 1 x 300。
因此,如果启用以获取值,有时它们会增加 150 或 300,无论数量值是多少,如果其设置和/如果将 150 和 300 的总数相加。
示例:
如果启用 150 且填充值为:2
如果禁用 300
做 2 x 150 = 300
如果启用 150 且值为 4
如果启用 300 且值为 3
做 4 x 150 = 600、3 x 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}
如果有人知道或有更好的解决方案,请随时分享:)