Class: BBMB::Html::State::CurrentOrder

Inherits:
Global
  • Object
show all
Defined in:
lib/bbmb/html/state/current_order.rb

Constant Summary collapse

DIRECT_EVENT =
:current_order
VIEW =
View::CurrentOrder

Instance Method Summary collapse

Methods inherited from Global

#direct_argument_keys, #direct_arguments, #direct_request?, #initialize, #logout, mandatory, #requested_event, #trigger, #user_input

Constructor Details

This class inherits a constructor from BBMB::Html::State::Global

Instance Method Details

#ajaxObject



23
24
25
26
27
28
29
30
# File 'lib/bbmb/html/state/current_order.rb', line 23

def ajax
  do_update
  data = {}
  [ :reference, :comment, :priority, :total ].each { |key|
    data.store key, @model.send(key).to_s
  }
  State::Json.new(@session, data)
end

#commitObject



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
# File 'lib/bbmb/html/state/current_order.rb', line 31

def commit
  ## update most recent values and ensure @model = _customer.current_order
  do_update
  if @session.lookandfeel.enabled?(:terms_of_service, false)
    if @session.user_input(:accept_terms)
      _customer.terms_last_accepted ||= Time.now
    else
      @errors.store :terms_accepted,
                    create_error(:e_terms_of_service, :terms_accepted, nil)
      _customer.terms_last_accepted = nil
    end
    BBMB.persistence.save(_customer)
  end
  unless error?
    _customer.commit_order!
    order = @model
    SBSM.info("committing #{_customer.customer_id} #{order.order_id} #{caller[0..10].join("\n")}")
    @session.async {
      @session.app.send_order order, _customer
    }
    @model = _customer.current_order
    Info.new(@session, :message => :order_sent,
             :event => :current_order)
  end
end

#do_updateObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/bbmb/html/state/current_order.rb', line 56

def do_update
  if BBMB.config.mail_confirm_reply_to
    _customer.order_confirmation = @session.user_input(:order_confirmation)
    BBMB.persistence.save(_customer)
  end
  @model = _customer.current_order
  keys = [ :comment, :priority, :reference ]
  input = user_input(keys)
  unless(error?)
    input.each { |key, value|
      @model.send("#{key}=", value)
    }
    case @model.priority
    when 40
      @model.shipping = 80
    when 41
      @model.shipping = 50
    else
      @model.shipping = 0
    end
    BBMB.persistence.save(@model)
  end
end

#initObject



19
20
21
22
# File 'lib/bbmb/html/state/current_order.rb', line 19

def init
  @model = _customer.current_order
  @model.calculate_effective_prices
end