craftcms / shopify

Synchronize and extend product data from your Shopify storefront.
MIT License
45 stars 25 forks source link

Product inventory out of sync after purchase #61

Closed justenh closed 1 year ago

justenh commented 1 year ago

I've been using this plugin for a custom storefront and learned today that Shopify does not trigger the "products/update" web-hook when an item is purchased, which means that the data Craft has regarding inventory will be out-of-date the moment someone purchase the product. Is there planned support for adding other web-hooks that could trigger product syncs?

This is the particular field in question. $this->getDefaultVariant()['inventory_quantity'];

justenh commented 1 year ago

@lukeholder thanks for moving this into "evaluating". Relatedly, would there be a possibility for us to trigger a product sync via cli to handle these situations?

johndwells commented 1 year ago

Shopify does not trigger the "products/update" web-hook when an item is purchased

@justenh any chance you have a link to documentation that stipulates this? It's so hard to find reputable information that isn't outdated or not relevant for the API.

lukeholder commented 1 year ago

I have gone ahead and added support for updating the product (and variants) when an inventory level is updated.

This will be in the next release.

Please note this will require making sure your API credential key's "Admin API access scopes" includes:

read_product_listings, read_products, read_inventory, write_inventory

After upgrading you will also need to revisit the webhooks page in the shopify plugin CP and click 'create' to make sure the inventory_levels/update event is being listened to on the webhooks.

To get the fix early, change your craftcms/shopify requirement in composer.json to:

"require": {
  "craftcms/shopify": "dev-develop#167a6b36da3acbe0cea971665faa1d5dee619e6e as 3.1.1",
  "...": "..."
}

Then run composer update.

justenh commented 1 year ago

@lukeholder Thanks for the update!

What action is performed where "write_inventory" needs to be granted? Is this part of the incoming update?

lukeholder commented 1 year ago

@justenh apologies that is a error in the docs/readme. It should just be read only for inventory. I will fix shortly.

lukeholder commented 1 year ago

This is now out in 3.2.0!