Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

I need to override Varien class because I need to change one method.

app/code/core/Varien/Data/Collection/Db.php

From what I know, the only way is to put it inside local folder.

app/code/local/Varien/Data/Collection/Db.php

But in this way I override entire class. Is there any way to override just single method?

share|improve this question
1  
Which method are you trying to override, and why?? Many of these methods are overridden in the Magento collection superclasses. –  benmarks Feb 18 at 19:50
    
Explain what you try to achieve. I'm sure there is a better method than overwriting a core class. –  Fabian Blechschmidt Feb 18 at 20:07
    
Method getSelectCountSql() because I use group by in admin grid and this returns wrong count. Unfortunately I could not find any better way. See using group() breaks getSelectCountSql and Wrong count in admin Grid when using GROUP BY clause. –  JohnyFree Feb 18 at 20:39

2 Answers 2

up vote 3 down vote accepted

Method getSelectCountSql() is overwritten in a lot of collections like Mage_Sales_Model_Resource_Order_Collection for example.

So if you need to change the behavior of getSelectCountSql() for some collection, you can easily do that in your collection class.

But do not do that in Varien_Data_Collection_Db because it will change the behavior of this method for all collections.

share|improve this answer
    
You are right, I extended Mage_Customer_Model_Resource_Customer_Collection class and it works. tnx! –  JohnyFree Feb 19 at 8:07
    
If my answer helped you please mark it as accepted. –  oleksii.svarychevskyi Feb 19 at 9:07

The original definition for this class lives in the ./lib/Varien/ folder.

If you must override any autoloaded classes from the ./lib folder, you can only do this via inclusion in total in one of the codepools (local, core, community in order of precedence).

There is no way to overwrite only one method.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.