shopify - 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 中计算折扣的正确方法是什么?
解决方案
看起来大致还可以。请记住,如果您使用基于十进制的货币,金额以美分为单位。
以下在 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
}
};
推荐阅读
- python - Iterable-Unpack 导致稍后的函数调用无法正常工作
- xml - 请求在本地笔记本上工作,但在云笔记本上返回 403
- python - 如何在 python 中使用 opencv 防止分段错误
- sqlite - 尽管受到互斥锁保护,SQLite 更新失败并显示“数据库已锁定”
- css - 图标的范围很奇怪(CSS 范围 Vue.js 3)
- javascript - 通过切片使用异步迭代器进行集合的顺序映射
- java - 为转换提供资源提示时,Dataflow Prime 作业失败
- javascript - 事件“OnKeyDown”在反应应用程序中工作不正确
- javascript - Inquirer.js javascript 输入中的选项
- reactjs - React 组件不刷新