0

拡張機能がレイアウトの更新を行う必要がある場合、次の方法は機能しません。

名前空間/モジュール/etc/config.xml :

<?xml version="1.0" encoding="UTF-8"?>
<config> 
    <modules>
        <Namespace_Modulename>
            <version>0.0.1</version>
        </Namespace_Modulename>
    </modules>
    <frontend>
        <layout>
            <updates>
                <catalog_product_view>
                    <reference name="content">
                        <remove name="product.info.upsell" />
                    </reference>
                </catalog_product_view>
            </updates>
        </layout>
    </frontend>
</config>

しかし、これはうまくいきます:

名前空間/モジュール/etc/config.xml :

<?xml version="1.0" encoding="UTF-8"?>
<config> 
    <modules>
        <Namespace_Modulename>
            <version>0.0.1</version>
        </Namespace_Modulename>
    </modules>
    <frontend>
        <layout>
            <updates>
                <Namespace_Modulename>
                    <file>modulename.xml</file>
                </Namespace_Modulename>
            </updates>
        </layout>
    </frontend>
</config>

そして、関連するレイアウトの更新をapp/design/frontend/base/default/layout/modulename.xmlに配置しました。

少し前にチュートリアルでアプローチ#1について読んだことを誓うことができましたが、今はもう見つけられません。そのチュートリアルは間違っていましたか?アプローチ #2 はこれを行う正しい方法ですか? 私のレイアウト更新ファイルをフロントエンド/ベースに置くのは少しハックに思えます...何か提案はありますか?

4

2 に答える 2

2

あなたがそれについて読んだ場合、それはどちらかでした

  1. 古いバージョンの Magento の場合

  2. 露骨に間違っている

config.xmlレイアウト更新 XML ファイルは、グローバル構成ツリーとは別のシステムです。レイアウト XML が読み込まれます

#File: app/code/core/Mage/Core/Model/Layout/Update.php
public function getFileLayoutUpdatesXml($area, $package, $theme, $storeId = null)
{
    if (null === $storeId) {
        $storeId = Mage::app()->getStore()->getId();
    }
    /* @var $design Mage_Core_Model_Design_Package */
    $design = Mage::getSingleton('core/design_package');
    $layoutXml = null;
    $elementClass = $this->getElementClass();
    $updatesRoot = Mage::app()->getConfig()->getNode($area.'/layout/updates');
    Mage::dispatchEvent('core_layout_update_updates_get_after', array('updates' => $updatesRoot));
    $updateFiles = array();
    foreach ($updatesRoot->children() as $updateNode) {
        if ($updateNode->file) {
            $module = $updateNode->getAttribute('module');
            if ($module && Mage::getStoreConfigFlag('advanced/modules_disable_output/' . $module, $storeId)) {
                continue;
            }
            $updateFiles[] = (string)$updateNode->file;
        }
    }
    // custom local layout updates file - load always last
    $updateFiles[] = 'local.xml';
    $layoutStr = '';
    foreach ($updateFiles as $file) {
        $filename = $design->getLayoutFilename($file, array(
            '_area'    => $area,
            '_package' => $package,
            '_theme'   => $theme
        ));
        if (!is_readable($filename)) {
            continue;
        }
        $fileStr = file_get_contents($filename);
        $fileStr = str_replace($this->_subst['from'], $this->_subst['to'], $fileStr);
        $fileXml = simplexml_load_string($fileStr, $elementClass);
        if (!$fileXml instanceof SimpleXMLElement) {
            continue;
        }
        $layoutStr .= $fileXml->innerXml();
    }
    $layoutXml = simplexml_load_string('<layouts>'.$layoutStr.'</layouts>', $elementClass);
    return $layoutXml;
}

このコードは<updates/>ノードへの参照を取得しますが、

$updatesRoot = Mage::app()->getConfig()->getNode($area.'/layout/updates');

これは、ファイルのリストをまとめるためにのみ使用されます

foreach ($updatesRoot->children() as $updateNode) {
    if ($updateNode->file) {
        $module = $updateNode->getAttribute('module');
        if ($module && Mage::getStoreConfigFlag('advanced/modules_disable_output/' . $module, $storeId)) {
            continue;
        }
        $updateFiles[] = (string)$updateNode->file;
    }
}
于 2013-03-19T18:09:44.703 に答える
1

Mage_Core_Model_Layout_Update::getFileLayoutUpdatesXml()(リンク)は、ビューを構成する目的でファイルベースのレイアウト更新をマージするメソッドであり、構成 DOM からのレイアウト更新ディレクティブをマージするためのロジックを備えていません。

于 2013-03-19T18:11:30.360 に答える