警告:包括无法打开流:magento helper中没有此类文件或目录

时间:2014-08-09 21:41:36

标签: php magento php-5.3

我创建了以下config.xml文件:

<config>
    <global>
        <helpers>
            <awesome>
                <class>CommissionJunction</class>
            </awesome>
        </helpers>
    </global>
</config>

我添加了以下php文件:as Data.php

<?php
    class CommissionJunction extends Mage_Core_Helper_Data
    {

        /**
        * Get SKU, quantity, price and discount amount for each product in a given order
        * @param object $order
        * @return array
        */
        private function _getOrderProductsList($order)
        {
            $orderItems = $order->getAllItems();
            $purchasedSkus = array();
            $count_orderItems = count($orderItems);
            for($i = 0; $i < $count_orderItems; $i++) {
                $purchasedSkus[$i] = array(
                    'ITEM' => $orderItems[$i]['sku'],
                    'QTY' => number_format($orderItems[$i]['qty_ordered'],0), // no decimals
                    'AMT' => number_format($orderItems[$i]['price'],2), // 2 decimal places
                    'DCNT' => number_format(abs($orderItems[$i]['discount_amount']),2)
                 );
            }

            return $purchasedSkus;
        }

        /**
        * Get the Universal Data (JSON) Object for Commission Junction.
        * This object contains the order details passed on to Commission Junction for reporting purposes
        * on the Checkout Success / Order Confirmation page.
        * Notes:
        *  - CID, TYPE AND CURRENCY are hard coded
        * @param string $orderId
        * @return JSON object Universal Data Object for Commission Junction $json_masterTmsUdp
        */
        public function getCommissionJunctionUdo($orderId)
        {
            $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
            $udo = array();
            $udo['CID'] = 'XXXX';
            $udo['TYPE'] = 'XXXX';
            $udo['CURRENCY'] = 'USD';
            $udo['OID'] = $orderId;
            $udo['DISCOUNT'] = number_format(abs($order->discount_amount),2);

            $order_coupon_code = $order->coupon_code;
            if(!is_null($order_coupon_code) && !empty($order_coupon_code))
            {
                $udo['COUPON'] = $order_coupon_code;
            }

            $udo['PRODUCTLIST'] = self::_getOrderProductsList($order);

            if(Mage::getModel('core/cookie')->get('aff_commissionjunction') == 'cjafflx')
            {
                $udo['FIRECJ'] = "TRUE";
            }
            else
            {
                $udo['FIRECJ'] = "FALSE";
            }

            $masterTmsUdo['CJ'] = $udo;
            $json_masterTmsUdo = json_encode($masterTmsUdo);

            return $json_masterTmsUdo;

        }

    }

然后在succes.phtml中我添加了这个:

<script>var MasterTmsUdo = <?php echo Mage::helper('commissionjunction')->getCommissionJunctionUdo($this->getOrderId()); ?></script>
<script>/*DO NOT ALTER *** tpd*/(function(e){var t="1340",n=document,r,i,s={http:"http://cdn.mplxtms.com/s/MasterTMS.min.js",https:"https://secure-cdn.mplxtms.com/s/MasterTMS.min.js"},o=s[/\w+/.exec(window.location.protocol)[0]];i=n.createElement("script"),i.type="text/javascript",i.async=!0,i.src=o+"#"+t,r=n.getElementsByTagName("script")[0],r.parentNode.insertBefore(i,r),i.readyState?i.onreadystatechange=function(){if(i.readyState==="loaded"||i.readyState==="complete")i.onreadystatechange=null}:i.onload=function(){try{e()}catch(t){}}})(function(){});</script>

错误: 1.我的成功页面无法正确呈现,模板丢失。 2.我在system.log中得到以下内容

014-08-09T21:33:07+00:00 ERR (3): Warning: include(Mage/Commissionjunction/Helper/Data.php): failed to open stream: No such file or directory  in /home/theprint/public_html/preprod/lib/Varien/Autoload.php on line 93
2014-08-09T21:33:07+00:00 ERR (3): Warning: include(Mage/Commissionjunction/Helper/Data.php): failed to open stream: No such file or directory  in /home/theprint/public_html/preprod/lib/Varien/Autoload.php on line 93

2 个答案:

答案 0 :(得分:2)

我至少可以看到3个错误:

  1. 您的帮助程序类不能只调用CommissionJunction。该名称必须包含从Mage_Core_Helper_Data的扩展名命名空间开始的所有路径。如果您的文件名为Data.php,那么帮助程序类名必须以Data结尾。所以它应该看起来像 Namespace_Extension_Helper_Data

  2. 在配置中,您声明您的助手应该由字符串 awesome 引用,但在模板中,您尝试通过字符串 commissionjunction 来获取帮助。所以你应该在config.xml或模板中更改它。

  3. 在config.xml类标记中,您必须编写辅助文件夹的路径。像 Namespace_Extension_Helper

  4. 之类的东西

答案 1 :(得分:2)

magento需要类名Packagename_Modulename_Helper

config.xml中

<config>
    <global>
        <helpers>
            <CommissionJunction>
                <class>CompanyName_CommissionJunction_Helper</class>
            </CommissionJunction>
        </helpers>
   </global>
</config>

并在你的班长:

class CompanyName_CommissionJunction_Helper_Data extends Mage_Core_Helper_Abstract

然后您可以拨打:Mage::helper('CommissionJunction');