Skip to content

Instantly share code, notes, and snippets.

@IliasHad
Created July 22, 2022 17:20
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 IliasHad/98bae9da0be73bcc392f54f00b4bf718 to your computer and use it in GitHub Desktop.
Save IliasHad/98bae9da0be73bcc392f54f00b4bf718 to your computer and use it in GitHub Desktop.
const products = []; // products Array that will be in Shopify bulk import data after converting it to JSONL and uploading it
const getProductDetails = (product) => {
// using function to get data from somewhere
// we have the data needed to create the product
// the product param will be an object holding the product data
let data = {
media: [],
input: {
title: product.title,
descriptionHtml: product.descriptionHtml,
barcode: product.barcode,
variants: [],
options: [],
handle: product.handle,
tags: product.tags,
published: true, // make published from the first time
},
};
data.variant = product.variants.map((variant, index) => {
data.media.push({
mediaContentType: "IMAGE",
originalSource: variant.publicImageUrl,
});
return {
mediaSrc: [variant.publicImageUrl],
price: variant.price,
compareAtPrice: variant.compareAtPrice,
weight: variant.weight,
sku: variant.sku,
position: index,
};
});
products.push(data);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment