magentoモジュール書き換え
4033 ワード
書き換えapp/code/core/Mage/Catalog/Block/Navigation.phpを例に
1.マッチのコピー(推奨しない)
First add a new Navigation.php file you can edit to your local folder that Magento will reference instead of the original.
Copy the original found here: app/code/core/Mage/Catalog/Block/Navigation.php
Recreate this folder structure in your app/code/local folder. So go to app/code/local, make a Mage folder, inside it make a Catalog folder, inside that make a Block folder, and inside that place your copy of Navigation.php, eg: app/code/local/Mage/Catalog/Block/Navigation.php
Second, add some code to the app/etc/local.xml file, inside of the global tags.
2.書き換え(推奨)
If you want to override a core controller on Magento in order to add other customActions, it is really quick and easy to do so. Here are the files that you have to take into account: The block you want to override :/app/code/core/Mage/Catalog/Block/Navigation.php The xml file to enable the module:/app/etc/modules/[namespace] _All.xml The block xml file definition :/app/code/local/[namespace]/Catalog/etc/config.xml The overridden block :/app/code/local/[namespace]/Catalog/Block/Navigation.php
本明細書のすべての[namespace]は、自分のインスタンスの名前「App」に置き換えられます.他のネーミングスペースを使用する場合は、[namespace]を置き換えることができます.
First of all, you have to enable the module on the/app/etc/modules/directory. This file would be App _All.xml and inside that:
dependsを開くとcore classに頼ることを表し、
Now it’s time to create the/app/code/local/App/Catalog/etc/config.xml file that will override the core block:
注意:App_Catalog_Block_Navigation でApp_Catalog_Block_Navigationは勝手に名前をつけることはできません.必ず正しい完全な経路を形成しなければなりません.[namespace]Catalog_Block_Navigation => [namespace]/Catalog/Block/Navigation.php
Finally, we can create the class that will add/change actions to the core block: app/code/local/App/Catalog/Block/Navigation.php
注意:classは元のMageを継承しています.Catalog_Block_Navigation
注意:効果を見る場合は、cacheをクリーンアップするか、バックグラウンドでdisable cacheをクリアします.
1.マッチのコピー(推奨しない)
First add a new Navigation.php file you can edit to your local folder that Magento will reference instead of the original.
Copy the original found here: app/code/core/Mage/Catalog/Block/Navigation.php
Recreate this folder structure in your app/code/local folder. So go to app/code/local, make a Mage folder, inside it make a Catalog folder, inside that make a Block folder, and inside that place your copy of Navigation.php, eg: app/code/local/Mage/Catalog/Block/Navigation.php
Second, add some code to the app/etc/local.xml file, inside of the global tags.
<blocks>
<catalog>
<rewrite>
<navigation>Mage_Catalog_Block_Navigation</navigation>
</rewrite>
</catalog>
</blocks>
2.書き換え(推奨)
If you want to override a core controller on Magento in order to add other customActions, it is really quick and easy to do so. Here are the files that you have to take into account:
本明細書のすべての[namespace]は、自分のインスタンスの名前「App」に置き換えられます.他のネーミングスペースを使用する場合は、[namespace]を置き換えることができます.
First of all, you have to enable the module on the/app/etc/modules/directory. This file would be App _All.xml and inside that:
<?xml version="1.0"?>
<config>
<modules>
<App_Catalog>
<active>true</active>
<codePool>local</codePool>
<!--depends>
<Mage_Core/>
</depends-->
</App_Catalog>
</modules>
</config>
dependsを開くとcore classに頼ることを表し、
Now it’s time to create the/app/code/local/App/Catalog/etc/config.xml file that will override the core block:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<App_Catalog>
<version>0.1.0</version>
</App_Catalog>
</modules>
<global>
<blocks>
<catalog>
<rewrite>
<navigation>App_Catalog_Block_Navigation</navigation>
</rewrite>
</catalog>
</blocks>
</global>
</config>
注意:
Finally, we can create the class that will add/change actions to the core block: app/code/local/App/Catalog/Block/Navigation.php
<?php
class App_Catalog_Block_Navigation extends Mage_Catalog_Block_Navigation
{
protected function _renderCategoryMenuItemHtml($category, $level = 0, $isLast = false, $isFirst = false,
$isOutermost = false, $outermostItemClass = '', $childrenWrapClass = '', $noEventAttributes = false, $showText = false)
{
/* .... */
}
}
注意:classは元のMageを継承しています.Catalog_Block_Navigation
注意:効果を見る場合は、cacheをクリーンアップするか、バックグラウンドでdisable cacheをクリアします.