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()
    {
     ...
    }
}
  • 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')); ? – Raphael at Digital Pianism Mar 15 '16 at 11:29
  • Yes, I have flush the chache and it does not solve the problem. – Adrian Gallego Castellanos Mar 15 '16 at 11:51
  • What about the code I pasted ? Which result did you get from this ? – Raphael at Digital Pianism Mar 15 '16 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. – Adrian Gallego Castellanos Mar 15 '16 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. – Adrian Gallego Castellanos Mar 15 '16 at 12:01
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.

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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