Skip to content

Instantly share code, notes, and snippets.

@atomgiant
Created November 20, 2015 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save atomgiant/0025a38e96229e85f270 to your computer and use it in GitHub Desktop.
Save atomgiant/0025a38e96229e85f270 to your computer and use it in GitHub Desktop.
# Takes a product id, and a map of variant ids and quantities
def update_inventory(id, vid_quantities)
variants = vid_quantities.map do |vid, qty|
{ "id" => vid, "inventory_quantity" => qty }
end
data = {
"product" => {
"variants" => variants
}
}
request(:put, "products/#{id}.json", body: data.to_json)
end
update_inventory(1234567, {2222222 => 100, 3333333 => 200})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment