Class: TbCommerce::ProductSku

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/tb_commerce/product_sku.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.with_option_ids(option_ids_list) ⇒ Object

Return SKU records that support the provided list of option IDs

  • option_ids_list: Array of integer values corresponding to TbCommcerce::Option



29
30
31
32
33
# File 'app/models/tb_commerce/product_sku.rb', line 29

def self.with_option_ids(option_ids_list)
  return includes(:options).to_a.select do |sku|
    sku.has_options?(option_ids_list)
  end
end

Instance Method Details

#descriptionObject



17
18
19
# File 'app/models/tb_commerce/product_sku.rb', line 17

def description
  return product.title
end

#has_options?(option_ids_list) ⇒ Boolean

Return true if the current record supports the supplied list of option IDs

  • option_ids_list: Array of integer values corresponding to TbCommcerce::Option

Returns:

  • (Boolean)


39
40
41
42
43
44
45
46
# File 'app/models/tb_commerce/product_sku.rb', line 39

def has_options?(option_ids_list)
  option_ids_list.each do |option_id|
    if !self.option_ids.include?(option_id)
      return false
    end
  end
  return true
end

#priceObject



21
22
23
# File 'app/models/tb_commerce/product_sku.rb', line 21

def price
  return product.price + add_price
end