Class: Prestashop::Mapper::StockAvailable

Inherits:
Model
  • Object
show all
Defined in:
lib/prestashop/mapper/models/stock_available.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#hash_lang, #meta_description, #meta_keywords, #meta_title, model, resource

Methods included from Extension

included

Constructor Details

#initialize(args = {}) ⇒ StockAvailable

Returns a new instance of StockAvailable


10
11
12
13
14
15
16
17
18
19
# File 'lib/prestashop/mapper/models/stock_available.rb', line 10

def initialize args = {}
  @id                   = args[:id]
  @id_product           = args[:id_product]
  @id_product_attribute = args.fetch(:id_product_attribute, 0)
  @id_shop              = args.fetch(:id_shop, 1)
  @id_shop_group        = args.fetch(:id_shop_group, 0)
  @quantity             = args.fetch(:quantity, 0)
  @depends_on_stock     = args.fetch(:depends_on_stock, 0)
  @out_of_stock         = args.fetch(:out_of_stock, 2)
end

Instance Attribute Details

#depends_on_stockObject

Returns the value of attribute depends_on_stock


8
9
10
# File 'lib/prestashop/mapper/models/stock_available.rb', line 8

def depends_on_stock
  @depends_on_stock
end

#id_productObject

Returns the value of attribute id_product


8
9
10
# File 'lib/prestashop/mapper/models/stock_available.rb', line 8

def id_product
  @id_product
end

#id_product_attributeObject

Returns the value of attribute id_product_attribute


8
9
10
# File 'lib/prestashop/mapper/models/stock_available.rb', line 8

def id_product_attribute
  @id_product_attribute
end

#id_shopObject

Returns the value of attribute id_shop


8
9
10
# File 'lib/prestashop/mapper/models/stock_available.rb', line 8

def id_shop
  @id_shop
end

#id_shop_groupObject

Returns the value of attribute id_shop_group


8
9
10
# File 'lib/prestashop/mapper/models/stock_available.rb', line 8

def id_shop_group
  @id_shop_group
end

#out_of_stockObject

Returns the value of attribute out_of_stock


8
9
10
# File 'lib/prestashop/mapper/models/stock_available.rb', line 8

def out_of_stock
  @out_of_stock
end

#quantityObject

Returns the value of attribute quantity


8
9
10
# File 'lib/prestashop/mapper/models/stock_available.rb', line 8

def quantity
  @quantity
end

Instance Method Details

#idObject Also known as: find?


21
22
23
24
25
26
27
# File 'lib/prestashop/mapper/models/stock_available.rb', line 21

def id
  @id ||= if id_product_attribute == 0
    self.class.find_by 'filter[id_product]' => id_product
  else
    self.class.find_by 'filter[id_product]' => id_product, 'filter[id_product_attribute]' => id_product_attribute
  end
end

#update(options = {}) ⇒ Object


30
31
32
# File 'lib/prestashop/mapper/models/stock_available.rb', line 30

def update options = {}
  self.class.update(id, options) if find?
end