23 Jan Spree: Set the current_order value with the order you want
If you want to set the current_order with the order we want(maybe an order created previously) just follow the steps bellow:
Search the order you want to use as a current_order in the console for instance:
order = Spree::Order.find 12345679
Set the user_id as a nil in the order that we are using above this is necessary to allow spree do the user assigment to that order.
order.user_id = nil order.save!
The current_order internally have some logic to select which is the last created order so we need to update the created_at field
order.created_at = Time.now order.save!
Put a binding.pry or a debugger in the controller to stop the program execution of our store in my case i’m using the orders_controller in the method edit and I’m visiting the url /cart and when we are in that part we need to set the following session variable.
session[:order_id] = order.id
And now remove the binding.pry or debugger from that method and let spree assign the order we want as a current_order
No Comments