我正在Shopify上创建一个带有折扣的草稿订单,其返回错误如“必须与根据价值计算的结果一致”。
我的折扣计算如下:
$amount是订单的总金额(78.99),$rate(30)是折扣百分比的值。
$discount = $amount * ( $rate / 100);
$discount = $discount * pow(10, 2);
$discount = floatval($discount);
$discount = $discount / pow(10, 2);
$new_discount_amt = round($discount, 2);
这里,我的总数是78.99,我想在此基础上享受30%的折扣。所以最终的折扣金额是23.7英镑
$applied_discount = array(
"title" => "RCT Reorder Discount",
"description" => "Description",
"value" => "30",
"value_type" => "percentage",
"amount" => $new_discount_amt
);
购物退货
{"errors":{"applied_discount.amount":["must correspond to that calculated from the value"]}}
这个计算有什么问题?在Shopify中计算折扣的正确方法是什么?
那看起来大致可以。请记住,如果您使用的是基于十进制的货币,则金额为美分。
以下内容在节点的生产中工作。js应用程序:
var discount = 0.33;
var qty = parseInt(row.qty,10);
var rate = v.price * discount; //discount amount in cents
var line = {
variant_id: v.id,
quantity:qty,
description: row.description,
applied_discount:{
title:'Wholesale Discount',
value_type:'percentage',
value:(100*discount),
amount: Math.floor(100* qty * rate)/100
}
};