Module: ShopifyAPI::Metafields

Included in:
Article, Blog, CustomCollection, Customer, DraftOrder, Order, Page, Product, SmartCollection, Variant
Defined in:
lib/shopify_api/metafields.rb

Instance Method Summary collapse

Instance Method Details

#add_metafield(metafield) ⇒ Object

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
18
# File 'lib/shopify_api/metafields.rb', line 9

def add_metafield(metafield)
  raise ArgumentError, "You can only add metafields to resource that has been saved" if new?

  metafield.prefix_options = {
    :resource => self.class.collection_name,
    :resource_id => id
  }
  metafield.save
  metafield
end

#metafields(**options) ⇒ Object



3
4
5
6
7
# File 'lib/shopify_api/metafields.rb', line 3

def metafields(**options)
  options.merge! resource: self.class.collection_name, resource_id: id

  Metafield.find :all, params: options
end