I’m a Magento newbier and I’m trying to override the controller “app/code/core/Mage/Directory/controllers/CurrencyController.php” to clear the cart when the currency is changed.
I tried a lot of ways to do that, so I believe to be missing in the XML file…
Could someone help me please???
Bellow follows what I’m doing:
Folder’s Structure
_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());
}
}
You can use this module creator to create basic skeleton of module.Then you can compare it with the module you have created.This way it becomes easy to debug.
If you want to learn module creation from scratch then go through the magento wiki articles.