我是Magento新手,我試圖覆蓋控制器「app/code/core/Mage/Directory/controllers/CurrencyController.php」以在貨幣更改時清除購物車。覆蓋Magento中的CurrencyController
我嘗試了很多方法可以做到這一點,所以我相信在XML文件中被遺漏......
有人能幫助我嗎???
婁如下我在做什麼:
文件夾的結構
_app _CODE _local _Emptycart _directory _controllers _CurrencyController.php
_app _CODE _local _Emptycart _directory _etc _config.xml
/app/code/local/Emptycart/Directory/etc/config.xml
<config>
<frontend>
<routers>
<directory>
<use>standard</use>
<args>
<modules>
<Emptycart_Directory before="Mage_Directory">Emptycart_Directory</Emptycart_Directory>
</modules>
</args>
</directory>
</routers>
</frontend>
</config>
/應用程序/代碼/本地/ Emptycart/Directory/controllers/CurrencyController.php
<?php
require_once 'Mage/Directory/controllers/CurrencyController.php';
class Emptycart_Directory_CurrencyController extends Mage_Directory_CurrencyController
{
public function switchAction()
{
die('it worked!');
if ($curency = (string) $this->getRequest()->getParam('currency')) {
Mage::app()->getStore()->setCurrentCurrencyCode($curency);
}
//Get cart helper
$cartHelper = Mage::helper('checkout/cart');
//Get all items from cart
$items = $cartHelper->getCart()->getItems();
//Loop through all of cart items
foreach ($items as $item) {
$itemId = $item->getItemId();
//Remove items, one by one
$cartHelper->getCart()->removeItem($itemId)->save();
}
$this->_redirectReferer(Mage::getBaseUrl());
}
}
看起來這麼好給我。是否包含controller.php文件?如果在類定義之前添加die()會發生什麼?你清除了緩存嗎? –
感謝您的回覆。 「controller.php」你的意思是在第一行require_once?我把die()移到了類定義之前,什麼都沒有發生。我總是清理緩存來測試它... – RaphaelDuraes