Hi there !
I am trying to find a solution to create a product with variant and I am running into multiple issues.
My plan is to use the productCreate mutation, then productVariantsBulkCreate with a strategy of REMOVE_STANDALONE_VARIANT. I am probably using it wrong but here is the issue I am having :
When I create the product without options/optionsvalues, it creates the default variant
I then want to productVariantsBulkCreate, but the mutation says that I have to first specify the options and values in the product
So I updated the creation of the product by giving the list of options/optionvalues. When I do this, only 1 variant is created in Shopify with the first combination of the first option values I give (why only one ?)
So if I try to productVariantsBulkCreate, it first tells me that the first variant already exists.
Not sure what to do!
I also know about the productSet, but with more than 100 variants, we have to run it async, and as I need to get all the IDs of each variants, productVariantsBulkCreate seems easier.
I do see a few way to do this, but nothing seems perfectly clean. The productCreate + productVariantsBulkCreate seems like a good option for my need but I cannot find a way to make it work.
So I am now trying to use the productSet. The variant structure is something new ⦠the sku is not in InventoryItem, the inventory quantity has its own fields, we cannot set measurement. Is this even done by the same team in Shopify?
How can the experience to create to product can be that bad?
whats wrong with doing productCreate + productVariantsBulkCreate?
I believe the only thing youāre missing is when you do the productCreate you also need to add all of the options so that when you do the productVariantsBulkCreate the options are there to attach to.
I am also need to this so not 100% but that has worked for me when doing a small number of variants.
There is nothing really wrong with it. But when you create the product, we have two choices:
We give the list of optionValues and it will create a first variant with the first set of optionValues, we then have to create all the other variants using productVariantsBulkCreate. This is probably what I am going to do. What I donāt like about it is : why does it create the first variant only (probably because it needs at least one variant)? But why does the REMOVE_STANDALONE_VARIANT exists if we have to send the optionValues anyway (and it create a first variant). + we have to batch operation on our side because productVariantsBulkCreate accepts only 250 variants.
We use the productSet, but the graphql input is completely different. You have the option to set inventory quantities, but it doesnāt set tracked to true in the inventoryItem. So we have to do another mutation after anyway.
I feel like there are multiple pieces of the puzzle and everything doesnāt fit together for now. Eveything is way too complicated for no reason (donāt get me started on how optionValues are handledā¦). There are multiple ways of doing the same things, but none of them is fully complete.
This definitely feels like there are pieces missing.
We use productCreate to create our new product and first variant.
We then track what the first variant options were, and skip that variant when using productVariantsBulkCreate.
The problem with this approach is that the initial variant is missing properties - sku, and inventoryItem properties for example, that we have to go back and update outside of the bulk update (because we canāt ācreateā the initial variant completely unless it is created in the productCreate mutation???).
Removing the variant options from productCreate doesnāt allow any subsequent variants to be created, so it seems that we are stuck with dealing with the initial incomplete variant in some other fashion ā my next step is to try productVariantsBulkUpdate to create the missing properties on the initial variant, then use productVariantsBulkUpdate to create the remaining variantsā¦
One thing that might help is that the productVariantsBulkCreate mutation has a strategy argument which will remove the original product variant for you. This way you can include all the productās variants, including the first one, in the payload of productVariantsBulkCreate.
shopify tells developer to migrate from rest to graphql and promotes an easy way to migrate using ProductSet. Which would be true, if the same fields are support, but we have to same problem: measurements is missing in productset, which makes everything very very complicated and rate limits and many conflicts makes it almost impossible. The failed and wonāt help by just creating those measurements fields in ProductSet call. I am asking this since months. Maybe you have an idea? or how did you fix it?
This is exactly what we had to do. We also have to run inventoryActivate(), as the first variant isnāt automatically associated with our fulfillment.
Create Product using productCreate()
Identify and update initial variant using productVariantsBulkUpdate()
Activate inventory of first variant using inventoryActivate()
Create the additional variants using productVariantsBulkCreate()
Three calls that could have been done in one, potentially.
@Doud how did you manage to make the update calls - when a product changes or one of its variants? (or did you track all variation ids in your system?)
Same problem exactly, Iām having to skip the first variant because REMOVE_STANDALONE_VARIANT only gets rid of the auto-created variant which productCreate makes.
So then I thought, as part of the code that creates variants, Iāll do a quick delete of any variants which have been created by the process of adding the initial options (color and size) to the product.
(I use LEAVE_AS_IS when I add these options to the product, but it always makes a variant anyway. Iām not sure thatās working as intended.)
Problem with that is, when I delete the variant which was auto-created by the initial creation of product optionsā¦it also deletes the options, so all consecutive variant additions fail.
Google tells me that āproductVariantDeleteā exists, which deletes just the variant and not the optionsā¦but no API versions seem to support it, so thatās a non-starter.
All of which leaves me with one variant which doesnāt have any attached media, price, stock etc etc because you canāt get rid of it and let the subsequent productVariantBulkCreate operation create it properly without deleting all product options and thereby breaking everything.
This is deeply, deeply infuriating - both to puzzle out while developing, and also in terms of extra programmatic expense. After Iāve done all-but-one variant, Iām faced with having to do an update of the weird half-created variant in a separate operation.
Shopify devs, please look at the logic of this. Please let us create a product, define the possible options, and then add variants all in sequence rather than these weird workarounds weāre all having to come up with. It just doesnāt make sense!
Hey @dartacus - this appears to be a regression/bug. REMOVE_STANDALONE_VARIANT should behave as youāve anticipated - it should remove the custom or default singleton variant in favor for whatever input you provide. Weāll prioritize a fix and get back to this thread once itās shipped.
As an aside productVariantDelete has been deprecated in favor of productVariantBulkDelete. If you need to delete a single variant, that accepts a single ID.
Hey @dartacus - I actually made a mistake in my original testing where I didnāt LEAVE_AS_IS so I had multiple variants. I wasnāt able to recreate LEAVE_AS_IS creating additional variants.
Could you share with me some example calls and request IDs where youāre seeing this? If you prefer, you can DM me your email address and we can connect over email.