ZenCart中的优惠券问题
我正在创建一个 ZenCart 支付模块。我可以传递产品、运输详细信息以及运费,但它不会在不弄乱货币格式的情况下传递优惠券。
如果我这样做,它根本不会显示优惠券
$mCouponCost => $order->info['coupon_cost'] * $order->info['currency_value'];
如果我这样做,它会显示优惠券,但它会弄乱货币格式
$mCouponCost = $order->info['coupon_cost'] -> $order->info['currency_value'];
所有代码如下:
$mCouponCost = $order->info['coupon_cost'] - $order->info['currency_value'];
if (!empty($mCouponCost)) {
$j++;
$process_button_string .= zen_draw_hidden_field('LIDSKU' . $j, 'Coupon') .
zen_draw_hidden_field('LIDDesc' . $j, 'Coupon Cost') .
zen_draw_hidden_field('LIDPrice' . $j, number_format($mCouponCost, 2, '.', '')) .
zen_draw_hidden_field('LIDQty' . $j, '1') .
zen_draw_hidden_field('ShippingRequired' . $j, '1') .
zen_draw_hidden_field('IsVoucher' . $j, '0');
}
我哪里出错了?
I am creating a ZenCart payment module. I can pass through the products, the shipping details as well as the shipping fee, but it won’t pass the coupon through without messing up the currency format.
If i do this, it won’t display the coupon at all
$mCouponCost => $order->info['coupon_cost'] * $order->info['currency_value'];
If i do it like this, it will display the coupon but it messes up the currency format
$mCouponCost = $order->info['coupon_cost'] -> $order->info['currency_value'];
All the code is below:
$mCouponCost = $order->info['coupon_cost'] - $order->info['currency_value'];
if (!empty($mCouponCost)) {
$j++;
$process_button_string .= zen_draw_hidden_field('LIDSKU' . $j, 'Coupon') .
zen_draw_hidden_field('LIDDesc' . $j, 'Coupon Cost') .
zen_draw_hidden_field('LIDPrice' . $j, number_format($mCouponCost, 2, '.', '')) .
zen_draw_hidden_field('LIDQty' . $j, '1') .
zen_draw_hidden_field('ShippingRequired' . $j, '1') .
zen_draw_hidden_field('IsVoucher' . $j, '0');
}
Where am I going wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您发布了 $mCouponCost = xxxxxxx 的 3 个变体
第一个使用 * 相乘...这是正确的解决方案。
第二个用途->这肯定是错误的,因为数据
不是对象格式 ->需要。
第三个,即您所说的“所有代码”的一部分,使用 -
这将是减法,并且绝对不会产生
正确的结果。
您的代码需要一些东西,其中一些在您的帖子中没有:
a)$ order对象必须在您使用它的函数/方法内声明为全局
b)您必须编写自己的代码来实际声明并为 $order->info 数组的 'coupon_cost' 元素分配一个值
c) 如果您正在处理多种货币,则将基本成本乘以 $order->info['currency_value'] 将得到货币的正确结果顾客正在购物。
确定您的问题是否实际上与您首先引用的代码行相关的一个简单测试是简单地分配
ie: 而不进行任何乘法。这样做可以揭示有用的信息,了解哪些其他问题实际上可能导致您遇到的困难。
You posted 3 variations of the $mCouponCost = xxxxxxx
The first uses * to multiply ... which is the correct solution.
The second uses -> which would definitely be wrong because the data
is not in the object format which -> would require.
The third, which is part of what you said is "all the code", uses a -
which would be subtracting, and definitely would not produce the
correct result.
Your code requires a few things, some of which are absent from your post:
a) the $order object must be declared as a global inside the function/method you're using it in
b) you must have written your own code to actually declare and assign a value to the 'coupon_cost' element of the $order->info array
c) if you're dealing with multiple currencies, then multiplying the base cost by $order->info['currency_value'] would yield the correct result for the currency in which the customer is shopping.
A simple test to determine whether your problem is actually related to the line of code you first quoted, would be to simply assign
ie: without doing any multiplication at all. Doing so would reveal useful information about what other problems might actually be causing the difficulties you're encountering.