客户提出的需求是,想实现购物车满多少金额就赠送一个礼品,再满更多金额则赠送另外一个礼品的功能。赠送礼品的功能由gifts插件实现,该插件可以定义礼品规则,然后不管商品原先的价格,在加入购物车的时候主动把该商品价格设置为规则设定的价格。所以问题就集中在怎么实现客户想要的自定义金额。在这里我才用了新增 System configuration自定义配置项,由于要和gifts插件结合,所以我就把新增的配置放在gifts模块中,具体代码如下:
路径:app\code\community\Belvg\Gifts\etc\system.xml(添加新增字段)
app\code\community\Belvg\Gifts\etc\config.xml(设置模块在后台配置里面的显示权限)
代码:
<min_send_price>
<label>Minimum send price of cart</label>
<frontend_type>text</frontend_type>
<validate>validate-digits</validate>
<sort_order>8</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<comment>Set 0 or leave empty if no limitations</comment>
</min_send_price>
<max_send_price>
<label>Maximum send price of cart</label>
<frontend_type>text</frontend_type>
<validate>validate-digits</validate>
<sort_order>9</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<comment>Set 0 or leave empty if no limitations</comment>
</max_send_price>
具体解析(magento):
System.xml配置讲解
<tabs>为配置模块,展现为Configuration页面左侧块,如GENERAL, CATALOG等,此处是ETAM BLOG, Magento在显示时会将英文label转化为大写
<sections>为配置模块下的菜单项,一个section对应一个页面,如没有配置ACL,则magento会将页面跳转至404 Not Found
<groups>对应一个section页面中可折叠的配置组,其中包括一个或多个配置项
<fields>配置组中的配置项定义
<frontend_type>只有在fileds中才有意义,定义了该配置项对应的HTML控件类型
config.xml中acl配置讲解
<adminhtml>后台配置块
<acl>ACL配置块
<children>URI路径分隔,如admin/system_config,则分为<admin><children><system><children><config>
<etam_blog_options>对应system.xml中的section名称
<title>配置页面中的标题
最终效果如下图: