5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'app/models/form_discount.rb', line 5
def create
@result ||= { process.to_sym => false }
find_current_order
case process
when 'add'
if @discount = ShopDiscount.find_by_code(discount_code)
@discountable = @discount.discountables.create(:discounted_id => @order.id, :discounted_type => @order.class.name)
@result[process.to_sym] = @discountable.valid?
end
when 'remove'
if @discountable = @order.discountables.find(discountable_id)
@result[process.to_sym] = @discountable.destroy
end
end
@result
end
|