Good day. Please tell me, as an observer, add a parameter with the ID of the last order to the end of the url of the success page, that is, instead of

... / checkout / onepage / success /

It was

... / checkout / onepage / success / order_id = 10000000001

observer code in config.xml

.... <events> <controller_front_init_routers> <observers> <dk_images> <!-- <type>singleton</type> --> <class>DK_Images_Controller_Router</class> <method>initControllerRouters</method> </dk_images> </observers> </controller_front_init_routers> </events> </global> 

controller

 <?php class DK_Images_Controller_Router extends Mage_Core_Controller_Varien_Router_Abstract { public function initControllerRouters($observer) { $front = $observer->getEvent()->getFront(); $front->addRouter('checkout/onepage', $this); return $this; } public function match(Zend_Controller_Request_Http $request) { if (!Mage::isInstalled()) { Mage::app()->getFrontController()->getResponse() ->setRedirect(Mage::getUrl('install')) ->sendResponse(); exit; } $urlKey = Mage::helper('core/url')->getCurrentUrl();//trim($request->getPathInfo(), '/'); $parts = explode('/', $urlKey); if (count($parts) < 3) { return false; } if ($parts[5] == 'onepage' && $parts[6] == 'success') { $lastOrderId = Mage::getSingleton('checkout/session') ->getLastRealOrderId(); $request->setModuleName('checkout') ->setControllerName('onepage') ->setActionName('success') ->setParam('id', $lastOrderId); $request->setAlias( Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS, $urlKey ); return true; } return false; } } 

But this code, unfortunately, does not work. I would be very grateful for the help.

  • why do you need this and the last order at all, or the user? - Naumov

1 answer 1

Yes, the question is why here by the way, maybe if it will be clear why there will be new solutions to the problem?

As an option, create a template in which the order ID will be received and push it as an URL parameter via js, well, we simply add our template to the before_body_end or something like the one where it will work out and change the URL in order to review it.

This is if you only need to change the URL, and not just to get to him the user, for this it is easier to rewrite the controller.