Reputation: 726
I am facing a problem - can not update the price of the variant using the ShopifyAPI..
while updating the price of the variant, it is giving the error
@remote_errors=#<\ActiveResource::ResourceInvalid: Failed. Response code = 422. Response message = Unprocessable Entity.>, @validation_context=nil, @errors=#<\ActiveResource::Errors:0x000000029eb1d0 ...>>, @messages={:base=>["Options are not unique"]}
'\' after '<' is required to show the error, otherwise stack overflow is hiding the error.
as required on another question
on production store, the request id is "38f5c3b3b7bdf4433724a845c6df4571"
on test store, the request id is "6050f165586b631e81b840dc0e1e6807"
variant price change on test store
p = ShopifyAPI::Product.last
v = p.variants.first
v.price = "8.00"
v.save
initial price of variant = "9.00"
returns false, with error @messages={:base=>["Options are not unique"]}
request id 978ad18483f40ff3946df18df0a9d1d8
.
.
variant price change on live store
p = ShopifyAPI::Product.first
p.variants[0].price = "24.65"
p.save
initial price of variant = "25.65"
return true, but price is not changed
request id a9a798b631e3dd10fc81b723f2883af1
.
.
variant price change through product on test store
p = ShopifyAPI::Product.first
p.variants[0].price = "8.00"
p.save
initial price of variant = "7.00"
return true and price is updated
request id 7d995f6f6ed3bf515e69a1640f27f44a
.
.
variant price change through product on live store
p = ShopifyAPI::Product.last
v = p.variants.first
v.price = "4.00"
v.save
initial price of variant = "3.00"
returns false, with error @messages={:base=>["Options are not unique"]}
request id c6aaa5b65576eb4ec0d89715d25b787e
Upvotes: 2
Views: 1645
Reputation: 1522
This is a bug in ActiveResource 3.1+.
I have opened an ActiveResource pull request, but I am still awaiting a response at the moment.
I have committed a workaround for this bug in shopify_api v3.0.1, so upgrading this gem will fix this issue for you issue.
Upvotes: 0
Reputation: 4966
@messages={:base=>["Options are not unique"]}
That's your problem. Looking at the logs you're using POST
to submit the request, which is used for creating new objects. Shopify is recognizing that there's already a variant with the specified options and refusing to create a new one.
If you use PUT
as your HTTP method instead, Shopify will correctly interpret this as an update and everything should be fine.
Upvotes: 3