覆盖运输方式 - 我缺少什么

发布于 2024-10-08 01:06:22 字数 1820 浏览 3 评论 0原文

我之前写过很多模块,但由于某种原因,我的运输模块不会覆盖现有的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

是伱的 2024-10-15 01:06:22

有一种方法,但它并不明显,需要我浏览运输模块源:

如果你查看Mage_Shipping_Model_Config,你会发现用作Mage::getModel()参数的代码被采用从商店配置。此代码不是像“shipping/carrier_tablerate”这样的标准代码,因此它无法像往常一样帮助覆盖。

现在你必须先找出这个代码是什么。例如,我想覆盖矩阵速率载体,所以我像这样测试了它:

$carrierConfig = Mage::getStoreConfig('carriers/matrixrate')
var_dump($carrierConfig['model']);

是的,您可以将此代码临时放置在页面上的任何位置,但对于可以从命令行运行的此类内容有一个单独的文件很有用(从 Mage::app() 开始初始化 Magento)

在我的例子中,代码是 ma​​trixrate_shipping/carrier_matrixrate 所以我必须像这样更改我的 config.xml:

<global>
    <models>
        <matrixrate_shipping>
            <rewrite>
                <carrier_matrixrate>my_class_name</carrier_matrixrate>
            </rewrite>
        </matrixrate_shipping>
    </models>

而不是

<global>
    <models>
        <matrixrate>
            <rewrite>
                <carrier_matrixrate>my_class_name</carrier_matrixrate>
            </rewrite>
        </matrixrate>
    </models>

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:

$carrierConfig = Mage::getStoreConfig('carriers/matrixrate')
var_dump($carrierConfig['model']);

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:

<global>
    <models>
        <matrixrate_shipping>
            <rewrite>
                <carrier_matrixrate>my_class_name</carrier_matrixrate>
            </rewrite>
        </matrixrate_shipping>
    </models>

instead of

<global>
    <models>
        <matrixrate>
            <rewrite>
                <carrier_matrixrate>my_class_name</carrier_matrixrate>
            </rewrite>
        </matrixrate>
    </models>

Good Luck!

心不设防 2024-10-15 01:06:22

首先检查模型是否被覆盖。试试这个:

var_dump(get_class(Mage::getModel("shipping/carrier_tablerate")));

Check first that the model is being overridden at all. Try this:

var_dump(get_class(Mage::getModel("shipping/carrier_tablerate")));
百合的盛世恋 2024-10-15 01:06:22

经过一番研究后,我发现覆盖运输控制器的唯一方法是在本地代码文件夹中复制文件(和目录结构)。然后我基本上可以调整代码。

不知道为什么 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.

深者入戏 2024-10-15 01:06:22

已经有一段时间了,但最近几天我遇到了同样的问题。我想覆盖免费送货和统一运费方法,除了 fab 的答案之外,我还必须在 etc/config.xml 中添加以下代码。就我而言,原始值位于 app/code/core/Mage/Shipping/etc/config.xml 中。

<?xml version="1.0"?>
<config>
    ...
    <default>
        <carriers>
            <flatrate>
                <model>your_module/shipping_carrier_flatrate</model>
            </flatrate>
            <freeshipping>
                <model>your_module/shipping_carrier_freeshipping</model>
            </freeshipping>
        </carriers>
    </default>
</config>

模型值是示例。您必须将它们替换为正确的路径。

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.

<?xml version="1.0"?>
<config>
    ...
    <default>
        <carriers>
            <flatrate>
                <model>your_module/shipping_carrier_flatrate</model>
            </flatrate>
            <freeshipping>
                <model>your_module/shipping_carrier_freeshipping</model>
            </freeshipping>
        </carriers>
    </default>
</config>

The model values are examples. You have to replace them with your correct paths.

拔了角的鹿 2024-10-15 01:06:22

如果其他人也面临这个问题并来这里寻求解决方案,那么看起来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 be codePool (notice the capital P).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文