Sha256: aae0c04cfe831c52a7d96110020b19f2e924763d9f195fcfb8a3be4e6e641064

Contents?: true

Size: 690 Bytes

Versions: 1

Compression:

Stored size: 690 Bytes

Contents

class ShopDiscountableCategory < ShopDiscountable
  
  before_validation       :create_shop_products
  before_destroy          :destroy_shop_products
  
  belongs_to :category,   :class_name => 'ShopCategory',  :foreign_key => :discounted_id
  
  # Adds discount to a category's products
  def create_shop_products
    discounted.products.each do |product|
      # Attach discount to the child product
      ShopDiscountable.create(:discount => discount, :discounted => product)
    end
  end
  
  # Removes discount from a category's products
  def destroy_shop_products
    discounted.discountables.for('ShopProduct').each do |discountable|
      discountable.destroy
    end
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
radiant-shop_discounts-extension-0.0.11 app/models/shop_discountable_category.rb