控制ECSHOP采购量,在很多情况下是必要的,当你有特殊要求时,控制量尤为重要。需要添加一个字段列表中的商品“gc”控制采购量
首先,你需要购买的时候,提示输入框,告诉用户,你需要购买多少。第二,需要改变采购量在购物车,您还需要控制。
1:详细页面控制。
- 在flow.php里面addto_cart中,加入以下代码,控制购买.
- $gc = $db -> getOne(“select gc from “.$ecs->table(‘goods’).” where goods_id = “.$goods ->goods_id);
- if ($goods->number%$gc) {
- $result[‘error’] = 1;
- $result[‘message’] = “购买数量必须输入{$gc}的倍数”;
- }
- 2:在common.js中增加函数
- function addToCart1(goodsId, parentId)
- {
- var goods = new Object();
- var spec_arr = new Array();
- var fittings_arr = new Array();
- var number = 1;
- var t = “number”+goodsId;
- number = document.getElementById(“number”+goodsId).value;
- goods.spec = spec_arr;
- goods.goods_id = goodsId;
- goods.number = number;
- goods.parent = (typeof(parentId) == “undefined”) ? 0 : parseInt(parentId);
- Ajax.call(‘flow.php?step=add_to_cart’, ‘goods=’ + goods.toJS**tring(), addToCartResp**e, ‘POST’, ‘JSON’);
- }
- 2:控制列表页面的购买.
- 在列表页面中,增加一个框.
- <form action=”javascript:addToCart1({$goods.goods_id})” method=”post” name=”ECS_FORMBUY{$goods.goods_id}” id=”ECS_FORMBUY{$goods.goods_id}” >
- 购买数量:<input name=”number{$goods.goods_id}” type=”text” id=”number{$goods.goods_id}” value=”1″ size=”4″ class=”formBorder”/><br />
- <a href=”javascript:addToCart1({$goods.goods_id})”><img src=”images/but_buy.jpg”></a>
- <a href=”javascript:;” id=”compareLink”quotes”}’,'{$goods.type}’)”><img src=”images/but_comp.jpg”></a></form>
- 调用addToCart1函数.
- 3:推荐页面
- 在common.js中增加函数addToCart2
- function addToCart2(goodsId, parentId)
- {
- var goods = new Object();
- var spec_arr = new Array();
- var fittings_arr = new Array();
- var number = 1;
- var t = “number”+goodsId;
- number = document.getElementById(“number_”+goodsId).value;
- goods.spec = spec_arr;
- goods.goods_id = goodsId;
- goods.number = number;
- goods.parent = (typeof(parentId) == “undefined”) ? 0 : parseInt(parentId);
- Ajax.call(‘flow.php?step=add_to_cart’, ‘goods=’ + goods.toJS**tring(), addToCartResp**e, ‘POST’, ‘JSON’);
- }
- 在recommend_new.lbi,recommend_best.lbi等页面中,需要增加输入框.调用次函数.
- <form action=”javascript:addToCart2({$goods.id})” method=”post” name=”ECS_FORMBUY_{$goods.id}” id=”ECS_FORMBUY_{$goods.id}” >
- 购 买数量:<input name=”number_{$goods.id}” type=”text” id=”number_{$goods.id}” value=”1″ size=”4″ class=”formBorder”/><br /><a href=”javascript:addToCart2({$goods.id})”><img src=”images/but_buy.jpg”></a></form>
- 最后完成了购买数量的控制。