I'm getting started with the shopify api ruby gem and just about to create products atm, but I'm already stuck at something very basic ... being that I can't create a (none-variant) product if I want to send my price and inventory data along.
If I'm correct, a product without variants actually has a 'Default Title' variant with the sku, price, inventory etc. But I can't figure out the correct way to do this ... This is what I have now:
new_product = ShopifyAPI::Product.new
new_product.title = "Burton Custom Freestlye 151"
new_product.product_type = "Snowboard"
new_product.vendor = "Burton"
new_product.published = "false"
new_product.variants << ShopifyAPI::Variant.new(
:option1 => "Default Title",
:price => 12.95,
:inventory_management => "shopify",
:inventory_quantity => 10
Been able to solve it this way:
variant = new_product.variants variant.price = $price variant.sku = $sku variant.weight = $g variant.weight_unit = "g" variant.inventory_quantity = $qty variant.inventory_management = "shopify" new_product.save
I guess – correct me if I'm wrong – this does work because the default variant is already existing, hence I have to access it (
variant), whereas in my question code I was trying to create a new one.