Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added code to make the reorder functionality work correctly #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ This is just a simple extension to add a "Reorder" button to the Orders show vie

To install, just add this to your Gemfile:

gem 'spree_reorder', github: 'onedanshow/spree-reorder', branch: '3-0-stable'
gem 'spree_reorder', github: 'onedanshow/spree-reorder', branch: '3-2-stable'


I'll add more functionality as needed, but this mainly was an experiment to play with writing a Spree extension.
Using the gem written by Daniel Dixon: https://github.com/onedanshow/spree-reorder.

Improved it to work with Spree 3.2.0.rc3, as Spree::OrderPopulator is deprecated and has been removed.

Copyright (c) 2015 Daniel Dixon, released under the New BSD License
Copyright (c) 2017 Abhilash M Kuruo, released under the New BSD License
9 changes: 4 additions & 5 deletions app/controllers/spree/orders_controller_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
Spree::OrdersController.class_eval do
def reorder
populator = Spree::OrderPopulator.new(current_order(create_order_if_necessary: true), current_currency)
current_order(create_order_if_necessary: true)
order = Spree::Order.where( number: params[:id] ).first

if order.line_items.select {|li| populator.populate(li.variant.id, li.quantity) }.any?
respond_with(@order) do |format|
if order.line_items.select{ |li| @current_order.contents.add(li.variant, li.quantity) }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space missing to the left of {.
Line is too long. [91/80]

respond_with(@current_order) do |format|
format.html { redirect_to cart_path }
end
else
flash[:error] = populator.errors.full_messages.join(' '.freeze)
flash[:error] = @current_order.errors.full_messages.join(' '.freeze)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

redirect_to :back
end

end
end
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Spree::Core::Engine.routes.draw do
match '/orders/:id/reorder' => 'orders#reorder', :via => :get, :as => :reorder_order
match '/orders/:id/reorder' => 'orders#reorder', via: :get, as: :reorder_order
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

end
11 changes: 5 additions & 6 deletions spree_reorder.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = 'spree_reorder'
s.version = '3.0.0'
s.version = '3.2.0'
s.summary = 'Simply adds a Reorder button to the Order show view.'
s.description = 'Simply adds a Reorder button to the Order show view.'
s.description = 'Allows user to reorder an existing order from his order listing.'
s.required_ruby_version = '>= 1.9.2'

s.author = 'Daniel Dixon'
s.email = '[email protected]'
s.homepage = 'http://www.danieldixon.com'
s.author = 'Abhilash M Kuruo'
s.email = '[email protected]'

s.require_path = 'lib'
s.requirements << 'none'

s.add_dependency 'spree_frontend', '~> 3.0'
s.add_dependency 'spree_frontend', '~> 3.2.0.rc3'
end