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

Custom order checkout_flow not transitioning #10211

Open
waaux opened this issue Jun 3, 2020 · 3 comments
Open

Custom order checkout_flow not transitioning #10211

waaux opened this issue Jun 3, 2020 · 3 comments

Comments

@waaux
Copy link

waaux commented Jun 3, 2020

Order checkout flow is not transitioning when I have a order decorator file in my app folder.

   # app/models/spree/order_decorator.rb
   Spree::Order.class_eval do
       checkout_flow do
           go_to_state :payment, if: ->(order) { order.payment? || order.payment_required? }
           go_to_state :complete
        end
   end

It only works when I move the order decorator file to lib folder and require the file in initializers folder.

   # lib/models/spree/order_decorator.rb
   Spree::Order.class_eval do
       checkout_flow do
           go_to_state :payment, if: ->(order) { order.payment? || order.payment_required? }
           go_to_state :complete
        end
   end
 
  # config/initializers/spree.rb
  require "#{Rails.root}/lib/models/spree/order_decorator"

Environment

  • Version used: Spree 3.3.6
    *Ruby version: 2.5.3
    *Rails version: 5.1.7

In application.rb

      # config/application.rb
       config.to_prepare do
            # Load application's model / class decorators
           Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
            Rails.configuration.cache_classes ? require(c) : load(c)
           end

           # Load application's view overrides
           Dir.glob(File.join(File.dirname(__FILE__), "../app/overrides/*.rb")) do |c|
            Rails.configuration.cache_classes ? require(c) : load(c)
           end
       end
@waaux
Copy link
Author

waaux commented Jun 4, 2020

This is exactly what is happening to my custom checkout flow.
[Cannot transition state via :next from :cart (Reason(s): State is not included in the list) #7337]

How can I fixed this issue with the state machine?

@waaux
Copy link
Author

waaux commented Jun 4, 2020

When I do this in my order_decorator.rb I can see my custom checkout flow but for some reason the Order always has state = cart. The order never transition.

   # app/models/spree/order_decorator.rb
    Spree::Order.class_eval do
        remove_checkout_step :address
        remove_checkout_step :delivery
        remove_checkout_step :confirm   
    end

Result:

      {
           "id": 279,
           "number": "R542295901",
            "state": "cart",
            "checkout_steps": [
                "payment",
                "complete"
            ]
     }

@jaredcwhite
Copy link

@waaux Thanks for that initial workaround — I was tearing my hair out and I tried your solution and it works! I'm upgrading an old Rails app to Spree 3.6.6 and ran into this issue. So strange that requiring it via a separate file in lib works and inside the main decorator itself it doesn't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants