I am using Shopify’s shopify_api
gem in Ruby.
I need to update each products cost and price from an external source.
products = ShopifyAPI::Product.find(:all, :params => {:limit => limit})
products.each do |product|
#product.variants.first.price == price
end
end
Is this the correct way to update a products price?
Do I need to do product.variants.first.save
after I have done product.variants.first.price == price
or is that done automatically?
How can I update the products cost (product.variants.first.cost
doesn’t seem to exist)?
2
Answers
In order to update product variant, I think calling the
save
method is necessaryproduct cost
mentioned isorder
? You should useShopifyAPI::Order
( check this sample and the api )If you need other attribute for product, check out the
metafields
usingShopifyAPI::Metafield
FYI,
Order
hasline_items
property and we also haveShopifyAPI:LineItem
if u find it helpfulI don’t think you can still update product (variant) prices like that. You will likely have to first loop through the product variants, and for each one you get an inventory_item_id. You use that to get the inventory item details. With the inventory item details, you can set the price and cost price, and SKU.
It used to be so much simpler! Another option for you is to use a mutation on the variant, and set prices with the GraphQL API. In either case, you are forced to update using the inventory item attributes and not variant price.