使用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;
}
}
答案 0 :(得分:4)
您的错误在方法 getCarrierByCode
尝试放置 Mage::log($carrierCode, false, 'mylog.log', true);
$obj = Mage::getModel($className);
您的运营商代码包含底码,请尝试将其删除。如果它没有帮助 - 显示Mage :: log
的 upd.1 强>
并从模型中删除下划线
<model>company_module/carrier</model>
<强> upd.2 强> 我复制粘贴你帖子中的所有内容,但有点不同。
/app/code/local/Company/Module/Model/Carrier.php
文件名Carrier.php(您使用小写字母的所有字母)。并且您的模块正常运行。我成功下了订单。