-
-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Filtering sync based on sales channel #19
Comments
Hey there @dnlmzw! All webhooks will still fire when an update is made regardless of what channel's they're on. If you wanted to check that the product that updated is part of your Headless storefront channel, you'd need to add an additional check in the product sync function. Something like this: // Check if the proudct exists in this sales channel (optional)
const shopifyChannelProduct = await axios({
url: `https://${process.env.SHOPIFY_STORE_ID}.myshopify.com/admin/product_listings/${id}.json`,
method: 'GET',
headers: shopifyConfig,
}) If you were to call that and check that it successfully returns the product you'd know it is part of the headless storefront channel, and can bail from the rest of the sync if it's not! I'd suggest adding this additional check here: https://github.com/ndimatteo/HULL/blob/main/pages/api/shopify/product-update.js#L172 I will note: there's a bit more involved if you wanted to also handle keeping that tracked on subsequent channel changes to previously sync'd products. Simply checking here and bailing won't help if a product was already sync'd and now needs to be essentially "removed" from Sanity. I hope that helps point you in the right direction! |
Thank you so much! I will test it out to see if I can get it to work. |
I ran into an issue when using the @ndimatteo I wanted to share this, so that you could potentially validate: Line 54 in e7f5ec9
When the I suspect this might be a general issue, since I was able to fix it by adding Line 339 in e7f5ec9
So that the line becomes: I haven't tested out cases where Shopify deletes products, which is why I'm not sure if this is a general issue, or only me who is experiencing this, but wanted to let you know regardless as I thought you might easily weed out if this was a general flaw. @ndimatteo Let me know if you want me to add a seperate ticket for this (or alternatively create a PR) |
Closing this issue, but keeping it pinned for those who need this feature 🤘 |
@dnlmzw good catch with this, I'll add that additional check to the GROQ function to account for this, will have that pushed in an update later this week! |
this check doesnt seem to prevent a product from syncing any help would bemuch appreciated. On my dev store it did behave as expected but on a different live shopify it seems to do nothing. `console.log('Checking for previous sync data...') // Setup our Shopify connection // Check if the product exists in the channel
} // Check Channel found // No changes found |
Hey there @highsandlows! I'm not sure I follow, but if you're wanting to block a product from sync'ing into Sanity based on if the The code you pasted is unformated and not really helpful in debugging your issue, but if it's working on one store account and not another, that should tell you that the issue is likely elsewhere with the implementation on the store that it's not working on. If you have more details to share let me know, happy to take a look! |
Apologies @ndimatteo , My question relates to your example below and how to log it/check it is recognising the sales channel.
I have added some additional logs like below Version: $LATEST
2021-12-17T08:15:34.001Z INFO Sync triggered for product: GARMENT-DYED HEAVYWEIGHT SHORT - BLACK (id: 7075701293233)
2021-12-17T08:15:34.012Z INFO Checking for previous sync data...
2021-12-17T08:15:34.266Z INFO Checking sales channel sync data... 7075701293233
2021-12-17T08:15:34.266Z INFO Product is here continue to sync.
2021-12-17T08:15:34.441Z INFO Previous sync found, comparing differences...
2021-12-17T08:15:34.443Z INFO No differences found, sync complete!
END Request
Would the following work? // Check if the product exists in the channel
const shopifyChannelProduct = await axios({
url: `https://${process.env.SHOPIFY_STORE_ID}.myshopify.com/admin/product_listings/${id}.json`,
method: 'GET',
headers: shopifyConfig,
}).catch(
function (error) {
console.info('This Product is not in the sales channel for this app!', error)
return res
}
)
console.log('Checking sales channel sync data...', id)
// Check Channel found
if (!shopifyChannelProduct) {
console.warn('NOT HERE')
return res
// No changes found
} else {
console.info('Product is here continue to sync.')
} Apologies for the bad formatting before was trying to post on the phone app :/ |
No problem at all @highsandlows, thanks for elaborating! So the issue is two-fold:
When a product isn't part of a sales channel, {
"errors": "Not Found"
} And when it is part of a sales channel, it returns something like this: {
"product_listing": {
"product_id": 1111111,
// other product fields....
}
} You'll need to use this data to do your check. I hope that makes more sense, let me know if you have more questions! |
I have a need to only sync products from Shopify that have been checked off in the "Sales channels" for my headless storefront. At the moment, it is currently being ignored.
The text was updated successfully, but these errors were encountered: