Class: ShopDiscountableCategory

Inherits:
ShopDiscountable show all
Defined in:
app/models/shop_discountable_category.rb

Instance Method Summary collapse

Methods inherited from ShopDiscountable

for

Instance Method Details

#create_shop_productsObject

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_productsObject

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