繁体   English   中英

自定义Magento扩展启用和禁用不工作

[英]Custom Magento Extension Enable and Disable not working

我只是想构建一个扩展,如果它被启用它将覆盖原始的cart / shipping.phtml文件与我自己的模板文件..

当我单击“启用”时,它不会启用扩展。 我知道如果手动更改我的布局块主题,扩展实际上是b / c工作。 但是,我不想这样做。 你能看看我的代码,让我知道我做错了什么吗? 我假设它与我的块文件不正确有关。 PS如果你看到有什么问题以及如何修复它你也可以告诉我如何为扩展设置一个CSS文件,如果它已启用?

这是我的所有文件:)

等/ 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>

等/的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>

助手/ Data.php

<?php
class Module_Name_Helper_Data extends Mage_Core_Helper_Abstract
{   

}

块/车/ 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;
}

}

为了检查布尔配置数据,使用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>

只要您的模块在Mage_Checkout上配置了<depends /> ,此布局XML更新将在核心指令之后合并,从而覆盖核心模板。

采取这种方法的唯一理由是彻底强制在渲染之前将模板设置到模块的模板 - 从而覆盖任何潜在的冲突布局XML指令 - 假设没有缓存命中,行为是......有争议的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM