Open vitaliy-bobrov opened 4 months ago
Hi @vitaliy-bobrov, the problem is that the variants
prop is optional. This is because fetching all the variants for a given product can be slow (that's why product options exists). The goal of the code currently is if there is no variant, just assume it's available. Perhaps it could be better and first check if the variants
property is defined at all, instead of just the searched for variant
.
At the same time, the SFAPI is going to be changing to better allow thousands of product variants, while also providing product availability. This component will be updated once those SFAPI changes are available.
@blittle thanks for the quick reply! Now, I understand why it is implemented that way. Maybe it would be worth adding a comment in the code, as it looks like a mistake at first glance, and it is unclear why it defaults to true
.
Will the SFAPI update be during the upcoming editions? Could the issue remain open until VariantSelector gets update?
It's something multiple teams are working on, though I don't have an exact ETA. I'm happy to leave this open until we update the component.
This came up again with more details in this issue: https://github.com/Shopify/hydrogen/issues/2353
What is the location of your example repository?
No response
Which package or tool is having this issue?
Hydrogen
What version of that package or tool are you using?
2024.4.2
What version of Remix are you using?
No response
Steps to Reproduce
If Product have some missed variants due to availability, ex. T-Shirt with "Color: Green" is not available in "Size: XS", and such variant wasn't added in Shopify admin. In this case VariantSelector will return
isAvailable: true
for that variant.The problem is in the line of
VariantSelector.ts
, line 114 (v 2024.4.2):isAvailable: variant ? variant.availableForSale! : true,
if variant is not listed in available variants, it should be marked as not available:
isAvailable: variant ? variant.availableForSale! : false,
I'm using a workaround currently to add missed variants with
availableForSale: false
, but it's quite big amount of code to check for missing variants among all possible combinations. The use-case is for Printful and Shopify integration, as Printful manages available product variants on their side, so you can't manage them in Shopify admin. Printful doesn't allow to add variants that are not available on their side.Expected Behavior
VariantSelector returns
isAvailable: false
for missed variantsActual Behavior
VariantSelector returns
isAvailable: true
for missed variants