Issue
I'm really new to the Shopify API, and I'm working with someone else's code. I'm uploading a product trough my Shopify store, but I want to set some sort of policy where a product can't be sold when it's out of stock, is there a way this can be done on code?
Every time I create a product on Shopify, I do it like this:
static async createProductInShopify(product) {
const createProductsURL = SHOPIFY_URL + '/products.json';
const latestPrice = product.prices[product.prices.length - 1];
const requestBody = {
product: {
title: product.name,
body_html: product.body,
vendor: 'My Store',
product_type: 'Sample Product',
handle: product.handle,
tags: product.categories,
images: [
{
src: product.imageURL
}
],
variants: [
{
option1: product.size ? 'Big' : 'Normal',
price: latestPrice,
requires_shipping: true,
taxable: false,
inventory_quantity: product.quantity,
inventory_management: 'shopify',
inventory_policy: 'continue'
}
]
}
};
const response = await ShopifyController.fetch(createProductsURL, requestBody, 'POST', product);
const shopifyJSON = await response.json();
product.productID = `${shopifyJSON.product.id}`;
product.productVariantID = `${shopifyJSON.product.variants[0].id}`;
product.inventoryLevelID = `${shopifyJSON.product.variants[0].inventory_item_id}`;
await product.save();
return product;
}
I assume that the inventory_policy
is where that flag can be set, however, I need some confirmation to see if that is true.
Solution
yes, the inventory_policy for product variant has to be set to something. i am sharing the screenshot for the value.
Answered By - Lakshay Kalra Answer Checked By - Mary Flores (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.