Skip to content

Instantly share code, notes, and snippets.

@dfa1234
Last active July 1, 2019 11:36
Show Gist options
  • Save dfa1234/f99a711a4a1592abe1d87f769fb0eeff to your computer and use it in GitHub Desktop.
Save dfa1234/f99a711a4a1592abe1d87f769fb0eeff to your computer and use it in GitHub Desktop.
Wix code (Corvid) bulk coupons insert
/**
The corvid doc api is not correct
Actually using the doc we get
Error message: "No coupon type"
Here is the code to fix this:
*/
/*
// Backend code (jsw file)
import wixMarketing from 'wix-marketing-backend';
export function deleteCoupon(couponId) {
return wixMarketing.deleteCoupon(couponId);
}
export function createCoupon(couponData) {
return wixMarketing.createCoupon(couponData);
}
*/
// Front end code (js file)
import { createCoupon, deleteCoupon } from 'backend/aModule';
const codes = [
"XXX",
"YYY"
]
async function deleteAllCoupons(mCode){
let i = 0;
for (let code of mCode) {
i++;
console.log(i,code);
try {
await deleteCoupon(code)
} catch(e) {
console.log(i,code,e)
}
}
}
async function createAllCoupons(allCode) {
let i = 0;
for (let code of allCode) {
i++;
console.log(i,code);
try {
await createCoupon({
name: code,
code: code,
startTime: new Date(),
expirationTime: new Date(2020, 11, 31),
usageLimit: 1,
limitedToOneItem: false,
active: true,
scope: {
namespace: 'stores',
},
moneyOffAmount: 30,
})
} catch(e) {
console.log(i,code,e)
}
}
}
$w.onReady(function () {
createAllCoupons(codes)
.then(
res => console.log(res),
err => console.log(err)
)
});
{
name: "TEST11",
code: "TEST11",
startTime: new Date(),
expirationTime: null,
limitedToOneItem: true,
usageLimit: 1,
active: true,
minimumSubtotal: 1,
displayData: null,
moneyOffAmount: 30,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment