Class: Prestashop::Mapper::Combination

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

Instance Attribute Summary collapse

Class Method 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 = {}) ⇒ Combination

Returns a new instance of Combination.


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/prestashop/mapper/models/combination.rb', line 12

def initialize args = {}
  @id                 = args[:id]
  @id_product         = args.fetch(:id_product)
  @location           = args[:location]
  @ean13              = args[:ean]
  @upc                = args[:upc]
  @quantity           = args.fetch(:quantity, 0)
  @reference          = args.fetch(:reference)
  @supplier_reference = args[:supplier_reference]
  @wholesale_price    = args[:wholesale_price]
  @price              = args[:price]
  @ecotax             = args[:ecotax]
  @weight             = args[:weight]
  @unit_price_impact  = args[:unit_price_impact]
  @minimal_quantity   = args.fetch(:minimal_quantity, 1)
  @default_on         = args.fetch(:default_on, 0)
  @available_date     = Date.today.strftime("%F")

  @id_product_options = args[:id_product_options]
  @id_images          = args[:id_images]

  @id_lang            = args.fetch(:id_lang)
end

Instance Attribute Details

#available_dateObject

Returns the value of attribute available_date


9
10
11
# File 'lib/prestashop/mapper/models/combination.rb', line 9

def available_date
  @available_date
end

#default_onObject

Returns the value of attribute default_on


9
10
11
# File 'lib/prestashop/mapper/models/combination.rb', line 9

def default_on
  @default_on
end

#ean13Object

Returns the value of attribute ean13


9
10
11
# File 'lib/prestashop/mapper/models/combination.rb', line 9

def ean13
  @ean13
end

#ecotaxObject

Returns the value of attribute ecotax


9
10
11
# File 'lib/prestashop/mapper/models/combination.rb', line 9

def ecotax
  @ecotax
end

#idObject Also known as: find?

ID of combination, or find ID by reference and id_product


37
38
39
# File 'lib/prestashop/mapper/models/combination.rb', line 37

def id
  @id
end

#id_imagesObject

Returns the value of attribute id_images


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

def id_images
  @id_images
end

#id_langObject

Returns the value of attribute id_lang


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

def id_lang
  @id_lang
end

#id_productObject

Returns the value of attribute id_product


9
10
11
# File 'lib/prestashop/mapper/models/combination.rb', line 9

def id_product
  @id_product
end

#id_product_optionsObject

Returns the value of attribute id_product_options


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

def id_product_options
  @id_product_options
end

#locationObject

Returns the value of attribute location


9
10
11
# File 'lib/prestashop/mapper/models/combination.rb', line 9

def location
  @location
end

#minimal_quantityObject

Returns the value of attribute minimal_quantity


9
10
11
# File 'lib/prestashop/mapper/models/combination.rb', line 9

def minimal_quantity
  @minimal_quantity
end

#priceObject

Returns the value of attribute price


9
10
11
# File 'lib/prestashop/mapper/models/combination.rb', line 9

def price
  @price
end

#quantityObject

Returns the value of attribute quantity


9
10
11
# File 'lib/prestashop/mapper/models/combination.rb', line 9

def quantity
  @quantity
end

#referenceObject

Returns the value of attribute reference


9
10
11
# File 'lib/prestashop/mapper/models/combination.rb', line 9

def reference
  @reference
end

#supplier_referenceObject

Returns the value of attribute supplier_reference


9
10
11
# File 'lib/prestashop/mapper/models/combination.rb', line 9

def supplier_reference
  @supplier_reference
end

#unit_price_impactObject

Returns the value of attribute unit_price_impact


9
10
11
# File 'lib/prestashop/mapper/models/combination.rb', line 9

def unit_price_impact
  @unit_price_impact
end

#upcObject

Returns the value of attribute upc


9
10
11
# File 'lib/prestashop/mapper/models/combination.rb', line 9

def upc
  @upc
end

#weightObject

Returns the value of attribute weight


9
10
11
# File 'lib/prestashop/mapper/models/combination.rb', line 9

def weight
  @weight
end

#wholesale_priceObject

Returns the value of attribute wholesale_price


9
10
11
# File 'lib/prestashop/mapper/models/combination.rb', line 9

def wholesale_price
  @wholesale_price
end

Class Method Details

.deactivate(supplier) ⇒ Object


70
71
72
73
74
75
76
77
# File 'lib/prestashop/mapper/models/combination.rb', line 70

def deactivate supplier
  first = (Date.today-365).strftime("%F")
  last = (Date.today-1).strftime("%F")
  combinations = where 'filter[date_upd]' => "[#{first},#{last}]", date: 1, 'filter[supplier_reference]' => supplier, limit: 1000
  if combinations and !combinations.empty?
    combinations.map{|c| delete(c)}
  end
end

Instance Method Details

#hashObject


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/prestashop/mapper/models/combination.rb', line 42

def hash
  combination = {
    id_product:         id_product,
    reference:          reference,
    supplier_reference: supplier_reference,
    minimal_quantity:   minimal_quantity,
    default_on:         default_on,
    available_date:     available_date,
    price:              price,
    quantity:           quantity,
    associations: {}
  }
  if id_product_options
    combination[:associations][:product_option_values] = {}
    combination[:associations][:product_option_values][:product_option_value] = hash_ids(id_product_options)
  end
  if id_images
    combination[:associations][:images] = {}
    combination[:associations][:images][:image] = hash_ids(id_images)
  end
  combination
end

#update(options = {}) ⇒ Object


65
66
67
# File 'lib/prestashop/mapper/models/combination.rb', line 65

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