Shopify草稿订单创建生成错误“必须与根据值计算得出的错误相对应”

时间:2018-12-20 05:07:48

标签: shopify

我正在打折的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
            );

Shopify退货

{"errors":{"applied_discount.amount":["must correspond to that calculated from the value"]}}

此计算有什么问题? 在Shopify中计算折扣的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

看起来不错。请记住,如果您使用的是基于十进制的货币,则金额以美分计。

以下内容可在node.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
    }
};