class Prestashop::Mapper::ProductOption

Attributes

group_type[RW]
id[RW]
id_lang[RW]
is_color_group[RW]
name[RW]
position[RW]
public_name[W]

Public Class Methods

cache() click to toggle source
# File lib/prestashop/mapper/models/product_option.rb, line 66
def cache
  all display: '[id,name]'
end
create_from_hash(product_options, id_lang) click to toggle source
# File lib/prestashop/mapper/models/product_option.rb, line 53
def create_from_hash product_options, id_lang
  result = []
  product_options.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 product_options
  result
end
find_in_cache(name, id_lang) click to toggle source
# File lib/prestashop/mapper/models/product_option.rb, line 62
def find_in_cache name, id_lang
  Client.options_cache.find{|k| k[:name].find_lang(name, id_lang) } if Client.options_cache
end
new(args = {}) click to toggle source
# 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

Public Instance Methods

find_or_create() click to toggle source
# 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.clear_options_cache
  end
  option[:id]
end
hash() click to toggle source
# 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
public_name() click to toggle source
# File lib/prestashop/mapper/models/product_option.rb, line 23
def public_name
  @public_name ? @public_name : name
end
validate!() click to toggle source
# 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