Class: Admin::VouchersController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/admin/vouchers_controller.rb

Instance Method Summary collapse

Instance Method Details

#activateObject



4
5
6
# File 'app/controllers/admin/vouchers_controller.rb', line 4

def activate
  render :text => @voucher.activate
end

#createObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'app/controllers/admin/vouchers_controller.rb', line 68

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

  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

#destroyObject



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/controllers/admin/vouchers_controller.rb', line 89

def destroy
  if @voucher.destroy
    flash[:notice] = "Voucher destroy"
  else
    flash[:error] = "Voucher not destroy"
  end
  respond_to do |wants|
    wants.html do
      redirect_to([forgeos_commerce, :admin, :vouchers])
    end
    wants.js
  end
end

#indexObject



8
9
10
11
12
13
14
15
16
# File 'app/controllers/admin/vouchers_controller.rb', line 8

def index
  respond_to do |format|
    format.html
    format.json do
      sort
      render :layout => false
    end
  end
end

#newObject



18
19
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
# File 'app/controllers/admin/vouchers_controller.rb', line 18

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_cart,:scope=>[:special_offer,:_for]), 'Product'],
    [t(:cart,:scope=>[:special_offer,:_for]), 'Cart']
  ]

  @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