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/f42c90424120378ed51125cc9cd6dc8e to your computer and use it in GitHub Desktop.
Save gmbarroso/f42c90424120378ed51125cc9cd6dc8e to your computer and use it in GitHub Desktop.
javascript: (function () {
if (window.location.href.indexOf("/admin/checkout/#/orders/") > 1) {
const orderId = window.location.hash.split('?')[0].split('/').pop();
console.log("================== get data...");
fetch(`/api/oms/pvt/orders/${orderId}`).then(order => order.json()).then(order => {
console.log("omsOrder", order);
account = order.hostname;
console.log(account);
sc = order.salesChannel;
items = Object.values(order.items).map(value => {
let obj = {
"id": value.id,
"quantity": value.quantity,
"seller": "1"
};
return obj;
});
arrayOfItemsAsStringWithSellersWL = items.map(value => {
let itemParameters = `sku=${value.id}&qty=${value.quantity}&seller=${value.seller}&sc=${sc}`;
return itemParameters;
});
arrayOfItemsAsStringWithRegularSeller = items.map(value => {
let itemParameters = `sku=${value.id}&qty=${value.quantity}&seller=${value.seller}&sc=${sc}`;
return itemParameters;
});
urlWithSellersWL = `https://${account}.myvtex.com/checkout/cart/add/?${arrayOfItemsAsStringWithSellersWL.join("&")}`;
urlWithRegularSeller = `https://${account}.myvtex.com/checkout/cart/add/?${arrayOfItemsAsStringWithRegularSeller.join("&")}`;
console.log("urlWithSellersWL", urlWithSellersWL);
console.log("urlWithRegularSeller", urlWithRegularSeller);
}).catch(error => console.log('omsError', error));
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment