2012-11-06 97 views
0

我试图重写Pdf类来修改发票/货件/ Creditmemo pdf,但它似乎并没有反映出来。Magento 1.7覆盖PDF类

我创建了一个模块与所述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> 

然后创建在Mymodule中/模型以下/ 作为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 ...} 

模块使能 - 我已经通过检查其系统>配置>管理员>高级,但它似乎并没有反映更改

另一方面,如果我将Paste Mage/Sales/Model/Order/Pdf/*。php复制到本地并更改,则会反映更改。我知道这不是推荐的方法,但通过重写类的方法似乎不起作用。

通过类重写的第一种方法的任何帮助将不胜感激。

感谢, Loveleen


真正的问题是一个语法在等/ config.xml中[见大写字母C的结束标记]

Mymodule_Printtemplates_Model_Order_Pdf_Creditmemo

错误我使用以下方法来调试问题:将其放在index.php的底部,与Alans模块列表类似快速的代码复制/粘贴方法。记住所有Magento的XML都被合并到一个XML树中。

header(“Content-Type:text/xml”);模具(法师::应用程序() - > getConfig() - > getNode() - > asXML());

从答案摘自:How do I know whether my Config.xml file is working in Magento?

回答

2

这里有几件事情,我看到的。

  1. 什么是每个重写文件的文件路径?例如,它们应该是:Mymodule/Printtemplates/Model/Order/Pdf/Invoice.php。类名称应与文件名称匹配。
  2. 重写不会影响抽象类,除非使用工厂方法调用抽象类(不推荐)。重写工作的方式是通过工厂方法(Mage::getModel(''))。使用工厂方法允许Magento查看系统,看看是否需要使用另一个类。但是,当一个类是硬引用的(e.x. Mage_Sales_Model_Order_Pdf_Abstract)时,它不会经过工厂方法,因此不会发生重写。
  3. 我会考虑让你的每个类扩展他们的原始类(e.x. Mage_Sales_Model_Order_Pdf_Invoice等)。如果你有额外的常用功能,你可能会把这些功能放到助手中。
  4. 要查看代码是否被调用,请在文件中输入已知的代码错误。 PHP会抱怨,并告诉你你的文件正在被加载。
+0

感谢Jmax!我会尝试你的建议。 –

+0

如果回答您的问题,请记住标记为已回答。 –

+0

你给了一个很好的清单。但真正的问题是,etc/config xml中的一个标签的结束标签有错误。有一个大写的C –

2

我使用以下方法调试问题: 将此放在index.php的底部,类似于Alans模块列表,但使用快速代码复制/粘贴方法。记住所有Magento的XML都被合并到一个XML树中。

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

来自:How do I know whether my Config.xml file is working in Magento?