Chr*_*ris 6 php shipping magento magento-1.4
我以前写了很多模块但由于某种原因我的运输模块不会覆盖现有的Magneto运输方法.这是允许的吗?我在这里错过了什么?模块名称显示在配置区域的高级选项卡中,因此它已加载,但没有发生任何事情.任何提示?
码
等/模块/ Ssi_Shipping.xml
<?xml version="1.0"?>
<config>
    <modules>
        <Ssi_Shipping>
            <active>true</active>
            <codepool>local</codepool>
        </Ssi_Shipping>
    </modules>
</config>
本地/ SSI /运输/ 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>
本地/ SSI /运输/型号/电信/ 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;
        }
    }
Fab*_*ler 12
有一种方法,但它不明显,并要求我浏览运输模块来源:
如果你看一下Mage_Shipping_Model_Config,你会发现用作Mage :: getModel()参数的代码来自商店配置.此代码不是像'shipping/carrier_tablerate'这样的标准代码,因此它无法像往常一样覆盖.
现在你必须先找出这段代码是什么.例如,我想覆盖矩阵载波,所以我测试了它:
$carrierConfig = Mage::getStoreConfig('carriers/matrixrate')
var_dump($carrierConfig['model']);
是的,您可以将此代码暂时放在页面的任何位置,但是有一个单独的文件可用于从命令行运行(从Mage :: app()开始初始化Magento)
在我的例子中,代码是matrixrate_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>
祝好运!
经过一番研究后,我发现覆盖运输控制器的唯一方法是在本地代码文件夹中复制文件(和目录结构)。然后我基本上可以调整代码。
不知道为什么 Magento 似乎不允许标准覆盖这些运输功能,但至少有一个解决方法。