【问题标题】:Magento custom shipping module - Fatal error: Call to a member function setStore()Magento 自定义运输模块 - 致命错误:调用成员函数 setStore()
【发布时间】:2015-04-07 13:09:28
【问题描述】:

使用 magento 1.9.0.1 我做了这样的自定义模块tutorial

我一步一步按照本教程进行操作,但在我的生产服务器中不起作用。

在前端的购物车中出现错误:致命错误:在 /var/www/html/includes/src/Mage_Shipping_Model_Shipping.php 中的非对象上调用成员函数 setStore() 424

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

代码如下:

/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;
}

}

【问题讨论】:

  • 禁用编译器会发生什么?
  • 通过终端和 mydomain.com/checkout/cart 清除和禁用 --> 空白页:致命错误:调用 /var/www 中非对象上的成员函数 setStore() /html/includes/src/Mage_Shipping_Model_Shipping.php 在第 424 行
  • 禁用编译器时,magento 不应使用文件夹包含/src。也许你有 APC/Varnish 或者你在另一个 magento 中禁用了缓存?
  • 好的,谢谢,我正在使用正确的 magento,它安装在 amazon ec2 中,带有基本的 ubuntu 安装,没有清漆等...我所做的所有操作都是通过终端。
  • 检查您的includes/config.php所有行都应该从注释符号'#'开始

标签: magento magento-1.9


【解决方案1】:

您的错误在于方法 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(您使用的所有字母都小写)。并且您的模块工作正常。我成功下单了。

【讨论】:

  • 我做了这个更改: 步骤 1:在第 4 行的 carrier.php 中,我删除了下划线:protected $_code = 'companymodule'; Step2:在我的 config.xml 中,我修改了 company_module/carrier 这一行 companymodule/carrier 我做错了什么?我把它放在方法 getCarrierByCode..> Mage::log(false, $carrierCode, 'mylog.log', true);Mage::log(false, 'test', 'mylog.log', true);但是日志文件是空的。
  • 对不起,我的错误。 Mage::log($carrierCode, false, 'mylog.log', true);如果日志仍然为空 - 检查其启用的系统/配置/开发人员/日志设置/启用是否设置为是。如您所知,日志位于 var/log/mylog.log
  • 2015-04-07T15:12:06+00:00 EMERG (): flatrate 2015-04-07T15:12:06+00:00 EMERG (): freeshipping 2015-04-07T15: 12:06+00:00 EMERG (): company_module 2015-04-07T15:17:28+00:00 EMERG (): flatrate 2015-04-07T15:17:28+00:00 EMERG (): freeshipping 2015- 04-07T15:17:28+00:00 EMERG (): company_module 还是有下划线?我在confing.xml和carrier.php中改变了它
  • 您的代码运行正常!阅读我的upd2。多于。很抱歉用下划线打断了你。
  • 我不敢相信这个 f**king "c" 是我的噩梦。我已经放了 Carrier.php,现在它工作正常......在 localhost 工作正常“carrier.php”和“Carrier.php”但在服务器中只能工作“Carrier.php”。天哪,非常感谢!
猜你喜欢
  • 2010-11-09
  • 1970-01-01
  • 2015-08-07
  • 2012-09-05
  • 1970-01-01
  • 1970-01-01
  • 2011-12-07
  • 2011-08-22
  • 2017-06-22
相关资源
最近更新 更多