Class: Binda::Shopify::Product

Inherits:
Object
  • Object
show all
Defined in:
lib/binda/shopify/product.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(product, shop) ⇒ Product

Returns a new instance of Product.



5
6
7
8
# File 'lib/binda/shopify/product.rb', line 5

def initialize product, shop
  @product = product
  @shop = shop
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, params = nil, &block) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/binda/shopify/product.rb', line 27

def method_missing name, params = nil, &block
  if product.respond_to? name
    product.send(name, params)
  else
    super
  end
end

Instance Attribute Details

#productObject

Returns the value of attribute product.



4
5
6
# File 'lib/binda/shopify/product.rb', line 4

def product
  @product
end

#shopObject

Returns the value of attribute shop.



4
5
6
# File 'lib/binda/shopify/product.rb', line 4

def shop
  @shop
end

Instance Method Details

#edit_urlObject



23
24
25
# File 'lib/binda/shopify/product.rb', line 23

def edit_url
  "https://#{shop.domain}/admin/products/#{product.id}"
end

#idObject



10
11
12
# File 'lib/binda/shopify/product.rb', line 10

def id
  product.id
end

#inventory_item_idObject



14
15
16
17
18
19
20
21
# File 'lib/binda/shopify/product.rb', line 14

def inventory_item_id
  variant = variants.first
  if variant.respond_to? :inventory_item_id
    variant.inventory_item_id if !variant.nil?
  else
    nil
  end
end