gpt4 book ai didi

php - 覆盖运输方式 - 我错过了什么

转载 作者:可可西里 更新时间:2023-11-01 13:11:39 25 4
gpt4 key购买 nike

我以前写过很多模块,但出于某种原因,我的运输模块不会覆盖现有的 Magneto 运输方法。这是允许的吗?我在这里错过了什么?模块名称显示在配置区域的高级选项卡中,因此它正在加载,但没有任何反应。有什么提示吗?

代码

etc/modules/Ssi_Shipping.xml

<?xml version="1.0"?>
<config>
<modules>
<Ssi_Shipping>
<active>true</active>
<codepool>local</codepool>
</Ssi_Shipping>
</modules>
</config>

本地/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;

}


}

最佳答案

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

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

现在你必须先找出这段代码是什么。例如,我想覆盖 matrixrate carrier,所以我这样测试了它:

$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>

祝你好运!

关于php - 覆盖运输方式 - 我错过了什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4474502/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com