Class: ShopDiscountableCategory
- Inherits:
-
ShopDiscountable
- Object
- ActiveRecord::Base
- ShopDiscountable
- ShopDiscountableCategory
- Defined in:
- app/models/shop_discountable_category.rb
Instance Method Summary collapse
-
#create_shop_products ⇒ Object
Adds discount to a category’s products.
-
#destroy_shop_products ⇒ Object
Removes discount from a category’s products.
Methods inherited from ShopDiscountable
Instance Method Details
#create_shop_products ⇒ Object
Adds discount to a category’s products
9 10 11 12 13 14 |
# File 'app/models/shop_discountable_category.rb', line 9 def create_shop_products discounted.products.each do |product| # Attach discount to the child product ShopDiscountable.create(:discount => discount, :discounted => product) end end |
#destroy_shop_products ⇒ Object
Removes discount from a category’s products
17 18 19 20 21 |
# File 'app/models/shop_discountable_category.rb', line 17 def destroy_shop_products discounted.discountables.for('ShopProduct').each do |discountable| discountable.destroy end end |