Reputation: 83
I am working on my RoR4 app with the Solidus gem included. When I tried to override its frontend's checkout_controller#update method (located here).
I override the controller according to Spree's documents, but it gave me an error of uninitialized constant OrderUpdateAttributes
.
CheckoutController#update
named as /app/controllers/spree/checkout_controller_decorator.rb
Spree::CheckoutController.class_eval do
def update
if OrderUpdateAttributes.new(@order, update_params, request_env: request.headers.env).apply
@order.temporary_address = !params[:save_user_address]
success = if @order.state == 'confirm'
@order.complete
else
@order.next
end
if !success
flash[:error] = @order.errors.full_messages.join("\n")
redirect_to(checkout_state_path(@order.state)) && return
end
if @order.completed?
@current_order = nil
flash.notice = Spree.t(:order_processed_successfully)
flash['order_completed'] = true
redirect_to completion_route
else
redirect_to checkout_state_path(@order.state)
end
else
render :edit
end
end
I needed to override this method in order to execute some action after an order is completed (after its checkout). Is there something I am missing to cause this error? Or another way to execute the action?
Upvotes: 1
Views: 1342
Reputation: 83
I figured the best way to handle this situation is to use the state machine at the model level. For this action, more documentation can be found here, and more precisely to use the decorator to override on the core's order
model, located on core/app/models/spree/order.rb
.
Upvotes: 1