Sha256: 7befd050db919523b7c858aac87b7fde72bcb8e148d1734c42a0e2718412643d

Contents?: true

Size: 793 Bytes

Versions: 3

Compression:

Stored size: 793 Bytes

Contents

class TbCommerce::ProductSkuOption < ActiveRecord::Base
  self.table_name = 'tb_commerce_product_sku_options'

  validates :product_sku, :option, :presence => true

  belongs_to :product_sku, :inverse_of => :product_sku_options, :foreign_key => :tb_commerce_product_sku
  belongs_to :option, :inverse_of => :product_sku_options, :foreign_key => :tb_commerce_option_id

  validate :product_supports_supplied_option

private

  def product_supports_supplied_option
    supported_option_sets = product_sku.product.product_option_sets.collect(&:tb_commerce_option_set_id)
    if !supported_option_sets.include?(option.tb_commerce_option_set_id)
      errors.add(:base, "This product does not support the #{option.option_set.name} option set")
      return false
    end
    return true
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tb_commerce-0.0.4 app/models/tb_commerce/product_sku_option.rb
tb_commerce-0.0.3 app/models/tb_commerce/product_sku_option.rb
tb_commerce-0.0.2 app/models/tb_commerce/product_sku_option.rb