laravel-shopify
laravel-shopify copied to clipboard
Updating Inventory Quantity Without Creating Inventory Level and Location
Hello Signifly Support,
I trust this message finds you well. I've recently integrated the Signifly/Shopify app, and while most functionalities are working smoothly, I'm facing a challenge regarding inventory management.
Specifically, I need guidance on updating inventory quantities without the need to create a new inventory level and location. It seems that the current process involves these steps, but I'm wondering if there's a more direct method or if this feature will be considered in future updates.
I'm not part of the Signifly support, but I've worked on inventory changes recently. This can be done using the adjustInventoryLevel
function. You'll need
- some specific information about the product variant that you're updating
- the Shopify id of the location where you're updating the inventory
- the stock adjustment
Note that you can't just set the inventory level, Shopify simply doesn't allow it. You have to adjust it. So for example
// the Shopify ID for the location
$locationId = 1321312312;
// whatever you want the stock level to be
$desiredStock = 100;
// get the variant resource data, using the variant's Shopify ID
$variantResource = $this->shopify->getVariant(12313232);
$variantAttributes = $variantResource->getAttributes();
// get the current inventory level in Shopify
$inventoryQuantity = $variantAttributes["inventory_quantity"];
// calculate the adjustment required
$stockAdjustment = $desiredStock - $inventoryQuantity;
$this->shopify->adjustInventoryLevel($variantAttributes["inventory_item_id"], $locationId, $stockAdjustment);
If you're just adjusting it (e.g. adding 20), you can simplify that a bit and just set the (e.g. 20) to the last parameter. If you're reducing stock, just pass the negative value to adjust by.
Hope that helps.
@BrandonKerr Thanks