Class: Prestashop::Mapper::ProductOptionValue
- Defined in:
- lib/prestashop/mapper/models/product_option_value.rb
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
-
#id ⇒ Object
Returns the value of attribute id.
-
#id_attribute_group ⇒ Object
Returns the value of attribute id_attribute_group.
-
#id_lang ⇒ Object
Returns the value of attribute id_lang.
-
#name ⇒ Object
Returns the value of attribute name.
-
#position ⇒ Object
Returns the value of attribute position.
Class Method Summary collapse
Instance Method Summary collapse
- #find_or_create ⇒ Object
- #hash ⇒ Object
-
#initialize(args = {}) ⇒ ProductOptionValue
constructor
A new instance of ProductOptionValue.
-
#validate! ⇒ Object
Supplier must have 1/0 as active and name must be string.
Methods inherited from Model
#hash_lang, #meta_description, #meta_keywords, #meta_title, model, resource
Methods included from Extension
Constructor Details
#initialize(args = {}) ⇒ ProductOptionValue
Returns a new instance of ProductOptionValue.
11 12 13 14 15 16 17 18 19 |
# File 'lib/prestashop/mapper/models/product_option_value.rb', line 11 def initialize args = {} @id = args[:id] @id_attribute_group = args.fetch(:id_attribute_group) @color = args.fetch(:color, 0) @position = args[:position] @name = args.fetch(:name) @id_lang = args.fetch(:id_lang) end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
8 9 10 |
# File 'lib/prestashop/mapper/models/product_option_value.rb', line 8 def color @color end |
#id ⇒ Object
Returns the value of attribute id.
8 9 10 |
# File 'lib/prestashop/mapper/models/product_option_value.rb', line 8 def id @id end |
#id_attribute_group ⇒ Object
Returns the value of attribute id_attribute_group.
8 9 10 |
# File 'lib/prestashop/mapper/models/product_option_value.rb', line 8 def id_attribute_group @id_attribute_group end |
#id_lang ⇒ Object
Returns the value of attribute id_lang.
9 10 11 |
# File 'lib/prestashop/mapper/models/product_option_value.rb', line 9 def id_lang @id_lang end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/prestashop/mapper/models/product_option_value.rb', line 8 def name @name end |
#position ⇒ Object
Returns the value of attribute position.
8 9 10 |
# File 'lib/prestashop/mapper/models/product_option_value.rb', line 8 def position @position end |
Class Method Details
.cache ⇒ Object
50 51 52 |
# File 'lib/prestashop/mapper/models/product_option_value.rb', line 50 def cache all display: '[id,id_attribute_group,name]' end |
.find_in_cache(id_attribute_group, name, id_lang) ⇒ Object
46 47 48 |
# File 'lib/prestashop/mapper/models/product_option_value.rb', line 46 def find_in_cache id_attribute_group, name, id_lang Client.option_values_cache.find{|v| v[:id_attribute_group] == id_attribute_group and v[:name].find_lang(name, id_lang)} if Client.option_values_cache end |
Instance Method Details
#find_or_create ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/prestashop/mapper/models/product_option_value.rb', line 28 def find_or_create result = self.class.find_in_cache id_attribute_group, name, id_lang unless result result = create Client.clear_option_values_cache end result[:id] end |
#hash ⇒ Object
21 22 23 24 25 26 |
# File 'lib/prestashop/mapper/models/product_option_value.rb', line 21 def hash validate! { name: hash_lang(name, id_lang), id_attribute_group: id_attribute_group, color: color } end |
#validate! ⇒ Object
Supplier must have 1/0 as active and name must be string
38 39 40 41 42 43 |
# File 'lib/prestashop/mapper/models/product_option_value.rb', line 38 def validate! raise ArgumentError, 'id lang must be number' unless id_lang.kind_of?(Integer) raise ArgumentError, 'name must string' unless name.kind_of?(String) raise ArgumentError, 'id attribute group must be number' unless id_attribute_group.kind_of?(Integer) raise ArgumentError, 'color must be true or false' unless color == 1 or color == 0 end |