Class: Spree::Admin::Orders::BillingAddressController
Instance Method Summary
collapse
#add_breadcrumb_icon_instance_var
Instance Method Details
#create ⇒ Object
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
|
# File 'app/controllers/spree/admin/orders/billing_address_controller.rb', line 18
def create
if params[:billing_address_type] == 'same_as_shipping'
@order.clone_shipping_address
elsif params[:billing_address_id].present?
@address = Spree::Address.accessible_by(current_ability, :manage).find_by_prefix_id!(params[:billing_address_id])
@order.bill_address_id = @address.id
else
@order.bill_address_attributes = address_params
@address = @order.bill_address
end
if @order.save
if !@order.completed? && @order.line_items.any?
max_state = if @order.ship_address.present?
@order.ensure_updated_shipments
'payment'
else
'address'
end
advance_to_payment_result = Spree.checkout_advance_service.call(order: @order, state: max_state)
unless advance_to_payment_result.success?
flash[:error] = advance_to_payment_result.error.value.full_messages.to_sentence
@order.ensure_updated_shipments
return redirect_to spree.edit_admin_order_path(@order)
end
end
flash[:success] = Spree.t(:successfully_created, resource: Spree.t(:billing_address))
redirect_to spree.edit_admin_order_path(@order)
else
render :create, status: :unprocessable_content
end
end
|
#edit ⇒ Object
55
56
57
|
# File 'app/controllers/spree/admin/orders/billing_address_controller.rb', line 55
def edit
@address = @order.bill_address
end
|
#new ⇒ Object
9
10
11
12
13
14
15
16
|
# File 'app/controllers/spree/admin/orders/billing_address_controller.rb', line 9
def new
@address = @order.build_bill_address
if @order.user.present?
@address.first_name = @order.user.first_name
@address.last_name = @order.user.last_name
@address.phone = @order.user.phone
end
end
|
#update ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'app/controllers/spree/admin/orders/billing_address_controller.rb', line 59
def update
if params[:billing_address_type] == 'same_as_shipping'
@order.clone_shipping_address
elsif params[:billing_address_id].present?
@address = Spree::Address.accessible_by(current_ability, :manage).find_by_prefix_id!(params[:billing_address_id])
@order.bill_address_id = @address.id
else
@order.bill_address_attributes = address_params
@address = @order.bill_address
end
if @order.save
if !@order.completed? && @order.line_items.any?
max_state = if @order.ship_address.present?
@order.ensure_updated_shipments
'payment'
else
'address'
end
advance_to_payment_result = Spree.checkout_advance_service.call(order: @order, state: max_state)
unless advance_to_payment_result.success?
flash[:error] = advance_to_payment_result.error.value.full_messages.to_sentence
@order.ensure_updated_shipments
return redirect_to spree.edit_admin_order_path(@order)
end
end
flash[:success] = Spree.t(:successfully_updated, resource: Spree.t(:billing_address))
redirect_to spree.edit_admin_order_path(@order)
else
render :update, status: :unprocessable_content
end
end
|