Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Event in __call method
 
benippon-francois
Member
 
Total Posts:  51
Joined:  2009-01-15
 

Hello,

I have to create a lot of modules and some of them need to override the same classes to add methods.
This is of course not ideal, because often I don’t have an event to avoid to override, so the only way is to create a “global” overriding class for all my modules!

I think it would be great to have an event in the __call method (and why not __callStatic if possible), launched only when no match is found for the method name, so that we could extend a class by events!

What do you think about it?

Thank you,

François

(message originally in http://www.magentocommerce.com/boards/viewthread/39276/)

 
Magento Community Magento Community
Magento Community
Magento Community
 
demonkoryu
Guru
 
Avatar
Total Posts:  328
Joined:  2008-11-26
Dortmund, Germany
 

I don’t often need to add methods to classes, but override class methods from multiple modules. So… meh.  confused
Where do you need to add methods?

 
Magento Community Magento Community
Magento Community
Magento Community
 
benippon-francois
Member
 
Total Posts:  51
Joined:  2009-01-15
 

Mainly in Product.php (the product model), because I extends the basic product to deal with new/used states for example, but also some other functionalities in others modules.

But the needs are different for every body, the point is it would be easy to add methods to almost any class without to have to modify it, so much more cleaner and extensible than to override, no?

 
Magento Community Magento Community
Magento Community
Magento Community
 
demonkoryu
Guru
 
Avatar
Total Posts:  328
Joined:  2008-11-26
Dortmund, Germany
 

Yes, I hope they fix that ASAP. BTW can’t you just use attributes for used/new state?

 
Magento Community Magento Community
Magento Community
Magento Community
 
benippon-francois
Member
 
Total Posts:  51
Joined:  2009-01-15
 

No, ‘cause we have different stock/prices for each of them, but we have to display both in the same page. So I choose to use a grouped product (a virtual main product and 2 linked products), but I had to do some things like automatically create the linked products (and to have to edit/delete only one), or retrieve some informations with some calculations in the grouping product…

Well, this is ot the main subject so if you want to talk about it no problem at all, but let’s do it by pm or in another thread if you don’t mind ^^

 
Magento Community Magento Community
Magento Community
Magento Community
 
demonkoryu
Guru
 
Avatar
Total Posts:  328
Joined:  2008-11-26
Dortmund, Germany
 

Recently I’ve had your exact problem.

I don’t know how to solve it the “clean” way, but maybe there’s some (rather complicated) method to use PHP’s reflection and maybe Zend Frameworks code generators to create “dynamic” superclasses which get all methods and members from the various extensions? Then write the code out to a cache file and we’re done.

On second thought, it will be complicated to call the original functions correctly when they depend on implementations in parent classes.
Like the DirectResize Image helper calls upon the original helper with parent::resize().

Still, might be an idea. What do you think? Or did you find another solution?

 
Magento Community Magento Community
Magento Community
Magento Community
 
benippon-francois
Member
 
Total Posts:  51
Joined:  2009-01-15
 

Hello,

In fact since then I was working on totally differents modules, so I didn’t met the problem in that time. Since we’re in a rush to finalize a first version of the website, and that the current solution works (a module for global override), I didn’t try to cleanup it, no time. After our release I will probably try to, but for now nothing, sorry :S

 
Magento Community Magento Community
Magento Community
Magento Community
 
demonkoryu
Guru
 
Avatar
Total Posts:  328
Joined:  2008-11-26
Dortmund, Germany
 
benippon-francois - 12 May 2009 11:25 PM

a module for global override

Sounds interesting. Could you please explain a bit what this is?
Greetings

 
Magento Community Magento Community
Magento Community
Magento Community
 
benippon-francois
Member
 
Total Posts:  51
Joined:  2009-01-15
 

Nothing fantastic in fact, sorry ^^’
I just override my classes in a single module which its only purpose is to override rasberry
With some good comments, I can tell which method is for which other module, so it’s still clear, but far from a perfect solution. At least, it works and I don’t have useless module dependences.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top