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

How to extend abstract classes
 
jmbesol
Jr. Member
 
Avatar
Total Posts:  6
Joined:  2008-05-29
 

Hi,
I’ve created a few modules that change the functionality of some concrete classes in core but when I try the same procedure to extend an abstract class (like Mage_Shipping_Model_Carrier_Abstract), Magento does not run the new code in my module. I don’t get any errors, it just runs the core code instead of my module code. Does anyone know how to extend abstract classes? Thanks in advance.

Here is my config.xml:

<?xml version="1.0"?>
<config>
    <
modules>
        <
XXX_Tare>
            <
version>1.0.0</version>
            <
depends>
            <!-- 
no dependencies -->
            </
depends>
        </
XXX_Tare>
    </
modules>
    <global>
        <
models>
          <
shipping>
            <
rewrite>
              <
carrier_abstract>XXX_Tare_Model_Carrier_Abstract</carrier_abstract>
            </
rewrite>
          </
shipping>
        </
models>
        <
resources />
        <
extraconfig />
        <
blocks />
    </global>
</
config>
 
Magento Community Magento Community
Magento Community
Magento Community
 
jmbesol
Jr. Member
 
Avatar
Total Posts:  6
Joined:  2008-05-29
 

Just an update: I found another forum thread where people said that it is not possible to override an abstract class. If this is true then I’m a little surprised. In my case I need to change how the handling fee works for the shipping carriers. Each carrier class eventually extends Mage_Shipping_Model_Carrier_Abstract which is where getFinalPriceWithHandlingFee($cost) is found.

If you can’t modify an abstract class, do you have to extend every shipping method class to modify functionality that they all share from the parent?

 
Magento Community Magento Community
Magento Community
Magento Community
 
jmbesol
Jr. Member
 
Avatar
Total Posts:  6
Joined:  2008-05-29
 

Got a partial answer on this thread:
http://www.magentocommerce.com/boards/viewthread/18494/

Based on this it doesn’t look like you can extend an abstract class using a module.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Asad Rahman
Jr. Member
 
Avatar
Total Posts:  22
Joined:  2009-04-08
 

Hi,

Why do you want to override abstarct class ??

Magneto instantiated class object using xml notaion like Mage::getModel(’customer/customer’). By overriding a class we inform magento that rather instantiate ‘customer/customer’ model instantiate ‘customer/customer2’ class.

Now, Abstract classes are never instantiated.It is only used as parent class for inheritance for other class. Event you override abstract class it will never used since in inheritance the class name is use, not xml nation of the class.

I think you have to override the child classes not the abstract class.

Asad
http://magentocookbook.wordpress.com/

 
Magento Community Magento Community
Magento Community
Magento Community
 
Romain_C
Member
 
Avatar
Total Posts:  74
Joined:  2008-07-25
Hossegor, France
 

Even if I understand why overriding an Abstract Class is useless cause child classes will still reference the core “mage” named class.
I’m having the needs to update a method which is defined in an Abstract Class and I can’t make it work by the “classic module” way.
Do you have any idea how to achieve this ?

For example I would need to update the “getCountryHtmlSelect” method defined in app/code/core/Mage/Checkout/Onepage/Abstract .

 
Magento Community Magento Community
Magento Community
Magento Community
 
ckosny
Guru
 
Total Posts:  349
Joined:  2009-02-28
Luxembourg
 

Hi there

I believe (but I am not sure) that you can put your version of the file app/code/core/Mage/Checkout/Onepage/Abstract.php (meaning the class Mage_Checkout_Onepage_Abstract) in the /app/local folder.

As this folder comes before the core folder in the include paths, Magento should take this version of the file rather than the version in the core folder. Of course that means that you need to have a complete copy of the file in there, not just the function that you need changed, so you will have to check the file at each update.

Good luck

Claudia

 
Magento Community Magento Community
Magento Community
Magento Community
 
Romain_C
Member
 
Avatar
Total Posts:  74
Joined:  2008-07-25
Hossegor, France
 

Thanks for your help but I still couldn’t make it work by any manner…

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