segment-boneyard / analytics-magento

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

Issue #70 Instantiate action controllers through Mage::getModel #71

Closed 7ochem closed 5 years ago

7ochem commented 9 years ago

Now using Mage::getModel('segment_analytics/controller_' . $actionName) to instantiate action controllers instead of instantiating them directly so the controller classes (models) can be rewritten through the core Magento rewrite system.

I've done this by adding a factory method. I also changed the Front Controller model from instantiating it directly to doing this through Mage::getSingleton(). This way you could also rewrite the Front Controller model and ultimately rewrite the behaviour of the new Segment_Analytics_Model_Front_Controller::_controllerFactory() method to first try to find custom action controllers somewhere else for instance (= some sort of fallback).

See issue #70

sperand-io commented 8 years ago

@7ochem despite my comment to the contrary on the issue, now that I look at the scope of the fix... if you can just restate the case for this change I'd be happy to merge and release. I just want to make sure I really understand the case for the change.

Thanks!

7ochem commented 8 years ago

The actual impact of the change is minimal. Instead of directly instantiating the class, Mage::getModel() will do this. If you'd call, for instance Mage::getModel('segment_analytics/controller_page') this will resolve to Segment_Analytics_Model_Controller_Page: Passing 'segment_analytics' to getModel() will resolve to Segment_Analytics_Model and 'controller_page' will be added.

So as said, the change has little direct impact. But it does give developers the possibility/freedom to replace the classes with their own. When Mage::getModel('segment_analytics/controller_page') is being called, then Magento will check if there are any "rewrites" registered for this class, if so, then Magento will instantiate that class, typically one of a custom module and typically that class will extend the original class, so allowing for rewriting/replacing parts of it's functionalities.

This above process is necessary in our case to add another handle to Segment_Analytics_Model_Controller_Page's _getCategoryPageHandles() method as we have an alternative category page. And I think I could come up with other imaginative cases if you wish to be convinced more...