segment-boneyard / analytics-magento

[DEPRECATED] The hassle-free way to integrate analytics into any Magento store.
15 stars 19 forks source link

Observer on order place causes background process not to run #87

Open jaredkipe opened 8 years ago

jaredkipe commented 8 years ago

If you have a process that creates orders on a cron or otherwise background process, your Observer::orderPlaced() method can throw an exception preventing the order from actually being placed.

 [Tue Jun 14 10:00:35 2016] [hphp] [1:7fd90a2a4440:0:000003] [] exception 'Mage_Core_Exception' with message 'No session id. Blocking rather than instantiate object early.' in /var/www/app/Mage.php:595
Jun 14 10:00:35 coreos1 docker[45146]: Stack trace:
Jun 14 10:00:35 coreos1 docker[45146]: #0 /var/www/app/code/community/Segment/Analytics/Model/Session.php(8): Mage::throwException()
Jun 14 10:00:35 coreos1 docker[45146]: #1 /var/www/app/code/core/Mage/Core/Model/Config.php(1357): Segment_Analytics_Model_Session->__construct()
Jun 14 10:00:35 coreos1 docker[45146]: #2 /var/www/app/Mage.php(463): Mage_Core_Model_Config->getModelInstance()
Jun 14 10:00:35 coreos1 docker[45146]: #3 /var/www/app/Mage.php(477): Mage::getModel()
Jun 14 10:00:35 coreos1 docker[45146]: #4 /var/www/app/code/community/Segment/Analytics/Model/Front/Controller.php(57): Mage::getSingleton()
Jun 14 10:00:35 coreos1 docker[45146]: #5 /var/www/app/code/community/Segment/Analytics/Model/Front/Controller.php(29): Segment_Analytics_Model_Front_Controller->_getSession()
Jun 14 10:00:35 coreos1 docker[45146]: #6 /var/www/app/code/community/Segment/Analytics/Model/Observer.php(256): Segment_Analytics_Model_Front_Controller->addDeferredAction()
Jun 14 10:00:35 coreos1 docker[45146]: #7 /var/www/app/code/core/Mage/Core/Model/App.php(1358): Segment_Analytics_Model_Observer->orderPlaced()
Jun 14 10:00:35 coreos1 docker[45146]: #8 /var/www/app/code/core/Mage/Core/Model/App.php(1337): Mage_Core_Model_App->_callObserverMethod()
Jun 14 10:00:35 coreos1 docker[45146]: #9 /var/www/app/Mage.php(448): Mage_Core_Model_App->dispatchEvent()
Jun 14 10:00:35 coreos1 docker[45146]: #10 /var/www/app/code/core/Mage/Sales/Model/Order.php(1115): Mage::dispatchEvent()
Jun 14 10:00:35 coreos1 docker[45146]: #11 /var/www/app/code/core/Mage/Core/Model/Resource/Transaction.php(105): Mage_Sales_Model_Order->place()
Jun 14 10:00:35 coreos1 docker[45146]: #12 /var/www/app/code/core/Mage/Core/Model/Resource/Transaction.php(159): Mage_Core_Model_Resource_Transaction->_runCallbacks()
Jun 14 10:00:35 coreos1 docker[45146]: #13 /var/www/app/code/core/Mage/Sales/Model/Service/Quote.php(189): Mage_Core_Model_Resource_Transaction->save()
Jun 14 10:00:35 coreos1 docker[45146]: #14 /var/www/app/code/core/Mage/Sales/Model/Service/Quote.php(249): Mage_Sales_Model_Service_Quote->submitOrder()
...

The most obvious solution (and the one I've used at least temporarily) is to wrap all of Observer::orderPlaced() in a try{}catch{} that silently discards the exception.

Thanks, Jared