Class: Prestashop::Mapper::ProductFeatureValue

Inherits:
Model
  • Object
show all
Defined in:
lib/prestashop/mapper/models/product_feature_value.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 = {}) ⇒ ProductFeatureValue

Returns a new instance of ProductFeatureValue.


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

def initialize args = {}
  @id         = args[:id]
  @id_feature = args.fetch(:id_feature)
  @custom     = args.fetch(:custom, 0)
  @value      = args.fetch(:value)

  @id_lang    = args.fetch(:id_lang)
end

Instance Attribute Details

#customObject

Returns the value of attribute custom


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

def custom
  @custom
end

#idObject

Returns the value of attribute id


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

def id
  @id
end

#id_featureObject

Returns the value of attribute id_feature


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

def id_feature
  @id_feature
end

#id_langObject

Returns the value of attribute id_lang


10
11
12
# File 'lib/prestashop/mapper/models/product_feature_value.rb', line 10

def id_lang
  @id_lang
end

#valueObject


21
22
23
# File 'lib/prestashop/mapper/models/product_feature_value.rb', line 21

def value
  @value.plain
end

Class Method Details

.cacheObject


54
55
56
# File 'lib/prestashop/mapper/models/product_feature_value.rb', line 54

def cache
  all display: '[id,id_feature,value]'
end

.find_in_cache(id_feature, value, id_lang) ⇒ Object


50
51
52
# File 'lib/prestashop/mapper/models/product_feature_value.rb', line 50

def find_in_cache id_feature, value, id_lang
  Client.feature_values_cache.find{|v| v[:id_feature] == id_feature and v[:value].find_lang(value, id_lang)} if Client.feature_values_cache
end

Instance Method Details

#find_or_createObject


33
34
35
36
37
38
39
40
# File 'lib/prestashop/mapper/models/product_feature_value.rb', line 33

def find_or_create
  result = self.class.find_in_cache id_feature, value, id_lang
  unless result
    result = create
    Client.clear_feature_values_cache
  end
  result[:id]
end

#hashObject


25
26
27
28
29
30
31
# File 'lib/prestashop/mapper/models/product_feature_value.rb', line 25

def hash
  validate!

  { id_feature: id_feature,
    custom:     custom,
    value:      hash_lang(value, id_lang) }
end

#validate!Object

Raises:

  • (ArgumentError)

42
43
44
45
46
47
# File 'lib/prestashop/mapper/models/product_feature_value.rb', line 42

def validate!
  raise ArgumentError, 'id lang must be number' unless id_lang.kind_of?(Integer)
  raise ArgumentError, 'id feature must string' unless id_feature.kind_of?(Integer)
  raise ArgumentError, 'custom must be 0 or 1' unless custom == 0 or custom == 1
  raise ArgumentError, 'value must string' unless value.kind_of?(String)
end