Magento 1.7覆盖Pdf类 [英] Magento 1.7 Override Pdf Classes

查看:82
本文介绍了Magento 1.7覆盖Pdf类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图覆盖Pdf类以更改Invoice/Shipment/Creditmemo pdf,但它似乎没有体现.

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

我在Mymodule/etc/config.xml中使用以下命令创建了一个模块

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>

然后我在Mymodule/models/中创建了以下Model类 作为Abstract.php,Invoice.php,Shipment.php,Creditmemo.php

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

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

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.

谢谢, 洛夫琳

真正的问题是etc/config.xml中的语法错误[请参见大写C结束标记]

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

Mymodule_Printtemplates_Model_Order_Pdf_Creditmemo

Mymodule_Printtemplates_Model_Order_Pdf_Creditmemo

我使用以下步骤调试了该问题:将其放在index.php的底部,类似于Alans Module List,但是使用了快速的代码复制/粘贴方法.请记住,Magento的所有XML都合并到一个XML树中.

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());

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

选自以下答案:推荐答案

以下是我看到的几件事.

Here are a couple of things that I am seeing.

  1. 每个覆盖文件的文件路径是什么?它们应该是:例如,Mymodule/Printtemplates/Model/Order/Pdf/Invoice.php.类名应与文件名匹配.
  2. 重写不会影响抽象类,除非使用工厂方法(不推荐)调用抽象类.重写的工作方式是通过工厂方法(Mage::getModel('')).使用factory方法,Magento可以浏览系统以查看是否需要使用另一个类.但是,当一个类被硬引用(例如Mage_Sales_Model_Order_Pdf_Abstract)时,它不会通过factory方法,因此不会对此进行任何重写.
  3. 我会考虑让您的每个类扩展其原始类(例如,Mage_Sales_Model_Order_Pdf_Invoice等).如果您还有其他常用功能,则可以将其放入帮助器中.
  4. 要查看代码是否被调用,请在文件中放入一个已知的代码错误. PHP会抱怨,并且告诉您文件正在加载.
  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.

这篇关于Magento 1.7覆盖Pdf类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆