自定义Magento扩展程序.如何添加选项以启用或禁用它? [英] Custom Magento Extension. How can I add the option to enable or disable it?
问题描述
在这里,我终于有了我的第一个扩展程序,谢谢大家!我设法将扩展名也添加为管理区域中的选项卡.我有一个菜单,显示启用或禁用.我想使此功能起作用,从而使客户可以通过此扩展程序获得更多控制权.在提到它之前,我知道您可以在高级菜单下启用和禁用扩展.但是,大多数Magento客户不是.我想直接将此添加到我的扩展程序中.
I have finally got my first extension built thanks to everyone here! I managed to get the extension added as a tab in the admin area as well. I have a menu that says enable or disable. I would like to make this function work giving the customer more control with this extension. Before it is mentioned, I am aware that you can enable and disable extensions under the advanced menu. However, most Magento customers are not. I would like to add this directly to my extension.
如果启用了该模块,我想使用自己的自定义送货模板覆盖位于checkout/cart/shipping.phtml中的shipping.phtml文件.
If the module is enabled I would like to overide the shipping.phtml file located in the checkout/cart/shipping.phtml with my own custom shipping template.
- 如何使我的启用或禁用下拉框起作用?下面是我的代码:
etc/system.xml
etc/system.xml
<?xml version="1.0"?>
<config>
<tabs>
<beckinconfig translate="label" module="dropdownshipping">
<label>Beckin Extensions</label>
<sort_order>100</sort_order>
</beckinconfig>
</tabs>
<sections>
<dropdownshipping translate="label" module="dropdownshipping">
<label>Drop Down Shipping Options</label>
<tab>beckinconfig</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>
<general>
<label>General</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>
</general>
</groups>
</dropdownshipping>
</sections>
</config>
etc/config.xml
etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Beckin_DropDownShipping><version>1.0.0</version></Beckin_DropDownShipping>
</modules>
<global>
<blocks>
<beckin_dropdownshipping>
<class>Beckin_DropDownShipping_Block</class>
</beckin_dropdownshipping>
</blocks>
<helpers>
<beckin_dropdownshipping>
<class>Beckin_DropDownShipping_Helper</class>
</beckin_dropdownshipping>
</helpers>
</global>
<frontend>
<layout>
<updates>
<beckin>
<file><!-- beckin_dropdownshipping.xml --></file>
</beckin>
</updates>
</layout>
<routers>
<dropdownshipping>
<use>standard</use>
<args>
<module>Beckin_DropDownShipping</module>
<frontName>dropdownshipping</frontName>
</args>
</dropdownshipping>
</routers>
</frontend>
<adminhtml>
<acl>
<resources>
<admin>
<children>
<system>
<children>
<config>
<children>
<dropdownshipping_options>
<title>Beckin Drop Down Shipping Extension</title>
</dropdownshipping_options>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</adminhtml>
</config>
Helper/Data.php
Helper/Data.php
<?php
class Beckin_DropDownShipping_Helper_Data extends Mage_Core_Helper_Abstract
{
}
Block/Cart/Shipping.php
Block/Cart/Shipping.php
<?php
class Beckin_DropDownShipping_Block_Cart_Shipping extends Mage_Checkout_Block_Cart_Shipping
{
protected function _construct()
{
if(Mage::getStoreConfig('beckin/dropdownshipping_options/enable', Mage::app()->getStore()->getId()){
{
$this->setTemplate('Beckin/dropdownshipping/drop_down_shipping.phtml');
}
else
{
$this->setTemplate('checkout/cart/shipping.phtml');
}
}
}
感谢您提供的任何帮助!!当我进入扩展程序所在的系统/配置部分时,我现在得到一个空白的管理页面.我敢肯定,这很简单,我很想念.除了我认为不相关的模板文件之外,我还包含了上面正在使用的所有文件.你能发现我的错误吗?我希望它会显示一个错误,而不是页面空白:(
Thanks for any help provided!! I am getting a blank admin page now when I go to the system/config section where my extension is located. I am sure it is something simple that I am missing. I have included every file above that I am using except for the template file which I believe is irrelevant. Can you spot my error? I wished it would show me an error instead of the page being blank :(
推荐答案
不确切知道模块的功能以及在何处以及如何加载模块.假设它不是自定义运输扩展名.您可以
Without known exactly what your module does and where and how your loading it. Assuming that it is not a custom shipping extension. You could do
例如. 1
if((Mage::getStoreConfig('deckin/dropdownshipping_options/beckin_enable', Mage::app()->getStore()->getId()){
module enable/display .phtml
assuming that beckin_enable value are 0 or 1
}
我不确定100%的含义是"...模板xml文件,用于设置模板以覆盖shipping.phtml文件..." ` 您可能需要查找并重写为运输设置模板文件的块结构
I'm not 100% sure what you mean by '... the template xml file to set the template to override the shipping.phtml file ...' ` You may need to find and rewrite the block construct that set the template file for the shipping
例如. 2
protected function _construct()
{
if(Mage::getStoreConfig('deckin/dropdownshipping_options/beckin_enable', Mage::app()->getStore()->getId()){
$this->setTemplate('.../my_custom_shipping.phtml');
}
else{
$this->setTemplate('.../regular_shipping.phtml');
}
}
此外,您无需为是/否创建自己的源模型",magento预先构建了该模型
Also, You don't need to create you own 'source model' for yes/no, magento have it pre-built
<beckin_enable>
....
<source_model>dropdownshipping/enable</source_model>
...
</beckin_enable>
你本可以做到的
<beckin_enable>
....
<source_model>adminhtml/system_config_source_yesno</source_model>
...
</beckin_enable>
这篇关于自定义Magento扩展程序.如何添加选项以启用或禁用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!