【发布时间】: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