覆盖运输方式 - 我缺少什么
我之前写过很多模块,但由于某种原因,我的运输模块不会覆盖现有的 Magneto 运输方法。这是允许的吗?我在这里缺少什么?模块名称显示在配置区域的高级选项卡中,因此它正在加载,但没有任何反应。有什么提示吗?
代码
etc/modules/Ssi_Shipping.xml
<?xml version="1.0"?>
<config>
<modules>
<Ssi_Shipping>
<active>true</active>
<codepool>local</codepool>
</Ssi_Shipping>
</modules>
</config>
local/Ssi/Shipping/etc.xml
<?xml version="1.0"?>
<config>
<modules>
<Ssi_Shipping>
<version>0.1.0</version>
</Ssi_Shipping>
</modules>
<global>
<models>
<shipping>
<rewrite>
<carrier_tablerate>Ssi_Shipping_Model_Carrier_Tablerate</carrier_tablerate>
</rewrite>
</shipping>
</models>
</global>
</config>
local/Ssi/Shipping/Model/Carrier/Tablerate.php
<?php
class Ssi_Shipping_Model_Carrier_Tablerate
extends Mage_Shipping_Model_Carrier_Tablerate {
public function isActive()
{
Mage::log("here! Ssi_Shipping_Model_Carrier_Tablerate");
// check to see if it's disabled
if (parent::isActive() == false)
return false;
// check in the shopping cart
foreach( Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection() as $item ){
if ($item->getDeliveryFlag() == "test")
return true;
}
// if nothing is found then disable this option.
return false;
}
}
I've written many many modules before but for some reason my shipping module won't override an exsiting Magneto shipping method. Is that allowed? What am I missing here? The module name shows up in the advanced tab of the configuration area, so it's getting loaded, but nothing is happening. Any hints?
Code
etc/modules/Ssi_Shipping.xml
<?xml version="1.0"?>
<config>
<modules>
<Ssi_Shipping>
<active>true</active>
<codepool>local</codepool>
</Ssi_Shipping>
</modules>
</config>
local/Ssi/Shipping/etc.xml
<?xml version="1.0"?>
<config>
<modules>
<Ssi_Shipping>
<version>0.1.0</version>
</Ssi_Shipping>
</modules>
<global>
<models>
<shipping>
<rewrite>
<carrier_tablerate>Ssi_Shipping_Model_Carrier_Tablerate</carrier_tablerate>
</rewrite>
</shipping>
</models>
</global>
</config>
local/Ssi/Shipping/Model/Carrier/Tablerate.php
<?php
class Ssi_Shipping_Model_Carrier_Tablerate
extends Mage_Shipping_Model_Carrier_Tablerate {
public function isActive()
{
Mage::log("here! Ssi_Shipping_Model_Carrier_Tablerate");
// check to see if it's disabled
if (parent::isActive() == false)
return false;
// check in the shopping cart
foreach( Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection() as $item ){
if ($item->getDeliveryFlag() == "test")
return true;
}
// if nothing is found then disable this option.
return false;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
有一种方法,但它并不明显,需要我浏览运输模块源:
如果你查看Mage_Shipping_Model_Config,你会发现用作Mage::getModel()参数的代码被采用从商店配置。此代码不是像“shipping/carrier_tablerate”这样的标准代码,因此它无法像往常一样帮助覆盖。
现在你必须先找出这个代码是什么。例如,我想覆盖矩阵速率载体,所以我像这样测试了它:
是的,您可以将此代码临时放置在页面上的任何位置,但对于可以从命令行运行的此类内容有一个单独的文件很有用(从 Mage::app() 开始初始化 Magento)
在我的例子中,代码是 matrixrate_shipping/carrier_matrixrate 所以我必须像这样更改我的 config.xml:
而不是
Good Luck!
There is a way but it is not obvious and required me to browse the shipping module source:
If you look at Mage_Shipping_Model_Config, you will discover that the code used as parameter for Mage::getModel() is taken from the store configuration. This code is NOT the standard code like 'shipping/carrier_tablerate', so it does not help overriding as usual.
Now you have to find out first what this code is. For example I wanted to override the matrixrate carrier, so I tested it like that:
Yes, you can put this code anywhere on the page temporary but it is useful to have a separate file for such things that can be run from the command line (starting with Mage::app() to initialize Magento)
In my case the code was matrixrate_shipping/carrier_matrixrate so I had to change my config.xml like that:
instead of
Good Luck!
首先检查模型是否被覆盖。试试这个:
Check first that the model is being overridden at all. Try this:
经过一番研究后,我发现覆盖运输控制器的唯一方法是在本地代码文件夹中复制文件(和目录结构)。然后我基本上可以调整代码。
不知道为什么 Magento 似乎不允许标准覆盖这些运输功能,但至少有一个解决方法。
After working through this one a bit, I found that the only way to override the shipping controller was to make a duplicate of the file (and directory structure) in the local code folder. Then I could basically tweak the code.
Not sure why Magento doesn't seem to allow the standard overriding of these shipping functions, but a least there is a work around.
已经有一段时间了,但最近几天我遇到了同样的问题。我想覆盖免费送货和统一运费方法,除了 fab 的答案之外,我还必须在 etc/config.xml 中添加以下代码。就我而言,原始值位于 app/code/core/Mage/Shipping/etc/config.xml 中。
模型值是示例。您必须将它们替换为正确的路径。
it's been a while but I had the same problem the last days. I wanted to override freeshipping and flatrate shipping methods and in addition to the answer of fab I had to add the following code in etc/config.xml. In my case the original values are located in app/code/core/Mage/Shipping/etc/config.xml.
The model values are examples. You have to replace them with your correct paths.
如果其他人也面临这个问题并来这里寻求解决方案,那么看起来OP已经在模块文件中使用了
codepool
,而它应该是codePool
(注意大写的P)。If anyone else is facing this problem and came here for solution, it looks like OP have used
codepool
in module file where it should becodePool
(notice the capital P).