Repository navigation
Sanity-Shopify Sync Rewrite with Metafields
The Sanity webhook has been extended to diffmatch against itself. This is a pattern I am implementing to resolve an issue with inventory/hourly incremental syncs from Shopify.
The new function now converts various elements of the Shopify product to an object to diff match (including: title, handle, variants, images). You can easily extend this for your own needs and potentially include metafields etc. From there the function checks if a meta field exists on your product that I have key valued to not conflict with any of your possible metafields. If no metafield exists it will update Sanity as well as create the metafield on the Product you are updating.
Future updates will Diffmatch the json object of the saved metafield and the current instance of the product during the webhook sync. This should ideally prevent excessive Sanity hits/updates and also prevent your site rebuilds from being triggered if you are using Netlify.