我是 Magento 新手,我正在尝试覆盖控制器“app/code/core/Mage/Directory/controllers/CurrencyController.php”以在货币更改时清除购物车。
我尝试了很多方法来做到这一点,所以我相信在 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>
/app/code/local/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());
}
}