问题
Is there an observer in Magento to detect the start of the checkout process? This would include hitting the page checkout/onepage/
or checkout/onestepcheckout/
. I would like to avoid overriding controllers if possible.
回答1:
Every controller action will result in multiple targeted events which are fired in Mage_Core_Controller_Varien_Action (link), the superclass for all action controllers. These events variously involve the "full action name," derived from module router configuration + controller path + action, as well as the route name which is being requested.
In the case of standard onepage checkout, the full action name is checkout_onepage_index
and the route name is checkout_onepage
.
renderLayout():
controller_action_layout_render_before_'.$this->getFullActionName()
preDispatch():
controller_action_predispatch_' . $this->getRequest()->getRouteName()
controller_action_predispatch_' . $this->getFullActionName()
postDispatch():
controller_action_postdispatch_' . $this->getRequest()->getRouteName()
controller_action_postdispatch_' . $this->getFullActionName()
Which events you observe will depend on how the OneStepCheckout module captures routes. The getRouteName()
-based events may be useful if you need to distinguish between routes and modules. You'll want to test "customer is logged in" and "customer is logged out" scenarios. While the predispatch events are preferred for logic which involves a redirect, you'll want to balance your needs against duplicating cart/quote + customer session logic.
回答2:
Take a look @ controller_action_predispatch_checkout_onepage_index
event
See 'Proceed to Checkout' Event for Magento?
回答3:
Why do you want to do it that late? Depending on what you are checking, you might do it after adding them to the cart? checkout_cart_save_before
来源:https://stackoverflow.com/questions/14652497/observer-for-checkout-start