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>

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值