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

Page 1 of 2
How do I overwrite/extend an abstract class? 
 
scree
Sr. Member
 
Avatar
Total Posts:  137
Joined:  2008-07-14
Linz
 

I want to overwrite Mage_Sales_Model_Order_Pdf_Items_Abstract like I did with Mage_Sales_Model_Order_Pdf_Invoice (to set the font to HELVETICA), but the changes do not take affect.

I tried to add everything to my config file.

Is it possible to extend an abstract class?

 
Magento Community Magento Community
Magento Community
Magento Community
 
kiwimonk
Jr. Member
 
Total Posts:  3
Joined:  2008-06-19
 

I have the exact same question.  I would like to overwrite Mage_Catalog_Block_Product_Abstract .. Nothing i’ve tried thus far is working.

 
Magento Community Magento Community
Magento Community
Magento Community
 
LindyKyaw
Sr. Member
 
Avatar
Total Posts:  138
Joined:  2008-01-02
Los Angeles
 

You can extend an abstract class.
For you case, overriding the abstract class will be useless.
It is better to override the class which is used in object creation.
Hope it helps.

 
Magento Community Magento Community
Magento Community
Magento Community
 
alkarim
Guru
 
Total Posts:  368
Joined:  2008-04-10
 

Try this but as this far, I didn’t notice any error. Please tell me if you do… thanks

app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php
app/code/core/Mage/Sales/Model/Order/Pdf/Invoice.php

1. You want to orverride app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php, then you need to replace or additional function to new abstract.php (app/code/local/New/Sales/Model/Order/Pdf/Abstract.php)

abstract class New_Sales_Model_Order_Pdf_Abstract extends Mage_Sales_Model_Order_Pdf_Abstract

{

.... [ ADDITIONAL or REPLACE FUNCTION  ]
}

2. Then (this is what I do) we need to override the file that call the abstract.php, it is app/code/core/Mage/Sales/Model/Order/Pdf/Invoice.php so we override it.

class New_Sales_Model_Order_Pdf_Invoice extends New_Sales_Model_Order_Pdf_Abstract 
{
....[ COPY PASTE ALL THE FUNCTION HERE ]
}

hope this would help you

 
Magento Community Magento Community
Magento Community
Magento Community
 
jdurand
Jr. Member
 
Total Posts:  9
Joined:  2008-05-16
 

Can you post what you did to overwrite Mage_Sales_Model_Order_Pdf_Invoice

I’m trying to do this exact thing right now and any help would be useful…

 
Magento Community Magento Community
Magento Community
Magento Community
 
abhijit
Jr. Member
 
Total Posts:  7
Joined:  2009-01-18
India
 

Hello all,

I want to override the abstract class Mage_Catalog_Block_Product_Abstract, but couldn’t succeed. This class is extended by many other classes. Do I need to override them too (only to change there extend statement). I really would not prefer this as it would cause a lot of overhead.

Thanks in advance.

 
Magento Community Magento Community
Magento Community
Magento Community
 
meurissema
Member
 
Total Posts:  62
Joined:  2008-03-10
Marcq En Baroeul
 

I want to override this class Mage_Customer_Model_Address_Abstract, i create this class XXX_Psurcharge_Model_SurchargeValidate.
And i the config xml, i have :

<customer_address>
                <
rewrite>
                     <abstract>
XXX_Psurcharge_Model_SurchargeValidate</abstract>
                </
rewrite>
 </
customer_address>
It doesn’t work. Is it possible to override an abstract class ?
 
Magento Community Magento Community
Magento Community
Magento Community
 
aaronce
Member
 
Avatar
Total Posts:  32
Joined:  2008-08-07
Brisbane
 

Hi all,

I am trying to override both of the files Abstract.php, but it will not work for me.
these are the current file modifications i have in place.

MyModule/Sales/Model/Order/Pdf/Abstract.php
MyModule/Sales/Model/Order/Pdf/Creditmemo.php
MyModule/Sales/Model/Order/Pdf/Invoice.php
MyModule/Sales/Model/Order/Pdf/Shipment.php
MyModule/Sales/Model/Order/Pdf/Items/Abstract.php
MyModule/Sales/Model/Order/Pdf/Items/Creditmemo/Default.php
MyModule/Sales/Model/Order/Pdf/Items/Invoice/Default.php
MyModule/Sales/Model/Order/Pdf/Items/Shipment/Default.php

MyModule/Sales/ect/config.xml

<?xml version="1.0"?>
<config>
    <global>
             <
models>
                <
sales>
                <
rewrite>
                    <
order_pdf_abstract>MyModule_Sales_Model_Order_Pdf_Abstract</order_pdf_abstract>   
                            <
order_pdf_shipment>MyModule_Sales_Model_Order_Pdf_Shipment</order_pdf_shipment
                            <
order_pdf_invoice>MyModule_Sales_Model_Order_Pdf_Invoice</order_pdf_invoice
                            <
order_pdf_creditmemo>MyModule_Sales_Model_Order_Pdf_Creditmemo</order_pdf_creditmemo>
                                   <
order_pdf_items_creditmemo_default>MyModule_Sales_Model_Order_Pdf_Items_Creditmemo_Default</order_pdf_items_creditmemo_default>
                                   <
order_pdf_items_invoice_default>MyModule_Sales_Model_Order_Pdf_Items_Invoice_Default</order_pdf_items_invoice_default>
                                   <
order_pdf_items_shipment_default>MyModule_Sales_Model_Order_Pdf_Items_Shipment_Default</order_pdf_items_shipment_default>
                                   <
order_pdf_items_abstract>MyModule_Sales_Model_Order_Pdf_Items_Abstract</order_pdf_items_abstract>
                        </
rewrite>
                </
sales>
             </
models>
    </global>
</
config>

MyModule/Sales/Model/Order/Pdf/Items/Abstract.php

abstract class MyModule_Sales_Model_Order_Pdf_Items_Abstract extends Mage_Core_Model_Abstract

MyModule/Sales/Model/Order/Pdf/Abstract.php

abstract class MyModule_Sales_Model_Order_Pdf_Abstract extends Varien_Object

And the rest of the file in the directories are pointing at the Mymodule_..._Abstract.php correctly.

This is the Error i get in upon requesting an invoice in admin.

Recoverable ErrorArgument 1 passed to MyModule_Sales_Model_Order_Pdf_Items_Abstract::setPdf() must be an instance of Mage_Sales_Model_Order_Pdf_Abstractinstance of MyModule_Sales_Model_Order_Pdf_Invoice givencalled in /home/virt/public_html/app/code/local/MyModule/Sales/Model/Order/Pdf/Abstract.php on line 527 and defined  in /home/virt/public_html/app/code/local/MyModule/Sales/Model/Order/Pdf/Items/Abstract.php on line 114

Can anyone help me here on how to override this correctly, Is it even possible this way? really stumped on the process involved with overriding abstract files, so any help would be good. Thanks!

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

Did anyone find an answer as to how to override abstract classes?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Saggy
Sr. Member
 
Total Posts:  133
Joined:  2009-02-03
 

Do the following to overwrite abstract class -:

1) Copy the abstract class at the following location -> /app/local/Mage/Sales/Model/Order/Pdf/Abstract.php (create missing folders)

2) Once copied make the changes. This way you can overwrite abstract class.

Normal classes can be overwritten using usual rewrite approach.

Cheers
S

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

Thanks Saggy, that worked like a charm!

Does this mean there is no way to extend an abstract class through a module?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Saggy
Sr. Member
 
Total Posts:  133
Joined:  2009-02-03
 

I have tried several ways but this is the only way worked. Only magento team can put some light on this.

Cheers
S

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

Saggys approach is the only solution to your problem ATM, one that has the problem that different modules can’t override the same core abstract class. It’s possible to rewrite core classes and extend the __call function to extension modules functions, but that would go too far (and is of questionable use).

There is really no way out of this other than a proper plugin system, which would have to be implemented by the Core Team (and they could better rewrite the whole software while they’re at it. wink)

Really, the best way is what LindyKyaw said and just override all derived classes. You could factor out the common code to a helper and have not too much repeating code.

 
Magento Community Magento Community
Magento Community
Magento Community
 
FishPig
Sr. Member
 
Avatar
Total Posts:  232
Joined:  2009-06-05
 

I’m trying to override Mage_Core_Block_Abstract.

I want to override the function _afterToHtml so that I can strip out all white space from my html. I can’t override all of the derived classes like LindyKyaw said because I would need to override every block that outputs html (almost all of them!).

Are there any options available to me without actually modifying Mage_Core_Block_Abstract?

Thanks smile

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

The only thing you can do is to copy core/Mage/Core/Block/Abstract.php to local/Mage/Core/Block/Abstract.php and modify the copy.

 
Magento Community Magento Community
Magento Community
Magento Community
 
FishPig
Sr. Member
 
Avatar
Total Posts:  232
Joined:  2009-06-05
 

Is that it? Do I not have to create it a module for it or anything or change any xml files?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 2