node.js - 如何将 Shopify 价格规则 ID 传递给 Shopify 折扣创建
问题描述
我正在尝试使用MONEI/Shopify-api-node创建折扣券,我成功创建了价格规则和价格规则 ID。 index.js(节点服务器)
在 .then 方法 priceRule.create 中,获取 priceRule id 后,我不想将响应返回给用户。我想使用 priceRule id 进行另一个调用,但要使用 discountCode.create。在 discountCode.create 的 .then 函数中,我无法获取 priceRule id 来创建折扣代码,现在将其返回给 UI。
简而言之,如何将 price Rule id 从 shopify.priceRule.create 传递给 shopify.discountCode.create ?
谢谢。
解决方案
这就是我如何将嵌套的 Promise 函数一起传递并像魔术一样工作。
shopify.priceRule.create({
email,
phone,
title: "REFERRALFRIEND",
allocation_method: "each",
once_per_customer: true,
target_type: "line_item",
target_selection: "all",
value_type: "percentage",
value: -15.0,
customer_selection: "all",
starts_at: "2018-10-10T1:00:10Z"
})
.then((data) => {
shopify.discountCode.create(data.id,
{ code: couponcode })
.then((data) => {
console.log(`coupon code created = `, data);
response.json({
status: 'success',
discount_code: {
code: couponcode,
}
});
})
.catch((err) => {
console.log(`Error in create coupon code'. = `, err);
console.log(`Error creating coupon code'. ${JSON.stringify(err.response.body)}`);
response.status(err.statusCode).send(err.response.body);
});
})
.catch((err) => {
console.log(`Error in create price rule'. = `, err);
console.log(`Error creating price rule'. ${JSON.stringify(err.response.body)}`);
response.status(err.statusCode).send(err.response.body);
});
}));
推荐阅读
- css - 将 CSS 类添加到闪亮的 textOutput
- python - 从磁盘驱动器、硬盘驱动器等获取设备品牌/型号
- r - 如何在 Greenplum/Postgres 中使用 PL/R 反序列化模型对象?
- laravel - 如何使用 Laravel mix 链接到 node_modules 文件夹
- javascript - CasperJS Angular按钮不起作用
- docker - 从主机发送 udp 数据包可以工作,但不能从容器发送
- vue.js - 将 CloudKit JS 添加到 Vue 项目
- sql - 可以杀死这个 DELETE 查询吗?
- javascript - 如何使用 webpack 将非 mudular javascript 文件捆绑到文件中
- xaml - UWP 中 ComboBox 的 CompositeCollection 替代方案?