Skip to content

Instantly share code, notes, and snippets.

@gmbarroso
Created November 18, 2021 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmbarroso/cb96317868a41d81f30bc42786f7ab17 to your computer and use it in GitHub Desktop.
Save gmbarroso/cb96317868a41d81f30bc42786f7ab17 to your computer and use it in GitHub Desktop.
const orderJSON = require('./order.json');
let arrayOfItems = []
let arrayOfItemsAsString = []
let url = ""
const sc = orderJSON.content.salesChannel
const account = orderJSON.content.items[0].catalogProvider.split(":")
const items = Object.values(orderJSON.content.items).map(value => value.id)
arrayOfItems = items.map(value => {
let obj = {
"id": value,
"quantity": 1,
"seller": "1"
}
return obj
})
arrayOfItemsAsString = arrayOfItems.map(value => {
let itemParameters = `sku=${value.id}&qty=${value.quantity}&seller=${value.seller}&sc=${sc}`
return itemParameters
})
url = `https://${account[3]}.myvtex.com/checkout/cart/add/?${arrayOfItemsAsString.join("&")}`
console.log(url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment