Error occurs while saving variant values to shopify

1,692 views
Skip to first unread message

Sonal

unread,
Sep 14, 2011, 10:16:35 AM9/14/11
to shopi...@googlegroups.com
hi guys,

I have a few queries regarding the application that I am developing. 
I am trying to update the Variant Values to shopify. but I am not able to update all values at a time. Currently I update single value after saving I can update the another value. when I tried to update multiple Variant Value at a time, I got the error that " Options are not unique". These are the values which I am trying to update. I have three colours:

Black
Purple
Blue
Red

After updating 

Black
Blue
Red
White
Means I changed the position of Blue and Red and changed other colours also.

When I tried to save it I got the following error:
           HTTP/1.1 422 Unprocessable Entity 
         <?xml version="1.0" encoding="UTF-8"?>
          <errors>
                  <error>Options are not unique</error>
           </errors>

I have attached the request xml file.

Can any one solve my problem?

Is there any way to update whole variant value at a time?

Thanks
Sonal



ErrorWhileSavingVariantValueRequest.xml

John Duff

unread,
Sep 14, 2011, 10:47:36 AM9/14/11
to shopi...@googlegroups.com
This error occurs when you try and set variant options to be the same
as an existing variant. Options on a variant must be unique, so you
can't have two variants with the exact same options. I'm guessing this
product already has a variant with the options you're trying to add.

John Duff
Developer @ Shopify

Sonal

unread,
Sep 15, 2011, 2:04:11 AM9/15/11
to shopi...@googlegroups.com
Hi John,

Thanks for your quick reply.
I know that Options must be unique. but if I want to update the all options value at the same time, and also change the position of existing value.
So How it would be possible?

Thanks
Sonal

Robert Banh

unread,
Dec 27, 2011, 8:32:06 AM12/27/11
to shopi...@googlegroups.com
John, is there a response to this? I'm running into the same race condition... unless I can update all variants at once.


Dave

unread,
Dec 27, 2011, 9:22:45 AM12/27/11
to shopify-api
Why not just update them one at a time. Solves your problem.

Robert Banh

unread,
Dec 27, 2011, 10:43:52 AM12/27/11
to shopi...@googlegroups.com
That's the problem... if you update one at a time, then you'll get a race condition... shopify will return "options are not unique" when you update one variant value that already exist in another.

1. User creates a product with 2 variants... size SMALL (variant #1) and LARGE (variant #2).
2. User updates product from size SMALL to LARGE (variant #1), and size LARGE to X-LARGE (variant #2).
This will fail b/c of a race condition where two variants will be size LARGE... shopify error "Options are not unique".

Dave

unread,
Dec 27, 2011, 11:35:30 AM12/27/11
to shopify-api
Go cheap and dirty then...

You know the object you want, all that is standing in the way are
existing Variants... so just kill 'em all, create your shiny new ones
and be done with it. Not exactly algorithmically pleasant, but that is
the reality of clunky API based computing. You do not need a doctorate
to see that fighting for computing efficiency is a losing cause. Any
API that moves the luxury closer to the end-user, probably incurs a
lot more complexity internal to their codebase, so they opt-out. You
get that in this issue of course. I see it all the time...

Ever examined some of the Liquid theme code floating around in front-
end shops. If you ever want to see some of the craziest nested looping
comparison structures, that world is your oyster. Trillions of CPU
cycles mercilessly slaughtered all in the name of easy-peasy
frictionless templating. But in the end, it kinda works...

Just revert to the old bubble sort when you have to, in other words.

Robert Banh

unread,
Dec 27, 2011, 11:43:27 AM12/27/11
to shopi...@googlegroups.com
Ha! That's exactly the solution I coded in the first rev... kill all old variants and create new ones.

Sadly we're working with vendors who can't have variant IDs changing constantly since tracking them will be a nightmare. But thanks for the bubble sort idea.

John, let me know if you have an answer to this... or anyone from shopify.

Chris Saunders

unread,
Jan 19, 2012, 3:29:23 PM1/19/12
to shopify-api
Hey,

Are you looking to simply move the variants around so that if your
variant options are out of order you can fix them?

You are given a position variable for each variant which may be better
than trying to simply rename variants (which I *think* is just
renaming each variants option).

So instead what you could do is just re-order the variants based on
position.

For example: https://gist.github.com/1642383

Unfortunately this requires n calls to the API, but I think it will
solve the problem you are having.

--
Chris // Developer @ Shopify
Reply all
Reply to author
Forward
0 new messages