Sha256: 2541b1f2a46a441954ddc290c0a92cdd83e2a5b8aff1816a8716343c436160cb

Contents?: true

Size: 594 Bytes

Versions: 2

Compression:

Stored size: 594 Bytes

Contents

class CategoryShopDiscountable < ShopDiscount
  
  before_validation       :create_shop_products
  before_destroy          :destroy_shop_products
  
  # 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

2 entries across 2 versions & 1 rubygems

Version Path
radiant-shop_discounts-extension-0.0.10 app/models/category_shop_discountable.rb
radiant-shop_discounts-extension-0.0.9 app/models/category_shop_discountable.rb