Augusto
Augusto

Reputation: 1150

Unable to add product to a custom collection

Using the shopify gem I'm trying to add a product to a custom collection.

c = ShopifyAPI::CustomCollection.first(:title => "Man")
p = ShopifyAPI::Product.find(95448374)

If I try:

c.products << p
c.save
=> true

But the product is not added to the custom collection.

I also tried

p.collections << c
p.save
=> true

But still the product is not added to the collection...why?

Any help is greatly appreciated!

Augusto

Upvotes: 1

Views: 189

Answers (1)

John Duff
John Duff

Reputation: 38598

Your answer lies in the source:

https://github.com/Shopify/shopify_api/blob/master/lib/shopify_api/resources/product.rb#L30

You have to use the add_to_collection or add_product methods because these create a Collect object, which is what we use to associate a product and collection.

Upvotes: 1

Related Questions