Class: Admin::SpecialOffersController
- Inherits:
-
BaseController
- Object
- BaseController
- Admin::SpecialOffersController
- Includes:
- Ruleby
- Defined in:
- app/controllers/admin/special_offers_controller.rb
Instance Method Summary collapse
- #activate ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #preview ⇒ Object
- #show ⇒ Object
Instance Method Details
#activate ⇒ Object
6 7 8 |
# File 'app/controllers/admin/special_offers_controller.rb', line 6 def activate render :text => @special_offer.activate end |
#create ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'app/controllers/admin/special_offers_controller.rb', line 73 def create return flash[:error] = 'Fields' unless params[:rule_builder] @main_attributes = %w(price name description weight sku stock product_type_id brand_id) conditions = [] params[:rule][:targets].each_with_index do |rule_target, index| conditions << generate_condition(rule_target, index) end if params[:rule_builder]['for'] == 'Category' conditions << "m.has_category_#{params[:rule_builder][:target]}.==(true)" end matchers = if params[:rule_builder]['for'] == 'Cart' ['Cart',':cart'] else [':is_a?', 'Product',':product'] end generate_rule(matchers, conditions, generate_variables, (params[:rule_builder][:if] == 'Any')) redirect_to :action => 'index' end |
#destroy ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'app/controllers/admin/special_offers_controller.rb', line 98 def destroy if @special_offer.destroy flash[:notice] = t('special_offer.destroy.success') else flash[:error] = t('special_offer.destroy.failed') end respond_to do |wants| wants.html do redirect_to([forgeos_commerce, :admin, :special_offers]) end wants.js end end |
#index ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'app/controllers/admin/special_offers_controller.rb', line 10 def index respond_to do |format| format.html format.json do sort render :layout => false end end end |
#new ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/controllers/admin/special_offers_controller.rb', line 20 def new @default_attributes = %w(price name description weight sku stock product_type_id brand_id).collect do |n| [t(n, :count => 1), n] end @attributes = Attribute.all(:select => 'id, access_method').collect do |a| [a.name, a.access_method] end @cart_attributes = [ [t(:quantity,:scope=>[:special_offer,:cart]),'Total items quantity'], [t(:weight,:scope=>[:special_offer,:cart]), 'Total weight'], [t(:price,:scope=>[:special_offer,:cart]),'Total amount'], [t(:shipping,:scope=>[:special_offer,:cart]),'Shipping method'] ] @disable_attributes = t(:disabled,:scope=>[:special_offer,:attributes]) @for = [ [t(:product_in_shop,:scope=>[:special_offer,:_for]), 'Product'], [t(:product_in_cart,:scope=>[:special_offer,:_for]), 'Product'], [t(:cart,:scope=>[:special_offer,:_for]), 'Cart'] ] @for << [t(:category,:scope=>[:special_offer,:_for]), 'Category'] if ProductCategory.count > 0 @conditions = [ [t(:is,:scope=>[:special_offer,:conditions]), "=="], [t(:is_not,:scope=>[:special_offer,:conditions]),"not=="], [t(:equal_or_greater_than,:scope=>[:special_offer,:conditions]),">="], [t(:equal_or_less_than,:scope=>[:special_offer,:conditions]),"<="], [t(:greater_than,:scope=>[:special_offer,:conditions]), ">"], [t(:less_than,:scope=>[:special_offer,:conditions]),"<"] ] @end = [ [t(:date,:scope=>[:special_offer,:end]),'Date'], [t(:total_use,:scope=>[:special_offer,:end]),'Total number of offer use'], [t(:user_total_use,:scope=>[:special_offer,:end]),'Customer number of offer use'] ] @discount_type = [ [t(:percent,:scope=>[:special_offer,:action]),0], [t(:fixed,:scope=>[:special_offer,:action]),1] ] @product_attributes = [t(:main,:scope=>[:special_offer,:attributes,:disabled])]+ @default_attributes+ [t(:attribute,:scope=>[:special_offer,:attributes,:disabled])]+ @attributes @products = Product.actives(:select => 'products.id, sku', :order => 'sku') end |
#preview ⇒ Object
131 132 |
# File 'app/controllers/admin/special_offers_controller.rb', line 131 def preview end |
#show ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'app/controllers/admin/special_offers_controller.rb', line 112 def show @selected_products = [] = {:page => 1, :per_page => 100, :conditions => {:active => true, :deleted=> false} } pagination = Product.paginate() pagination.total_pages.enum_for(:times).each do |page| [:page] = page+1 engine :special_offer_engine do |e| rule_builder = SpecialOffer.new(e) rule_builder.selected_products = @selected_products rule_builder.rule_preview(@special_offer) Product.paginate().each do |product| e.assert product end e.match end end end |