Magento 1.7 Override Pdf Classes

血红的双手。 提交于 2020-01-17 10:21:37

问题


I tried to override Pdf classes for making changes toInvoice/Shipment/Creditmemo pdf but it doesnt seem to reflect.

I created a module with following in the Mymodule/etc/config.xml

<config>
<modules>
    <Mymodule_Printtemplates>
        <version>0.1.0</version>
    </Mymodule_Printtemplates>
</modules>
<global>
    <models>
        <sales>
            <rewrite>
                <order_pdf_abstract>Mymodule_Printtemplates_Model_Order_Pdf_Abstract</order_pdf_abstract>
                <order_pdf_invoice>Mymodule_Printtemplates_Model_Order_Pdf_Invoice</order_pdf_invoice>
                <order_pdf_creditmemo>Mymodule_Printtemplates_Model_Order_Pdf_Creditmemo</order_pdf_Creditmemo>
                <order_pdf_shipment>Mymodule_Printtemplates_Model_Order_Pdf_Shipment</order_pdf_shipment>
            </rewrite>
        </sales>
    </models>
</global>

Then I created following Model classes in Mymodule/models/ as Abstract.php, Invoice.php, Shipment.php, Creditmemo.php

abstract class Mymodule_Printtemplates_Model_Order_Pdf_Abstract extends Mage_Sales_Model_Order_Pdf_Abstract

class  Mymodule_Printtemplates_Model_Order_Pdf_Invoice extends  Mymodule__Printtemplates_Model_Order_Pdf_Abstract { ... functions here ...}

class Mymodule_Printtemplates_Model_Order_Pdf_Shipment extends Mymodule__Printtemplates_Model_Order_Pdf_Abstract{ ... functions here ...}

class Mymodule_Printtemplates_Model_Order_Pdf_Creditmemo  extends  Mymodule__Printtemplates_Model_Order_Pdf_Abstract{ ... functions here ...}

The module is enabled - I have checked it through System>Configuration>Admin>Advanced but it doesn't seem to reflect the changes

On the other-hand, if I copy paste Mage/Sales/Model/Order/Pdf/*.php into local and change, changes are reflected. I know this is not a recommended method but the method via rewriting classes doesnt seem to work.

Any help for the first method via class rewrite would be appreciated.

Thanks, Loveleen


The real problem was a Syntax in error in etc/config.xml [see Capital C in ending tag]

Mymodule_Printtemplates_Model_Order_Pdf_Creditmemo

I used the following to debug the issue: Drop this in the bottom of your index.php, similar to Alans Module List but a quick code copy/paste approach. Remember all of Magento's XML's get combined into one XML tree.

header("Content-Type: text/xml"); die(Mage::app()->getConfig()->getNode()->asXML());

Taken from the answers of: How do I know whether my Config.xml file is working in Magento?


回答1:


Here are a couple of things that I am seeing.

  1. What are the file paths to each of your overridden files? They should be: Mymodule/Printtemplates/Model/Order/Pdf/Invoice.php, for example. The class name should match the file name.
  2. Rewrites do not affect abstract classes, unless the abstract class is called with a factory method (not recommended). The way that a rewrite works is through the factory methods (Mage::getModel('')). Using the factory method allows Magento to look through the system to see if another class is needing to be used. However, when a class is hard-referenced (e.x. Mage_Sales_Model_Order_Pdf_Abstract), it does not go through the factory method, and thus no rewrites will occur on that.
  3. I would consider making each of your classes extend their original class (e.x. Mage_Sales_Model_Order_Pdf_Invoice, etc). If you have extra common functions, you would possibly put those into a Helper.
  4. To see if the code is even being called, put a known code error in the file. PHP will complain, and that tells you that your file is being loaded.



回答2:


I used the following to debug the issue: Drop this in the bottom of your index.php, similar to Alans Module List but a quick code copy/paste approach. Remember all of Magento's XML's get combined into one XML tree.

header("Content-Type: text/xml"); die(Mage::app()->getConfig()->getNode()->asXML());

Taken from the answers of: How do I know whether my Config.xml file is working in Magento?



来源:https://stackoverflow.com/questions/13253782/magento-1-7-override-pdf-classes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!