Giter VIP home page Giter VIP logo

Comments (9)

dnlmzw avatar dnlmzw commented on May 16, 2024 1

Thank you so much! I will test it out to see if I can get it to work.

from hull.

dnlmzw avatar dnlmzw commented on May 16, 2024 1

I ran into an issue when using the wasDeleted flag on products. I believe it might impact others as well, even if they're not trying to achieve what I'm doing in the issue above.

@ndimatteo I wanted to share this, so that you could potentially validate:

const { site, page } = data

When the wasDeleted flag is set to true the page is null, which breaks static site generation on Vercel.

I suspect this might be a general issue, since I was able to fix it by adding && wasDeleted != true to the @lib/api.js here:

HULL/lib/api.js

Line 339 in e7f5ec9

`*[_type == "${doc}"]{ "slug": slug.current }`

So that the line becomes: *[_type == "${doc}" && wasDeleted != true]{ "slug": slug.current }

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)

from hull.

ndimatteo avatar ndimatteo commented on May 16, 2024

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!

from hull.

ndimatteo avatar ndimatteo commented on May 16, 2024

Closing this issue, but keeping it pinned for those who need this feature 🤘

from hull.

ndimatteo avatar ndimatteo commented on May 16, 2024

I ran into an issue when using the wasDeleted flag on products. I believe it might impact others as well, even if they're not trying to achieve what I'm doing in the issue above.

@ndimatteo I wanted to share this, so that you could potentially validate:

const { site, page } = data

When the wasDeleted flag is set to true the page is null, which breaks static site generation on Vercel.

I suspect this might be a general issue, since I was able to fix it by adding && wasDeleted != true to the @lib/api.js here:

HULL/lib/api.js

Line 339 in e7f5ec9

`*[_type == "${doc}"]{ "slug": slug.current }`

So that the line becomes: *[_type == "${doc}" && wasDeleted != true]{ "slug": slug.current }

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)

@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!

from hull.

s1nny0ur avatar s1nny0ur commented on May 16, 2024

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
const shopifyConfig = {
'Content-Type': 'application/json',
'X-Shopify-Access-Token': process.env.SHOPIFY_API_PASSWORD,
}

// 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.')
`

from hull.

ndimatteo avatar ndimatteo commented on May 16, 2024

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 headless sales channel is checked or not, the check outlined here should work: #19 (comment)

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!

from hull.

s1nny0ur avatar s1nny0ur commented on May 16, 2024

Apologies @ndimatteo , My question relates to your example below and how to log it/check it is recognising the sales channel.

// 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 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 :/

from hull.

ndimatteo avatar ndimatteo commented on May 16, 2024

No problem at all @highsandlows, thanks for elaborating!

So the issue is two-fold:

  1. Your catch() only gets hit if an exception is thrown. If the product wasn't part of the sales channel Shopify doesn't throw an exception, it returns data if it can't find the product (still resulting in a successful GET fetch)
  2. Your if/else check is only checking for the existence of shopifyChannelProduct which isn't enough. Much like above, even when the product isn't part of the sales channel, Shopify still returns data.

When a product isn't part of a sales channel, shopifyChannelProduct will return this:

{
    "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!

from hull.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.