Magento致命错误:找不到类'Mage_Order_Helper_Data'

时间:2014-08-07 15:44:49

标签: php magento magento-1.8

我必须过度思考这个问题,但我似乎无法解决它。我需要覆盖 Mage_Sales_Model_Order sendNewOrderEmail 功能。当我这样做时,我在管理界面的下拉列表中丢失了交易电子邮件模板。

错误:

Fatal error: Class 'Mage_Order_Helper_Data' not found

/app/code/local/Mine/Sales/etc/config.xml

<?xml version="1.0"?>
<config>
    <global>
        <models>
            <sales>
                <rewrite>
                    <order>Mine_Sales_Model_Order</order>
                </rewrite>
            </sales>
        </models>
        <helpers>
            <sales>
                <class>Mine_Sales_Helper</class>
            </sales>
        </helpers>
        <template>
            <email>
                <umicrosite_order_alert module="order">
                    <label>Vendor Order Alert</label>
                    <file>umicrosite_order_alert.html</file>
                    <type>html</type>
                </umicrosite_order_alert>
            </email>
        </template>
    </global>
</config>

/app/code/local/Mine/Model/Sales/Order.php

<?php
class Mine_Sales_Model_Order extends Mage_Sales_Model_Order
{
    /**
     * Send email with order data
     *
     * @return Mage_Sales_Model_Order
     */
    public function sendNewOrderEmail()
    {
        $storeId = $this->getStore()->getId();

        $emailTemplate = Mage::getModel('core/email_template')->loadDefault('umicrosite_order_alert');
        $emailTemplate->setSender(Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId));
        $emailTemplate->setSenderEmail(Mage::getStoreConfig('trans_email/ident_sales/email'));
        $emailTemplate->setSenderName(Mage::getStoreConfig('trans_email/ident_sales/name'));
        $emailTemplate->setType('html');
        $emailTemplate->setTemplateSubject('New Order from my store');
        $emails = array();
        foreach ($this->getItemsCollection() as $item) {
            $vendor = Mage::helper('udropship')->getVendor($item->getProduct());
            $email = $vendor->getEmail();
            if (!in_array($email,$emails)) {
                $emails[] = $email;
                $emailTemplateVariables = array();
                $emailTemplateVariables = array('vendor_name'=>$vendor->getVendorName());
                $emailTemplate->send($email, $vendor->getVendorName(), $emailTemplateVariables);
            }
        }
        parent::sendNewOrderEmail();
    }
}

/app/code/local/Mine/Sales/Helper/Data.php

<?php
class Mine_Sales_Helper_Data extends Mage_Sales_Helper_Data
{

}

如果我将Data.php更改为:

class Mage_Order_Helper_Data extends Mage_Core_Helper_Abstract

它会导致Class&#39; Mine_Sales_Helper_Data&#39;没找到。

我做错了什么???

1 个答案:

答案 0 :(得分:2)

您只需要从Mage_Core_Helper_Abstract扩展您的助手。

<?php
class Mine_Sales_Helper_Data extends Mage_Core_Helper_Abstract
{

}

实际上,如果只是重写模型类,则不希望为扩展定义帮助器。因此,如果从config.xml文件中删除帮助程序定义,它应该可以正常工作。试试吧

修改

啊..为什么我之前没有注意到它。你把这段代码放在配置文件中

<config>
    <global>
        <models>
            <sales>
                <rewrite>
                    <order>Mine_Sales_Model_Order</order>
                </rewrite>
            </sales>
        </models>
        <helpers>
            <mine_sales> <!-- helper alias; IT SHOULD BE UNIQUE; so avoid 'sales' -->
                <class>Mine_Sales_Helper</class>
            </mine_sales>
        </helpers>
        <template>
            <email>
                <umicrosite_order_alert module="mine_sales">
                    <label>Vendor Order Alert</label>
                    <file>umicrosite_order_alert.html</file>
                    <type>html</type>
                </umicrosite_order_alert>
            </email>
        </template>
    </global>
</config>

问题出在这里。 <umicrosite_order_alert module="order">。在这里,您已将模块指定为order。这实际上是寻找带别名order的助手。 Magento试图找到它。但它没有定义。因此显示此错误。

您可以在此设置mine_sales的帮助别名。所以你必须在module属性中指定它。现在试试吧。它肯定会起作用

注意:你需要在这里使用我的助手定义。如果您使用自己的助手定义,则没有问题。由于扩展助手类的类是Mage_Sales_Helper_Data,实际上是Mage_Core_Helper_Abstract的子级。但你不需要这样做。在这种情况下,您可以直接扩展Mage_Core_Helper_Abstract