Last active
August 20, 2023 16:50
-
-
Save daguitosama/42dad5c5f351f623b14bc4b21a52f049 to your computer and use it in GitHub Desktop.
BOGO feature exploration
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
import { createClient, OAuthStrategy } from "@wix/api-client"; | |
import { cart } from "@wix/ecom"; | |
import { CreateCartOptions } from "@wix/ecom/build/cjs/src/ecom-v1-cart-cart.universal"; | |
const WIX_STORES_APP_ID = "1380b703-ce81-ff05-f115-39571d94dfcd"; | |
const wixClient = createClient({ | |
modules: { cart }, | |
auth: OAuthStrategy({ clientId: "ID" }) | |
}); | |
const test_product = { | |
_id: "8e32a96f-256c-5553-1572-3aac96a061b1", | |
name: "Test Product #5", | |
slug: "test-product-5", | |
visible: true, | |
productType: "physical", | |
description: "<p>This product is for development purposes only</p>", | |
sku: "", | |
weight: 0, | |
weightRange: { | |
minValue: 0, | |
maxValue: 0 | |
}, | |
stock: { | |
trackInventory: false, | |
inStock: true, | |
inventoryStatus: "IN_STOCK" | |
}, | |
price: { | |
currency: "USD", | |
price: 4, | |
discountedPrice: 4, | |
formatted: { | |
price: "$4.00", | |
discountedPrice: "$4.00" | |
} | |
}, | |
priceData: { | |
currency: "USD", | |
price: 4, | |
discountedPrice: 4, | |
formatted: { | |
price: "$4.00", | |
discountedPrice: "$4.00" | |
} | |
}, | |
convertedPriceData: { | |
currency: "USD", | |
price: 4, | |
discountedPrice: 4, | |
formatted: { | |
price: "$4.00", | |
discountedPrice: "$4.00" | |
} | |
}, | |
priceRange: { | |
minValue: 4, | |
maxValue: 4 | |
}, | |
costRange: { | |
minValue: 0, | |
maxValue: 0 | |
}, | |
additionalInfoSections: [], | |
ribbons: [ | |
{ | |
text: "TEST" | |
} | |
], | |
media: { | |
mainMedia: { | |
thumbnail: { | |
url: "https://static.wixstatic.com/media/da2cd5_ae257d6db3704327960af1635ce3d1e5~mv2.webp/v1/fit/w_50,h_50,q_90/file.webp", | |
width: 50, | |
height: 50 | |
}, | |
mediaType: "image", | |
title: "argan-oil.webp", | |
image: { | |
url: "https://static.wixstatic.com/media/da2cd5_ae257d6db3704327960af1635ce3d1e5~mv2.webp/v1/fit/w_924,h_1232,q_90/file.webp", | |
width: 924, | |
height: 1232 | |
}, | |
_id: "da2cd5_ae257d6db3704327960af1635ce3d1e5~mv2.webp" | |
}, | |
items: [ | |
{ | |
thumbnail: { | |
url: "https://static.wixstatic.com/media/da2cd5_ae257d6db3704327960af1635ce3d1e5~mv2.webp/v1/fit/w_50,h_50,q_90/file.webp", | |
width: 50, | |
height: 50 | |
}, | |
mediaType: "image", | |
title: "argan-oil.webp", | |
image: { | |
url: "https://static.wixstatic.com/media/da2cd5_ae257d6db3704327960af1635ce3d1e5~mv2.webp/v1/fit/w_924,h_1232,q_90/file.webp", | |
width: 924, | |
height: 1232 | |
}, | |
_id: "da2cd5_ae257d6db3704327960af1635ce3d1e5~mv2.webp" | |
} | |
] | |
}, | |
customTextFields: [], | |
manageVariants: false, | |
productOptions: [], | |
productPageUrl: { | |
base: "https://www.store.damanci.com/", | |
path: "/product-page/test-product-5" | |
}, | |
numericId: "1692281859432000", | |
inventoryItemId: "71cd5690-da93-aaac-ea8d-c553695f9e4e", | |
discount: { | |
type: "NONE", | |
value: 0 | |
}, | |
collectionIds: ["7c4bb3ec-5da2-a719-379b-a133236b6691", "00000000-000000-000000-000000000001"], | |
variants: [ | |
{ | |
_id: "00000000-0000-0000-0000-000000000000", | |
choices: {}, | |
variant: { | |
priceData: { | |
currency: "USD", | |
price: 4, | |
discountedPrice: 4, | |
formatted: { | |
price: "$4.00", | |
discountedPrice: "$4.00" | |
} | |
}, | |
convertedPriceData: { | |
currency: "USD", | |
price: 4, | |
discountedPrice: 4, | |
formatted: { | |
price: "$4.00", | |
discountedPrice: "$4.00" | |
} | |
}, | |
weight: 0, | |
sku: "", | |
visible: true | |
}, | |
stock: { | |
trackQuantity: false, | |
inStock: true | |
} | |
} | |
], | |
lastUpdated: "2023-08-17T14:17:39.925Z", | |
_createdDate: "2023-08-17T14:17:39.432Z", | |
ribbon: "TEST", | |
exportProductId: "product_8e32a96f-256c-5553-1572-3aac96a061b1" | |
}; | |
const bogo_coupon = { | |
id: "1e97946f-87cc-41fa-95bc-3918df907ac9", | |
specification: { | |
name: "TEST_BOGO", | |
code: "TEST_BOGO", | |
startTime: "1692281919088", | |
limitedToOneItem: true, | |
appliesToSubscriptions: false, | |
active: true, | |
scope: { | |
namespace: "stores", | |
group: { | |
name: "product", | |
entityId: "8e32a96f-256c-5553-1572-3aac96a061b1" | |
} | |
}, | |
buyXGetY: { | |
x: 1, | |
y: 1 | |
}, | |
type: "BuyXGetY" | |
}, | |
dateCreated: "1692281949782", | |
displayData: { | |
name: "Test Product #5", | |
mediaItem: { | |
url: "https://static.wixstatic.com/media/da2cd5_ae257d6db3704327960af1635ce3d1e5~mv2.webp/v1/fit/w_924,h_1232,q_90/file.webp", | |
width: 924, | |
height: 1232 | |
}, | |
formattedPrice: "$4.00" | |
} | |
}; | |
async function create_cart_with_coupon() { | |
const create_options: CreateCartOptions = { | |
lineItems: [ | |
{ | |
catalogReference: { | |
appId: WIX_STORES_APP_ID, | |
catalogItemId: test_product._id, | |
options: { | |
options: { | |
Size: "1.7Oz" | |
} | |
} | |
}, | |
quantity: 2 | |
} | |
], | |
couponCode: "TEST_BOGO" | |
}; | |
const create_res = await wixClient.cart.createCart(create_options); | |
console.log(JSON.stringify(create_res, null, 2)); | |
} | |
create_cart_with_coupon(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment