Skip to content

Instantly share code, notes, and snippets.

Created December 9, 2011 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/1453231 to your computer and use it in GitHub Desktop.
Save anonymous/1453231 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
current_order.check_items(search_result.meal_name)
puts 'check_items' + current_order.problems.inspect
redirect_to confirm_order_path
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