Class: Spree::Api::V2::Storefront::CartController
Instance Method Summary
collapse
#check_coupon_codes, #select_coupon_codes, #select_error, #select_errors
#content_type
Instance Method Details
#add_item ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'app/controllers/spree/api/v2/storefront/cart_controller.rb', line 33
def add_item
spree_authorize! :update, spree_current_order, order_token
spree_authorize! :show, @variant
result = add_item_service.call(
order: spree_current_order,
variant: @variant,
quantity: add_item_params[:quantity],
public_metadata: add_item_params[:public_metadata],
private_metadata: add_item_params[:private_metadata],
options: add_item_params[:options]
)
render_order(result)
end
|
#apply_coupon_code ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'app/controllers/spree/api/v2/storefront/cart_controller.rb', line 100
def apply_coupon_code
spree_authorize! :update, spree_current_order, order_token
spree_current_order.coupon_code = params[:coupon_code]
result = coupon_handler.new(spree_current_order).apply
if result.error.blank?
render_serialized_payload { serialized_current_order }
else
render_error_payload(result.error)
end
end
|
#associate ⇒ Object
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
# File 'app/controllers/spree/api/v2/storefront/cart_controller.rb', line 141
def associate
guest_order_token = params[:guest_order_token]
guest_order = ::Spree::Api::Dependencies.storefront_current_order_finder.constantize.new.execute(
store: current_store,
user: nil,
token: guest_order_token,
currency: current_currency
)
spree_authorize! :update, guest_order, guest_order_token
result = associate_service.call(guest_order: guest_order, user: spree_current_user)
if result.success?
render_serialized_payload { serialize_resource(guest_order) }
else
render_error_payload(result.error)
end
end
|
#change_currency ⇒ Object
161
162
163
164
165
166
167
|
# File 'app/controllers/spree/api/v2/storefront/cart_controller.rb', line 161
def change_currency
spree_authorize! :update, spree_current_order, order_token
result = change_currency_service.call(order: spree_current_order, new_currency: params[:new_currency])
render_order(result)
end
|
#create ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'app/controllers/spree/api/v2/storefront/cart_controller.rb', line 16
def create
spree_authorize! :create, Spree::Order
create_cart_params = {
user: spree_current_user,
store: current_store,
currency: current_currency,
public_metadata: add_item_params[:public_metadata],
private_metadata: add_item_params[:private_metadata],
}
order = spree_current_order if spree_current_order.present?
order ||= create_service.call(create_cart_params).value
render_serialized_payload(201) { serialize_resource(order) }
end
|
#destroy ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
|
# File 'app/controllers/spree/api/v2/storefront/cart_controller.rb', line 72
def destroy
spree_authorize! :update, spree_current_order, order_token
result = destroy_cart_service.call(order: spree_current_order)
if result.success?
head 204
else
render_error_payload(result.error)
end
end
|
#empty ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
|
# File 'app/controllers/spree/api/v2/storefront/cart_controller.rb', line 60
def empty
spree_authorize! :update, spree_current_order, order_token
result = empty_cart_service.call(order: spree_current_order)
if result.success?
render_serialized_payload { serialized_current_order }
else
render_error_payload(result.error)
end
end
|
#estimate_shipping_rates ⇒ Object
129
130
131
132
133
134
135
136
137
138
139
|
# File 'app/controllers/spree/api/v2/storefront/cart_controller.rb', line 129
def estimate_shipping_rates
spree_authorize! :show, spree_current_order, order_token
result = estimate_shipping_rates_service.call(order: spree_current_order, country_iso: params[:country_iso])
if result.error.blank?
render_serialized_payload { serialize_estimated_shipping_rates(result.value) }
else
render_error_payload(result.error)
end
end
|
#remove_coupon_code ⇒ Object
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'app/controllers/spree/api/v2/storefront/cart_controller.rb', line 113
def remove_coupon_code
spree_authorize! :update, spree_current_order, order_token
coupon_codes = select_coupon_codes
return render_error_payload(I18n.t('spree.api.v2.cart.no_coupon_code')) if coupon_codes.empty?
result_errors = coupon_codes.count > 1 ? select_errors(coupon_codes) : select_error(coupon_codes)
if result_errors.blank?
render_serialized_payload { serialized_current_order }
else
render_error_payload(result_errors)
end
end
|
#remove_line_item ⇒ Object
49
50
51
52
53
54
55
56
57
58
|
# File 'app/controllers/spree/api/v2/storefront/cart_controller.rb', line 49
def remove_line_item
spree_authorize! :update, spree_current_order, order_token
remove_line_item_service.call(
order: spree_current_order,
line_item: line_item
)
render_serialized_payload { serialized_current_order }
end
|
#set_quantity ⇒ Object
84
85
86
87
88
89
90
91
92
|
# File 'app/controllers/spree/api/v2/storefront/cart_controller.rb', line 84
def set_quantity
return render_error_item_quantity unless params[:quantity].to_i > 0
spree_authorize! :update, spree_current_order, order_token
result = set_item_quantity_service.call(order: spree_current_order, line_item: line_item, quantity: params[:quantity])
render_order(result)
end
|
#show ⇒ Object
94
95
96
97
98
|
# File 'app/controllers/spree/api/v2/storefront/cart_controller.rb', line 94
def show
spree_authorize! :show, spree_current_order, order_token
render_serialized_payload { serialized_current_order }
end
|