[英]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.