Magento自定义运输模块-致命错误:调用成员函数setStore()



使用magento 1.9.0.1时,我做了像本教程一样的自定义模块

我一步一步地遵循了本教程,但在我的生产服务器中不起作用。

在前端的购物车中,我得到了错误:致命错误:在第424行的/var/www/html/includs/src/Mage_Shipping_Model_Shipping.php中的非对象上调用成员函数setStore()

我在这里读了很多问题,运气不好。就像这个问题一样,我清理了缓存,禁用并启用了编译器,我已经通过终端等进行了编译。但错误仍然存在。

这里的代码:

/app/etc/modules/Company_Module.xml

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

/app/code/local/Company/Module/etc/config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
    <Company_Module>
        <module>0.0.1</module>
    </Company_Module>
</modules>
<global>
    <models>
        <company_module>
            <class>Company_Module_Model</class>
        </company_module>
    </models>
</global>
<!-- Default configuration -->
<default>
    <carriers>
        <company_module>
            <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>company_module/carrier</model>
            <!--
                The title as referenced in the carrier class
            -->
            <title>Transporte Test</title>
            <sort_order>10</sort_order>
            <sallowspecific>0</sallowspecific>
        </company_module>
    </carriers>
</default>
</config>

/app/code/local/Company/Module/etc/system.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
<sections>
    <carriers translate="label" module="shipping">
        <groups>
            <company_module translate="label">
                <label>Transporte Test</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>
                    <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>
                    <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>
                    <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>
                    <sallowspecific translate="label">
                        <label>Transporte aplicado a los siguientes paises</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>
                    <specificcountry translate="label">
                        <label>Envio a países especificos</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>
                </fields>
            </company_module>
        </groups>
    </carriers>
</sections>
</config>

/app/code/local/Company/Module/Model/carrier.php

<?php
class Company_Module_Model_Carrier extends Mage_Shipping_Model_Carrier_Abstract implements Mage_Shipping_Model_Carrier_Interface
{
    protected $_code = 'company_module';
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());

    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, de 5 a 10 días');
    $rate->setPrice(14000);
    $rate->setCost(0);
    return $rate;
}
public function getAllowedMethods()
{
    return array(
        'standard' => 'Standard'
    );
}
public function isTrackingAvailable()
{
    return true;
}
}

您的错误在方法getCarrierByCode

尝试放置Mage::log($carrierCode, false, 'mylog.log', true);

$obj = Mage::getModel($className);

您的运营商代码包含欠编码,请尝试删除它。如果它没有帮助-显示Mage::log 的结果

更新版本1并从模型中删除下划线

<model>company_module/carrier</model>

更新版本2我复制粘贴了你帖子中的所有内容,但有点不同。

/app/code/local/Company/Module/Model/Carrier.php

文件名Carrier.php(您与所有小写字母一起使用)。您的模块工作正常。我成功下了订单。

最新更新