Last active
July 1, 2019 11:36
-
-
Save dfa1234/f99a711a4a1592abe1d87f769fb0eeff to your computer and use it in GitHub Desktop.
Wix code (Corvid) bulk coupons insert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
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