自定义Magento运输模块出现致命错误 [英] Fatal Error with Custom Magento Shipping Module

查看:72
本文介绍了自定义Magento运输模块出现致命错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Magento Development还是陌生的,并且无法使自定义运输模块正常工作.我遵循了许多教程,但每次都遇到类似的错误.我当前使用的是此处 .我进行了很多修改,但最终出现了更多错误,因此当前可以将本教程的内容复制到我的magento 1.12.0.2安装中.

I am fairly new to Magento Development and am having trouble getting a custom shipping module to work. I followed numerous tutorials but ended up with similar errors each time. The current one I am using is here. I tinkered with it a lot but ended up with more errors, so I am currently at the stock of this tutorial copied over to my magento 1.12.0.2 installation.

Sysytem->Config->Shipping Methods下,出现新方法Smashing Magazine Carrier,我可以编辑显示的值.但是,每当我尝试去前端的购物车时,都会收到错误消息: Fatal error: Call to a member function setStore() on a non-object in /var/www/includes/src/Mage_Shipping_Model_Shipping.php on line 421

Under Sysytem->Config->Shipping Methods the new method, Smashing Magazine Carrier, appears and I can edit the values shown. However, whenever I try to go to the cart on the frontend I get the error: Fatal error: Call to a member function setStore() on a non-object in /var/www/includes/src/Mage_Shipping_Model_Shipping.php on line 421

和错误: Fatal error: Class 'Mage' not found in /var/www/includes/src/Mage_Core_Model_Resource_Setup.php on line 378

我很茫然,正在寻找正确方向的任何印记以解决此问题.感谢您的阅读!以下是相关文件:

I am at a loss and am looking for any inkling of a right direction to move in to fix this. Thank you for reading! Here are the relevant files:

/var/www/app/etc/modules/SmashingMagazine_MyCarrier.xml

<?xml version="1.0"?>
<config>
    <modules>
        <SmashingMagazine_MyCarrier>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Shipping />
            </depends>
        </SmashingMagazine_MyCarrier>
    </modules>
</config>

/var/www/app/code/local/SmashingMagazine/MyCarrier/Model/Carrier.php

<?php

class SmashingMagazine_MyCarrier_Model_Carrier extends Mage_Shipping_Model_Carrier_Abstract implements Mage_Shipping_Model_Carrier_Interface {

    protected $_code = 'smashingmagazine_mycarrier';

    public function collectRates(
    Mage_Shipping_Model_Rate_Request $request
    ) {
        $result = Mage::getModel('shipping/rate_result');
        /* @var $result Mage_Shipping_Model_Rate_Result */

        $result->append($this->_getStandardShippingRate());

        $expressWeightThreshold =
            $this->getConfigData('express_weight_threshold');

        $eligibleForExpressDelivery = true;
        foreach ($request->getAllItems() as $_item) {
            if ($_item->getWeight() > $expressWeightThreshold) {
                $eligibleForExpressDelivery = false;
            }
        }         

        if ($eligibleForExpressDelivery) {
            $result->append($this->_getExpressShippingRate());
        }

        if ($request->getFreeShipping()) {
            /**
             *  If the request has the free shipping flag,
             *  append a free shipping rate to the result.
             */
            $freeShippingRate = $this->_getFreeShippingRate();
            $result->append($freeShippingRate);
        }

        return $result;
    }

    protected function _getStandardShippingRate() {
        $rate = Mage::getModel('shipping/rate_result_method');
        /* @var $rate Mage_Shipping_Model_Rate_Result_Method */

        $rate->setCarrier($this->_code);
        /**
         * getConfigData(config_key) returns the configuration value for the
         * carriers/[carrier_code]/[config_key]
         */
        $rate->setCarrierTitle($this->getConfigData('title'));

        $rate->setMethod('standand');
        $rate->setMethodTitle('Standard');

        $rate->setPrice(4.99);
        $rate->setCost(0);

        return $rate;
    }

    protected function _getExpressShippingRate() {
        $rate = Mage::getModel('shipping/rate_result_method');
        /* @var $rate Mage_Shipping_Model_Rate_Result_Method */
        $rate->setCarrier($this->_code);
        $rate->setCarrierTitle($this->getConfigData('title'));
        $rate->setMethod('express');
        $rate->setMethodTitle('Express (Next day)');
        $rate->setPrice(12.99);
        $rate->setCost(0);
        return $rate;
    }



    protected function _getFreeShippingRate()
    {
        $rate = Mage::getModel('shipping/rate_result_method');
        /* @var $rate Mage_Shipping_Model_Rate_Result_Method */
        $rate->setCarrier($this->_code);
        $rate->setCarrierTitle($this->getConfigData('title'));
        $rate->setMethod('free_shipping');
        $rate->setMethodTitle('Free Shipping (3 - 5 days)');      
        $rate->setPrice(0);
        $rate->setCost(0);
        return $rate;       
    }

    public function getAllowedMethods() {
        return array(
            'standard' => 'Standard',
            'express' => 'Express',
            'free_shipping' => 'Free Shipping',
        );
    }

}

/var/www/app/code/local/SmashingMagazine/MyCarrier/etc/system.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <sections>
        <carriers translate="label" module="shipping">
            <groups>
                <smashingmagazine_mycarrier translate="label">
                    <label>Smashing Magazine Carrier</label>
                    <frontend_type>text</frontend_type>
                    <sort_order>2</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>
                    <fields>
                        <!--
                            The following fields are available
                            to modify in the admin panel.
                            The values are saved in the
                            database.

                            This shipping carrier abstract checks
                            this value to determine whether
                            the carrier should be shown.
                        -->
                        <active translate="label">
                            <label>Enabled</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                            <sort_order>1</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </active>
                        <!--
                            This value can be used to specify a
                            custom title for our method.
                        -->
                        <title translate="label">
                            <label>Title</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>2</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </title>
                        <!--
                            The sort order is used in Magento
                            to determine what order the carrier
                            will appear in relative to the
                            other carriers available.
                        -->
                        <sort_order translate="label">
                            <label>Sort Order</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>100</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </sort_order>
                        <!--
                            This value is used to specify whether
                            the carrier is available only for
                            specific countries or all countries
                            available in the current Magento
                            installation.
                        -->
                        <sallowspecific translate="label">
                            <label>Ship to Applicable Countries</label>
                            <frontend_type>select</frontend_type>
                            <sort_order>90</sort_order>
                            <frontend_class>shipping-applicable-country</frontend_class>
                            <source_model>adminhtml/system_config_source_shipping_allspecificcountries</source_model>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </sallowspecific>
                        <!--
                            If 'specific countries' is chosen
                            in the previous option, then this field
                            allows the administrator to specify
                            which specific countries this carrier
                            should be available for.
                        -->                   
                        <specificcountry translate="label">
                            <label>Ship to Specific Countries</label>
                            <frontend_type>multiselect</frontend_type>
                            <sort_order>91</sort_order>
                            <source_model>adminhtml/system_config_source_country</source_model>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                            <can_be_empty>1</can_be_empty>
                        </specificcountry>
                        <express_weight_threshold translate="label">
                            <label>Express Weight Threshold</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>100</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </express_weight_threshold>
                    </fields>
                </smashingmagazine_mycarrier>
            </groups>
        </carriers>
    </sections>
</config>

/var/www/app/code/local/SmashingMagazine/MyCarrier/etc/config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <SmashingMagazine_MyCarrier>
            <module>0.0.1</module>
        </SmashingMagazine_MyCarrier>
    </modules>
    <global>
        <models>
            <smashingmagazine_mycarrier>
                <class>SmashingMagazine_MyCarrier_Model</class>
            </smashingmagazine_mycarrier>
        </models>
    </global>
    <!-- Default configuration -->
    <default>
        <carriers>
            <smashingmagazine_mycarrier>
                <active>1</active>
                <!--
                     This configuration should not be made visible
                     to the administrator, because it specifies
                     the model to be used for this carrier.
                -->
                <model>smashingmagazine_mycarrier/carrier</model>
                <!--
                    The title as referenced in the carrier class
                -->
                <title>Smashing Magazine Carrier</title>
                <!--
                    The sort order specifies the position that
                    this carrier appears relative to the other
                    carriers available in checkout.
                -->
                <sort_order>10</sort_order>
                <!--
                    Out of the box, Magento offers shipping
                    carriers the ability to restrict themselves
                    to specific countries. For this configuration
                    option, 0 means allow all countries available,
                    and 1 means allow all countries specified
                    in the country list that we will add later
                    in system.xml
                -->
                <sallowspecific>0</sallowspecific>
            </smashingmagazine_mycarrier>
        </carriers>
    </default>
</config>

推荐答案

这是一个编译问题.转到系统>工具>编译,然后运行重新编译.

It's a compilation issue. Go to System > Tools > Compilation and run a Recompile.

这篇关于自定义Magento运输模块出现致命错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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