控制ECSHOP的購買數量,在不少時候是必須的,並且當你有特別的需求的時候,控制數量顯得格外重要。須要在goods表中增長個字段"gc"控制購買數量 javascript
首先,你須要在購買的時候,提示輸入框,告訴用戶,你必須購買多少.其次,購物車中須要修改購買數量的時候,你也須要控制。 php
1:詳細頁面中控制 java
在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中增長函數 post
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.toJSONString(), addToCartResponse, 'POST', 'JSON');
}
2:控制列表頁面的購買. orm
在列表頁面中,增長一個框.
<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.toJSONString(), addToCartResponse, 'POST', 'JSON');
} ip
在recommend_new.lbi,recommend_best.lbi等頁面中,須要增長輸入框.調用次函數. get
<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> input
最後完成了購買數量的控制。 it