Skip to content

Instantly share code, notes, and snippets.

@wrburgess
Created January 28, 2013 21:41
Show Gist options
  • Save wrburgess/4659348 to your computer and use it in GitHub Desktop.
Save wrburgess/4659348 to your computer and use it in GitHub Desktop.
Spree: Skipping delivery step, but adding back default shipping method and tax calculation

Objective: Skip the delivery step in the Checkout state machine and bring back the ability to add a default shipping method and tax calculation

Approach: Add decorators to the Checkout controller and the Order model (see attached files)

Note: This approach might be better managed by overriding the self.define_state_machine! method of the Checkout model located at app/models/spree/order/checkout.rb. However, this model is rather unstable in the Spree upgrade path and overriding the above classes seems to be simpler to adjust.

# app/models/spree/checkout_controller_decorator.rb
Spree::CheckoutController.class_eval do
def before_payment
current_order.payments.destroy_all if request.put?
@order.create_tax_charge!
@order.shipping_method ||= (@order.rate_hash.first && @order.rate_hash.first[:shipping_method])
@order.create_shipment!
@order.update!
end
end
# app/models/spree/order_decorator.rb
Spree::Order.class_eval do
...
checkout_flow do
go_to_state :address
# go_to_state :delivery <== remove this line
go_to_state :payment, :if => lambda { |order| order.payment_required? }
go_to_state :confirm, :if => lambda { |order| order.confirmation_required? }
go_to_state :complete
remove_transition :from => :delivery, :to => :confirm
end
end
@1990prashant
Copy link

This is not working.

Error shows undefined method rate_hash and first for nil:nil_class.
Will you please a full model and controller code to skip delivery step but adding default shipping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment