[英]Custom Magento Extension. How can I add the option to enable or disable it?
我终于有了第一个扩展程序,感谢这里的每个人! 我设法将扩展名也添加为管理区域中的选项卡。 我有一个菜单,显示启用或禁用。 我想使此功能起作用,以便通过此扩展为客户提供更多控制权。 在提到它之前,我知道您可以在高级菜单下启用和禁用扩展。 但是,大多数Magento客户不是。 我想直接将此添加到我的扩展程序中。
如果启用了该模块,我想使用自己的自定义送货模板覆盖位于checkout / cart / shipping.phtml中的shipping.phtml文件。
等/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>
等/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>
帮手/Data.php
<?php
class Beckin_DropDownShipping_Helper_Data extends Mage_Core_Helper_Abstract
{
}
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');
}
}
}
感谢您提供的任何帮助! 当我进入扩展程序所在的system / config部分时,我现在得到一个空白的管理页面。 我确信这很简单,我很想念。 除了我认为不相关的模板文件之外,我还包含了上面使用的所有文件。 你能发现我的错误吗? 我希望它会显示一个错误,而不是页面空白:(
不知道您的模块的确切功能以及在何处以及如何加载它。 假设它不是自定义运输扩展名。 你可以做
例如。 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文件...”`您可能需要查找并重写设置模板文件的块结构用于运输
例如。 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预先构建了它
<beckin_enable>
....
<source_model>dropdownshipping/enable</source_model>
...
</beckin_enable>
你本来可以做的
<beckin_enable>
....
<source_model>adminhtml/system_config_source_yesno</source_model>
...
</beckin_enable>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.