26 lines
782 B
JavaScript
26 lines
782 B
JavaScript
const { addCartItem, updateCartItem, deleteCartItem, getCart } = require("../lib/bigcommerceRestAPI")
|
|
const { postAddToCart } = require("../lib/facebookRestAPI")
|
|
|
|
;(function () {
|
|
const operation = context?.data?.operation
|
|
|
|
if (operation == "add") {
|
|
addCartItem(context?.data?.cartId, context?.data?.lineItems)
|
|
try {
|
|
postAddToCart()
|
|
} catch (e) {}
|
|
} else if (operation == "update") {
|
|
updateCartItem(context?.data?.cartId, context?.data?.lineItem, context?.data?.entityId)
|
|
try {
|
|
postAddToCart()
|
|
} catch (e) {}
|
|
} else if (operation == "delete") {
|
|
deleteCartItem(context?.data?.cartId, context?.data?.entityId)
|
|
}
|
|
|
|
throw {
|
|
status: 200,
|
|
message: "success",
|
|
}
|
|
})()
|