Changing the checkout flow in spree-0.10.2
I n开发者_开发知识库eed a checkout process devoid of a delivery and payment step (working on a store which accept cash on delivery so I need only the address step.) I am using Spree 0.10.2
Things I have tried:
In the site_extension.rb
added the following state machine
Checkout.state_machines[:state] = StateMachine::Machine.new(Checkout, :initial => 'address') do
after_transition :to => 'complete', :do => :complete_order
before_transition :to => 'complete', :do => :process_payment
event :next do
transition :to => 'complete', :from => 'address'
end
end
The unwanted steps are removed (at least visually) but when I submit the address it throws up the following error.
IndexError in CheckoutsController#update "payment" is an invalid name
Looking at the trace and couple of similar errors later, I decide to blindly override two methods from checkouts_controller.rb in site_extension.rb to do nothing (since they deal with payment I presume)
def clear_payments_if_in_payment_state
end
def object_params
end
Doing this throws validation errors on all the fields of delivery and billing address. I vaguely have a notion that I need to override a couple of methods from checkouts_controller.rb. If this notion is right then what are those methods.
You need to :
1) Remove the paymenttransition and delivery state transition step.
2) Also overriding the payment_required method .
3) These steps need to be in order_decorator.rb under app/models/spree directory.
checkout_flow do
go_to_state :address
# go_to_state :payment
go_to_state :complete
remove_transition :from => :delivery, :to => :confirm
remove_transition :from => :delivery, :to => :confirm
remove_transition :from => :payment, :to => :confirm
end
#Spree::Order.state_machine.before_transition :to => :payment, :do => :set_order
def set_order
self.create_proposed_shipments
end
def require_email
return false
end
def payment_required?
false
end
I have tested this on spree 2-0-stable with rails 3.2.14.
Sorry, I can't really help you: Customizing the checkout process with Spree 0.10.2 is kind of a nightmare.
But I would recommend to switch to a more recent version of Spree, like the 1.3-stable.
If you switched to that one, it would be as easy as creating an order_decorator.rb
file in your_app_folder/app/models/spree
with the following code:
Spree::Order.class_eval do
remove_checkout_step :delivery
remove_checkout_step :payment
end
精彩评论