ecshop 促销活动,如每人只限购1件

控制ECSHOP的购买数量,在很多时候是必须的,而且当你有特别的需求的时候,控制数量显得格外重要。需要在goods表中增加个字段"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.toJSONString(), addToCartResponse, '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.toJSONString(), addToCartResponse, '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>

    最后完成了购买数量的控制。

posted on 2012-10-14 19:16  ECshop商城二次开发博客  阅读(1899)  评论(0编辑  收藏  举报

导航