magento helper

模块结构

    app/code/local/App/Shopping/etc  
    app/code/local/App/Shopping/Helper  

etc/config.xml中启用helper

</models>
<helpers>
	<shopping>
		<class>App_Shopping_Helper</class>
	</shopping>
</helpers>  

添加etc/system.xml,然后在管理后台添加配置数据, 系统->配置

<?xml version="1.0"?>
<config>
    <tabs>
        <shopping translate="label" module="shopping">
            <label>The virtualcurrency</label>
            <sort_order>300</sort_order>
        </shopping>
    </tabs>
	<sections>
          <shopping translate="label" module="shopping"> <!-- section shopping 权限标签-->
            <label>显示名称</label>
            <tab>shopping</tab>
            <sort_order>100</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>基本</label>
                    <frontend_type>text</frontend_type>
                    <sort_order>0</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>
                    <fields>
                        <name translate="label">
                            <label>Settings</label>
                        </name>
                        <renmingbi_duidian translate="label">
                            <label>1人民币可以冲值多少</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>0</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </renmingbi_duidian>
                    </fields>
                </settings>
		    </groups>
	    </shopping>
    </sections>
</config>

config.xml中配置权限,否则后台菜单404

</frontend>
<adminhtml>
    <acl>
        <resources>
            <admin>
                <children>
                    <system>
                        <children>
                            <config>
                                <children>
                                    <shopping>
                                        <title>shoping权限</title>
                                    </shopping>
                                </children>
                            </config>
                        </children>
                    </system>
                </children>
            </admin>
        </resources>
    </acl>
</adminhtml>

上面配置好后台就可以看到界面。 helper下的data.php

<?php
class App_Shopping_Helper_Data extends Mage_Core_Helper_Abstract
{   //数据存到core_config_data表中了
	const XML_PATH_RECHARGE_MONEY = 'shopping/settings/renmingbi_duidian';
	public function getCurrencyToMoney($store = null)
	{
		return Mage::getStoreConfig(self::XML_PATH_RECHARGE_MONEY, $store);
	}
}

help怎么调用

Mage::helper('shopping/data')->getCurrencyToMoney();//data为默认,可以不写

Mage::helper('shopping')->getCurrencyToMoney();

App_Shopping_Helper_Data::XML_PATH_RECHARGE_MONEY

 

Magento 后台配置中实现日期选择

<?php

class Glamour_Glscore_Block_Adminhtml_System_Config_Date extends Mage_Adminhtml_Block_System_Config_Form_Field {
    protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) {
        $date = new Varien_Data_Form_Element_Date;
        $format = 'yyyy-MM-dd HH:mm:ss';

        $data = array(
            'name' => $element->getName(),
            'html_id' => $element->getId(),
            'image' => $this->getSkinUrl('images/grid-cal.gif'),
            'time' => true
        );
        $date->setData($data);
        $date->setValue($element->getValue(), $format);
        $date->setFormat('yyyy-MM-dd HH:mm:ss');
        $date->setForm($element->getForm());

        return $date->getElementHtml();
    }
}

在system.xml中使用新的Field类

<start_date translate="label">
    <label>有效期至</label>
    <frontend_type>text</frontend_type>
    <frontend_model>Glamour_Glscore_Block_Adminhtml_System_Config_Date</frontend_model>
    <validate>validate-date</validate>
    <sort_order>4</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>1</show_in_store>
</start_date>

 

你可能感兴趣的:(agent)