Class: Prestashop::Mapper::ProductOption
- Defined in:
- lib/prestashop/mapper/models/product_option.rb
Instance Attribute Summary collapse
-
#group_type ⇒ Object
Returns the value of attribute group_type.
-
#id ⇒ Object
Returns the value of attribute id.
-
#id_lang ⇒ Object
Returns the value of attribute id_lang.
-
#is_color_group ⇒ Object
Returns the value of attribute is_color_group.
-
#name ⇒ Object
Returns the value of attribute name.
-
#position ⇒ Object
Returns the value of attribute position.
- #public_name ⇒ Object
Class Method Summary collapse
- .cache ⇒ Object
- .create_from_hash(product_options, id_lang) ⇒ Object
- .find_in_cache(name, id_lang) ⇒ Object
Instance Method Summary collapse
- #find_or_create ⇒ Object
- #hash ⇒ Object
-
#initialize(args = {}) ⇒ ProductOption
constructor
A new instance of ProductOption.
- #validate! ⇒ Object
Methods inherited from Model
#hash_lang, #meta_description, #meta_keywords, #meta_title, model, resource
Methods included from Extension
Constructor Details
#initialize(args = {}) ⇒ ProductOption
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/prestashop/mapper/models/product_option.rb', line 12 def initialize args = {} @id = args[:id] @is_color_group = args.fetch(:is_color_group, 0) @group_type = args.fetch(:group_type, 'select') @position = args[:position] @name = args.fetch(:name) @public_name = args[:public_name] @id_lang = args.fetch(:id_lang) end |
Instance Attribute Details
#group_type ⇒ Object
Returns the value of attribute group_type.
8 9 10 |
# File 'lib/prestashop/mapper/models/product_option.rb', line 8 def group_type @group_type end |
#id ⇒ Object
Returns the value of attribute id.
8 9 10 |
# File 'lib/prestashop/mapper/models/product_option.rb', line 8 def id @id end |
#id_lang ⇒ Object
Returns the value of attribute id_lang.
10 11 12 |
# File 'lib/prestashop/mapper/models/product_option.rb', line 10 def id_lang @id_lang end |
#is_color_group ⇒ Object
Returns the value of attribute is_color_group.
8 9 10 |
# File 'lib/prestashop/mapper/models/product_option.rb', line 8 def is_color_group @is_color_group end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/prestashop/mapper/models/product_option.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.rb', line 8 def position @position end |
#public_name ⇒ Object
23 24 25 |
# File 'lib/prestashop/mapper/models/product_option.rb', line 23 def public_name @public_name ? @public_name : name end |
Class Method Details
.cache ⇒ Object
66 67 68 |
# File 'lib/prestashop/mapper/models/product_option.rb', line 66 def cache all display: '[id,name]' end |
.create_from_hash(product_options, id_lang) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/prestashop/mapper/models/product_option.rb', line 53 def create_from_hash , id_lang result = [] .each do |product_option| id_o = ProductOption.new(name: product_option[:name], id_lang: id_lang).find_or_create result << ProductOptionValue.new(name: product_option[:value], id_attribute_group: id_o, id_lang: id_lang).find_or_create end if result end |
.find_in_cache(name, id_lang) ⇒ Object
62 63 64 |
# File 'lib/prestashop/mapper/models/product_option.rb', line 62 def find_in_cache name, id_lang Client..find{|k| k[:name].find_lang(name, id_lang) } if Client. end |
Instance Method Details
#find_or_create ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/prestashop/mapper/models/product_option.rb', line 37 def find_or_create option = self.class.find_in_cache name, id_lang unless option option = create Client. end option[:id] end |
#hash ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/prestashop/mapper/models/product_option.rb', line 27 def hash validate! { is_color_group: is_color_group, position: position, group_type: group_type, name: hash_lang(name, id_lang), public_name: hash_lang(public_name, id_lang) } end |
#validate! ⇒ Object
46 47 48 49 50 |
# File 'lib/prestashop/mapper/models/product_option.rb', line 46 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, 'group_type must string' unless group_type.kind_of?(String) end |