开发者

Load module from specific place (magento)

I am trying to override a core module on the Magento Platform.

This is absolutly no problem. I've made a simple module for it and it's loaded by default through the etc/modules/...xml file. But what I would like is to:

Call the module only on category pages.

Does anybody know if it is possible to call (define, set) a module from a template file?

How can I get it to load only on a particlar template file, or only on the category pages in that matter?


I am currently trying things out, but still cant wrap my fingers around the right code. I think an if/else statement is right for the core module currency.php, but mayby you guys can help me out.

*This is what I was thinking, see the order not the code ;) *

<?php
class MyCompany_ConstPrice_Model_Currency extends Mage_Directory_Model_Currency
{
开发者_如何转开发public function __A_NAME_() 
if(Mage::app()->getFrontController()->getRequest()->getRouteName() == 'catalog') :
elseif:
$this->_redirectReferer(Mage::getBase()); 

Rest of code....
?>


To provide an override you first need to rewrite the class alias.

<config>
    <global>
        <models>
            <directory>
                <rewrite>
                    <currency>MyCompany_ConstPrice_Model_Currency</currency>
                </rewrite>
            </directory>
        </models>
    </global>
</config>

Now you can do the actual override.

<?php

class MyCompany_ConstPrice_Model_Currency extends Mage_Directory_Model_Currency
{

    public function getCode()
    {
        if ((Mage::app()->getRequest()->getRouteName() == 'catalog')
         && (Mage::app()->getRequest()->getControllerName() == 'category')) {
            // return something here...
        }
        // else not a category page
        return parent::getCode();
    }
}

NB: I use getCode() as the example because it's the first function declared.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜