1

私は単に、それが有効になっている場合、元のcart/shipping.phtmlファイルを自分のテンプレートファイルで上書きする拡張機能を構築しようとしています。

[有効にする]をクリックしても、拡張機能が有効になりません。レイアウトブロックのテーマを手動で変更すると、拡張機能が実際にb/cで機能することはわかっています。しかし、私はそれをしたくありません。私のコードを見て、私が間違っていることを教えていただけますか?私はそれが私のブロックファイルが正しくないことに関係していると思います。PS何が間違っているのか、そしてそれを修正する方法を見つけたら、拡張機能のCSSファイルを設定する方法も教えてください。それが有効になっている場合はどうでしょうか。

これが私のすべてのファイルです:)

etc / config.xml

<?xml version="1.0"?>
<config>    
<modules>
<Module_Name><version>1.0.0</version></Module_Name>
</modules>

<global>
        <blocks>
             <modulename>
                  <class>Module_Name_Block</class>
             </modulename>
        </blocks>

<helpers>
     <modulename>
      <class>Module_Name_Helper</class>
     </modulename>
</helpers>      
</global>


<modulename>
<settings>
<enable>1</enable>
</settings>
</modulename>

<frontend>
<layout>
    <updates>
        <modulename>
            <file><!-- shipping.xml --></file>
        </modulename>
    </updates>
</layout>
<routers>
    <modulename>
        <use>standard</use>
        <args>
            <module>Module_Name</module>
            <frontName>modulename</frontName>
        </args>
    </modulename>
</routers>  
</frontend>


<adminhtml>
<acl>
    <resources>
        <admin>
            <children>
                <system>
                    <children>
                        <config>
                            <children>
                                <modulename>
                                    <title>Shipping Extension</title>
                                </modulename>
                            </children>
                        </config>
                    </children>
                </system>
            </children>
        </admin>
    </resources>
</acl>
</adminhtml>

</config>

etc / system.xml

<?xml version="1.0"?>
<config>
<tabs>
<module translate="label">
    <label>Custom Extensions</label>
    <sort_order>100</sort_order>
</module>
</tabs>

<sections>  
        <modulename translate="label">
    <label>Shipping</label>
    <tab>module</tab>
    <frontend_type>text</frontend_type>
    <sort_order>1000</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>1</show_in_store>


        <groups>            

            <settings translate="label">
            <label>Settings</label>
            <frontend_type>text</frontend_type>
            <sort_order>1</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>1</show_in_store>

                <fields>
                    <enable translate="label">
                    <label>Enable</label>
                    <comment>
                    <![CDATA[Enable or Disable this extension.]]>
                    </comment>
                    <frontend_type>select</frontend_type>
                    <source_model>adminhtml/system_config_source_yesno</source_model>
                    <sort_order>1</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>                    
                    </enable>           
                </fields>

            </settings>
        </groups>
    </modulename >
</sections>     
</config>

Helper / Data.php

<?php
class Module_Name_Helper_Data extends Mage_Core_Helper_Abstract
{   

}

Block / Cart / Shipping.php

 <?php

 class Module_Name_Block_Cart_Shipping extends Mage_Checkout_Block_Cart_Shipping
{
protected function _beforeToHtml()
{
if(Mage::getStoreConfig('modulename/settings/enable'))

$this->setTemplate('module/name/shipping.phtml');

return $this;
}

}
4

1 に答える 1

4

ブール構成データを確認するには、Mage::getStoreConfigFlag()[link]を使用する方が適切です。この場合、ブロック クラスの書き換えを行う必要なく、純粋にレイアウト XML でこれを行うためのフックがあります。

モジュールのカスタム レイアウト更新ファイルを構成し、そのファイルで次の操作を行うだけです。

<?xml version="1.0"?>
<layout>
    <checkout_cart_index>
        <action method="setTemplate" block="checkout.cart.shipping" ifconfig="dropdownshipping/settings/enable">
            <template>beckin/dropdownshipping/drop_down_shipping.phtml</template>
        </action>
        <action method="addCss" block="head" ifconfig="dropdownshipping/settings/enable">
            <template>css/beckin/dropdownshipping.css</template>
        </action>
    </checkout_cart_index>
</layout>

モジュールもこのレイアウトで構成されている限り、<depends />XMLMage_Checkout更新はコア命令の後にマージされ、コア テンプレートをオーバーライドします。

あなたが取ったアプローチを取る唯一の理由は、レンダリングの直前にテンプレートがあなたのモジュールのテンプレートに設定されることを徹底的に強制することです. ... 議論の余地があります。

于 2012-12-16T15:58:42.110 に答える