Closed RobinShineDezign closed 5 months ago
There is already an open issue asking for this value to be added to the resource picker response: https://github.com/Shopify/shopify-app-bridge/issues/235
Same issue, but for now you can deduce the total number of variants based on the product options.
Since the variants is all the combinations of product options you can use the following snippet to get the total number of variants:
const numberOfVariants = selected.options.reduce(
(acc, option) => acc * option.values.length,
1
);
@Stef733 That's a good way as a workaround.
@RobinShineDezign @ryanrphillips: I think the long term approach for ResourcePicker is that it should return just selected ids. Apps need to perform extra graphql call to get what they need because each app wants different information.
I close this issue for now 🙇
I think the long term approach for ResourcePicker is that it should return just selected ids. Apps need to perform extra graphql call to get what they need because each app wants different information.
It would be nice to have the ability to specify the return fields rather than making an extra request.
@henrytao-me After further testing it is apparent that the solution provided by @Stef733 will only work if all option combinations are valid variants.
For example, I have a product with 7 Flavours & 2 Sizes. Using the reduce method brings the total number of possible variants to 14 (7 * 2).
The problem arises when some of the flavours are only available in one size rather than both. In my case I only have a total number of 10 variants available because 7 flavours are available at 1kg, but only 4 flavours are available at 1.5kg, meaning that to get the correct number of variants I still need to perform an extra request.
I see.
It would be nice to have the ability to specify the return fields rather than making an extra request.
I will cycle back to the team.
@henrytao-me hey any chance we could have this issue reopened?
totalVariants
is returned in the payload now. Note that:
cc @meandillar @RobinShineDezign @Stef733 @ryanrphillips
@henrytao-me Much appreciated, that works great!
Describe the bug
When using the Resource Picker with the "Product" resource a total_variants field is needed to determine whether all variants have been selected or a subset. Currently there is no way to find this out from the resource picker response, other than by making an additional request after making a selection.
Packages and versions
List the relevant packages you’re using, and their versions. For example:
We are using latest version: