Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override Spree checkout forms and step flows?

I'm using spree 2.0.0 in my application. I just want to know how i can edit spree checkout or how I can completely remove / disable any "Step" during Spree checkout process.

Any thoughts on this?

like image 785
Muhammad Ateq Ejaz Avatar asked Nov 29 '22 12:11

Muhammad Ateq Ejaz


2 Answers

As Documentation says, you can use remove_checkout_step helper method (which is also much clearer than redefining whole checkout process), for example:

Spree::Order.class_eval do
  # ...
  remove_checkout_step :delivery
  # ...
end
like image 113
Marek Lipka Avatar answered Dec 06 '22 23:12

Marek Lipka


I just found the solution. Here it is.

Step 1:Create app/models/order_decorator.rb file

Step 2: Copy following code in your order_decorator.rb 

Spree::Order.class_eval do
  checkout_flow do
    go_to_state :address
    #go_to_state :delivery
    go_to_state :payment, if: ->(order) {
      order.update_totals
      order.payment_required?
    }
    go_to_state :confirm, if: ->(order) { order.confirmation_required? }
    go_to_state :complete, if: ->(order) {
      (order.payment_required? && order.has_unprocessed_payments?) || !order.payment_required?
    }
    remove_transition from: :delivery, to: :confirm
  end
end

Example: if you want to remove delivery state just comment it out.You can comment out any step.

You can find more info in the documentation.

like image 31
Muhammad Ateq Ejaz Avatar answered Dec 07 '22 01:12

Muhammad Ateq Ejaz