gpt4 book ai didi

Shopify 草稿订单创建生成错误 'must correspond to that calculated from the value'

转载 作者:行者123 更新时间:2023-12-02 15:46:25 24 4
gpt4 key购买 nike

我正在 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 中计算折扣的正确方法是什么?

最佳答案

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

以下内容适用于 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
}
};

关于Shopify 草稿订单创建生成错误 'must correspond to that calculated from the value',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53862690/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com