Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
自定义Magento扩展启用和禁用不工作_Magento_Module_Block_Adminhtml - Fatal编程技术网

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

自定义Magento扩展启用和禁用不工作,magento,module,block,adminhtml,Magento,Module,Block,Adminhtml,我只是试图构建一个扩展,如果启用它,它将用我自己的模板文件覆盖原始的cart/shipping.phtml文件 当我单击Enable时,它不会启用扩展。我知道如果我手动更改布局块主题,扩展实际上是b/c工作的。然而,我不想那样做。你能看一下我的代码,让我知道我做错了什么吗?我假设这与我的块文件不正确有关。另外,如果你看到了什么问题以及如何修复它,你能告诉我如果启用了扩展名,如何为扩展名设置CSS文件吗 以下是我的所有文件: etc/config.xml <?xml version="1.0

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

当我单击Enable时,它不会启用扩展。我知道如果我手动更改布局块主题,扩展实际上是b/c工作的。然而,我不想那样做。你能看一下我的代码,让我知道我做错了什么吗?我假设这与我的块文件不正确有关。另外,如果你看到了什么问题以及如何修复它,你能告诉我如果启用了扩展名,如何为扩展名设置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;
}

}

对于检查布尔配置数据,使用它更合适。在本例中,有一个钩子可以完全在布局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_签出上也配置了,这个布局XML更新就会在core指令之后合并,从而覆盖core模板


采用您所采用的方法的唯一原因是,完全强制在呈现之前将模板设置为模块的模板,从而覆盖任何潜在冲突的布局XML指令,假设没有缓存命中,这是一种。。。有争议。

对于检查布尔配置数据,更适合使用。在本例中,有一个钩子可以完全在布局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_签出上也配置了,这个布局XML更新就会在core指令之后合并,从而覆盖core模板


采用您所采用的方法的唯一原因是,完全强制在呈现之前将模板设置为模块的模板,从而覆盖任何潜在冲突的布局XML指令,假设没有缓存命中,这是一种。。。有争议。

谢谢@benmarks!那么,我是否应该删除我制作的装运块,并将其添加到etc/config.xml文件或模板layout.xml文件中,就像我在etc/config.xml文件中注释掉的一样?你就是那个人!!非常感谢你!我不知道您可以通过添加ifconfig=dropdownshipping/settings/enable来控制布局。你太棒了!非常感谢!!谢谢@benmarks!那么,我是否应该删除我制作的装运块,并将其添加到etc/config.xml文件或模板layout.xml文件中,就像我在etc/config.xml文件中注释掉的一样?你就是那个人!!非常感谢你!我不知道您可以通过添加ifconfig=dropdownshipping/settings/enable来控制布局。你太棒了!非常感谢!!