Skip to content

Instantly share code, notes, and snippets.

@hardbap
Forked from anonymous/gist:1453231
Created December 9, 2011 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hardbap/1453272 to your computer and use it in GitHub Desktop.
Save hardbap/1453272 to your computer and use it in GitHub Desktop.
def reorder
redirect_to confirm_order_path and return if params[:reorder] == current_order.id.to_s
reorder = current_user.orders.find(params[:reorder])
redirect_to favorites_order_path, :notice => 'The order is no longer available.' and return if reorder.nil?
redirect_to favorites_order_path, :notice => 'There are items in your cart. Please cancel your current order before reordering.' and return if (current_order.items.any?)
search_result = reorder.next_available_delivery
if !search_result.nil?
new_order = reorder.xerox
new_order.save
current_order.destroy
self.current_order = new_order
current_order.status = 'open'
current_order.favorite_order_id = params[:reorder]
current_order.favorite = false
current_order.created_at = DateTime.now
current_order.updated_at = DateTime.now
current_order.mealsoft_response = nil
current_order.error_message = nil
current_order.mealsoft_id = nil
current_order.guest_email = nil
current_order.register_client_message = nil
current_order.delivery_date = Date.today.to_s
current_order.delivery_time = search_result.estimated_delivery
current_order.asap = search_result.asap
current_order.meal = search_result.meal_name
current_order.save
render(:show) and return unless current_order.check_items(search_result.meal_name)
else
redirect_to favorites_order_path, :notice => 'There are no more delivery times available today for this reorder.' and return
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment