Sha256: db878b225da71322809ac620b19eb77deb946be96ea3910617d00f0695321567

Contents?: true

Size: 834 Bytes

Versions: 10

Compression:

Stored size: 834 Bytes

Contents

class FormDiscount
  include Forms::Models::Extension
  include Shop::Models::FormExtension
  
  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
  
  protected
  
  def process
    @config[:process]
  end
  
  def discount_code
    @data[:discount][:code]
  end
  
  def discountable_id
    @data[:discountable][:id]
  end
  
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
radiant-shop_discounts-extension-0.0.11 app/models/form_discount.rb
radiant-shop_discounts-extension-0.0.10 app/models/form_discount.rb
radiant-shop_discounts-extension-0.0.9 app/models/form_discount.rb
radiant-shop_discounts-extension-0.0.8 app/models/form_discount.rb
radiant-shop_discounts-extension-0.0.7 app/models/form_discount.rb
radiant-shop_discounts-extension-0.0.6 app/models/form_discount.rb
radiant-shop_discounts-extension-0.0.4 app/models/form_discount.rb
radiant-shop_discounts-extension-0.0.3 app/models/form_discount.rb
radiant-shop_discounts-extension-0.0.1 app/models/form_discount.rb
radiant-shop-extension-0.11.6 app/models/form_discount.rb