2

Good morning everybody!

I have a problem trying to override the model app/code/core/Mage/Sales/Model/Order/Pdf/Total/Default.php with app/code/local/Mycompany/Sales/Model/Order/Pdf/Total/Default.php.

The thing is that when I rewrite the module but Magento is using the old module without override.

Here I upload the relevant codes:

  • etc/modules/Mycompany_Sales.xml
<?xml version="1.0"?>
<config>
 <modules>
 <Mycompany_Sales>
 <active>true</active>
 <codePool>local</codePool>
 <depends>
 <Mage_Sales />
 </depends>
 </Mycompany_Sales>
 </modules>
</config>
  • app/code/local/Mycompany/Sales/etc/config.xml
<?xml version="1.0"?>
<config>
 <modules>
 <Mycompany_Sales>
 <version>0.1.0</version>
 </Mycompany_Sales>
 </modules>
 <global>
 <models>
 <sales>
 <rewrite>
 <order_pdf_total_default>Mycompany_Sales_Model_Order_Pdf_Total_Default</order_pdf_total_default>
 </rewrite>
 </sales>
 </models>
 </global>
</config>
  • code/local/Mycompany/Sales/Model/Order/Pdf/Total/Default.php
<?php
class Mycompany_Sales_Model_Order_Pdf_Total_Default extends Mage_Sales_Model_Order_Pdf_Total_Default
{
 public function getFullTaxInfo()
 {
 ...
 }
}

I have compared it with some internet examples of models overriding and everything seems to be alright.

Anyone knows what can be the problem?

Thank you very much!!

[EDIT]

Finally I have solved the problem. The thing is that there is a core file app/code/core/Mage/Tax/Model/Sales/Pdf/Grandtotal.php that overrides app/code/core/Mage/Sales/Order/Pdf/Total/Default.php so my extended class was in conflict with the tax class.

For solving it I rewrite my extension in order to extends app/code/core/Mage/Tax/Model/Sales/Pdf/Grandtotal.php.

The result is: - etc/modules/Mycompany_Sales.xml

<?xml version="1.0"?>
<config>
 <modules>
 <Mycompany_Sales>
 <active>true</active>
 <codePool>local</codePool>
 <depends>
 <Mage_Sales />
 <Mage_Tax />
 </depends>
 </Mycompany_Sales>
 </modules>
</config>
  • app/code/local/Mycompany/Sales/etc/config.xml
<?xml version="1.0"?>
<config>
 <modules>
 <Mycompany_Sales>
 <version>0.1.0</version>
 </Mycompany_Sales>
 </modules>
 <global>
 <models>
 <tax>
 <rewrite>
 <sales_pdf_grandtotal>Mycompany_Sales_Model_Order_Pdf_Total_Default</sales_pdf_grandtotal>
 </rewrite>
 </tax>
 </models>
 </global>
</config>
  • code/local/Mycompany/Sales/Model/Order/Pdf/Total/Default.php
<?php
class Mycompany_Sales_Model_Order_Pdf_Total_Default extends Mage_Tax_Model_Sales_Pdf_Grandtotal
{
 public function getFullTaxInfo()
 {
 ...
 }
}
7
  • Did flush the cache ? Recompile if you're using compiler ? What do you get if you type get_class(Mage::getModel('sales/order_pdf_total_default')); ? Commented Mar 15, 2016 at 11:29
  • Yes, I have flush the chache and it does not solve the problem. Commented Mar 15, 2016 at 11:51
  • What about the code I pasted ? Which result did you get from this ? Commented Mar 15, 2016 at 11:51
  • 1
    When I use get_class(Mage::getModel('sales/order_pdf_total_default')); a weird thing happens, it shows my class Mycompany_Sales_Model_Order_Pdf_Total_Default instead the old one. Commented Mar 15, 2016 at 11:54
  • 1
    Because of the pdf result. There is a section in the pdf that says: "ESP 21 (21.0000%)". If I truncate the number in the Mage model the result is "ESP 21 (21%)", but if I truncate the number in my class it displays "ESP 21 (21.0000%)" as if I wouldn't have changed anything. Commented Mar 15, 2016 at 12:01

2 Answers 2

0

I think it is not working because of sales group name. It conflicts with Magento core sales module.

Use below code

app/etc/modules/Mycompany_Customsales.xml

<?xml version="1.0"?>
<config>
 <modules>
 <Mycompany_Customsales>
 <active>true</active>
 <codePool>local</codePool>
 <version>0.1.0</version>
 </Mycompany_Customsales>
 </modules>
</config>

app/code/local/Mycompany/Customsales/etc/config.xml

<?xml version="1.0"?>
<config>
 <modules>
 <Mycompany_Customsales>
 <version>0.1.0</version>
 </Mycompany_Customsales>
 </modules>
 <global>
 <helpers>
 <customsales>
 <class>Mycompany_Customsales_Helper</class>
 </customsales>
 </helpers>
 <models>
 <customsales>
 <class>Mycompany_Customsales_Model</class>
 <resourceModel>customsales_mysql4</resourceModel>
 </customsales>
 <sales>
 <rewrite>
 <order_pdf_total_default>Mycompany_Customsales_Model_Sales_Order_Pdf_Total_Default</order_pdf_total_default>
 </rewrite>
 </sales>
 </models>
 </global>
</config> 

Model: app/code/local/Mycompany/Customsales/Model/Sales/Order/Pdf/Total/Default.php

<?php
class Mycompany_Customsales_Model_Sales_Order_Pdf_Total_Default extends Mage_Sales_Model_Order_Pdf_Total_Default
{
 //add your code
}

Hope it will helpful to you.

answered Mar 15, 2016 at 12:41
2
  • I tried to copy the code above and flush cache but nothing seems to change. Commented Mar 16, 2016 at 10:15
  • Have you changed module group name ? Commented Mar 17, 2016 at 5:29
0

To elaborate on what Adrian Gallego Castellanos edited into his post, I wasn't able to successfully override app/code/core/Mage/Tax/Model/Sales/Pdf/Grandtotal.php.

I had to extend app/code/core/Mage/Tax/Model/Sales/Pdf/Tax.php instead so I could override the getFullTaxInfo() function found in app/code/core/Mage/Sales/Order/Pdf/Total/Default.php.

answered Jun 4, 2019 at 20:54

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.