簡體   English   中英

從特定地方加載模塊(magento)

[英]Load module from specific place (magento)

我試圖覆蓋Magento平台上的核心模塊。

絕對沒有問題。 我為它制作了一個簡單的模塊,它默認通過etc / modules / ... xml文件加載。 但我想要的是:

僅在類別頁面上調用模塊。

有人知道是否可以從模板文件中調用(定義,設置)模塊?

如何才能將其僅加載到特定模板文件上,或僅加載到該類別頁面上?


我目前正在嘗試解決問題,但仍然無法繞過正確的代碼。 我認為if / else語句適用於核心模塊currency.php,但也許你們可以幫助我。

* 這就是我的想法,看到的順序不是代碼;)*

<?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....
?>

要提供覆蓋,首先需要重寫類別名。

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

現在你可以做實際的覆蓋了。

<?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();
    }
}

注意:我使用getCode()作為示例,因為它是第一個聲明的函數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM