0

我是 Magento 新手,我正在尝试覆盖控制器“app/code/core/Mage/Directory/controllers/CurrencyController.php”以在货币更改时清除购物车。

我尝试了很多方法来做到这一点,所以我相信在 XML 文件中丢失了......

有人可以帮我吗???

贝娄遵循我正在做的事情:


文件夹结构

_app _code _local _Emptycart _D​​irectory _controllers _CurrencyController.php

_app _code _local _Emptycart _D​​irectory _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());
    }
}
4

1 回答 1

0

您可以使用此 模块创建器创建模块的基本骨架。然后您可以将其与您创建的模块进行比较。这样调试变得容易。如果您想从头开始学习模块创建,请阅读magento wiki 文章

于 2013-02-07T10:27:28.220 回答