Daniel
09/14/2021, 2:27 PMdelivery state and now have the issue, that no shipments are getting created during checkout now. What I would like to do is somehow move the delivery state steps to the cart or address steps without having to duplicate the entire Spree::Core::StateMachines::Order module to avoid future update fiascos. I haven't found an answer by browsing through the guides / code. Is there an easy way to do this?kennyadsl
Edwin Cruz
09/14/2021, 2:33 PM# state machine decorator
after_transition do |order, transition|
Spree::Event.fire "order_#{transition[:new_state}", order
end
then subscribe to those eventskennyadsl
order.next! programmatically so that the user doesn't know that a delivery step happened (the first shipment available will be selected)Daniel
09/15/2021, 7:57 AMDaniel
09/15/2021, 7:59 AMDaniel
09/15/2021, 8:03 AMorder.next! in the console from the address state I still get transitioned to the delivery state, even with the delivery step disabled in the checkout_flow. Is that intended behaviour?Daniel
09/15/2021, 9:38 AMmodule OrderDecorator
def self.prepended(base)
base.state_machine do
after_transition do |order, transition|
Spree::Event.fire "order_transitioned_to_#{<http://transition.to|transition.to>}", order: order
end
end
end
Spree::Order.prepend self
endDaniel
09/15/2021, 9:39 AMorder.next during the order_transitioned_to_delivery event which works fine.Daniel
09/15/2021, 9:42 AMDaniel
09/15/2021, 9:43 AMSpree::CheckoutHelper#checkout_statesDaniel
09/15/2021, 10:05 AMSpree::CheckoutController and add a helper method for checkout_states. But no idea why it doesn't work by just decorating Spree::CheckoutHelper.Daniel
09/15/2021, 10:05 AMmodule CheckoutControllerDecorator
def self.prepended(base)
base.helper_method :checkout_states
end
private
def checkout_states
@order.checkout_steps - ['delivery']
end
Spree::CheckoutController.prepend self
endkennyadsl
Spree::CheckoutHelper is a module and not a class, so it's kinda useless to decorate it. You can just define a new helper in your own application and define a method with the same name into it, it should take precedenceDaniel
09/15/2021, 11:21 AMSpree::ProductsHelper and it works just fine 😅kennyadsl
Daniel
09/15/2021, 1:33 PM