ecshop微信商城
  官方微博: 腾讯  
首页 > ECSHOP教程 > ECSHOP二次开发 > ECSHOP二次开发教程 > ECSHOP商品购买数量增加加减按钮插件

ECSHOP商品购买数量增加加减按钮插件

ECSHOP教程 / ecshop 教程网(www.ecshop119.com) 2013-11-16

ecshop商品页购买数量加减按钮ecshop购物车页加减按钮插件

默认模版为例详细教程:

找到flow.php里的如下代码

elseif ($_REQUEST['step'] == 'update_cart')
    {
        if (isset($_POST['goods_number']) && is_array($_POST['goods_number']))
        {
            flow_update_cart($_POST['goods_number']);
        }
        show_message($_LANG['update_cart_notice'], $_LANG['back_to_cart'], 'flow.php');
        exit;
    }  

修改成:

elseif ($_REQUEST['step'] == 'update_cart')
{
    if (isset($_POST['goods_number']) && is_array($_POST['goods_number']))
    {
        flow_update_cart($_POST['goods_number']);
    }
ecs_header("Location: flow.php?step=cart\n"); 
    show_message($_LANG['update_cart_notice'], $_LANG['back_to_cart'], 'flow.php');
    exit;
}  

打开:goods.dwt

{* 包含脚本文件 *}
{insert_scripts files='common.js'}下面这段:

<script type="text/javascript">
function $id(element) {
  return document.getElementById(element);
}
//切屏--是按钮,_v是内容平台,_h是内容库
function reg(str){
  var bt=$id(str+"_b").getElementsByTagName("h2");
  for(var i=0;i<bt.length;i++){
    bt[i].subj=str;
    bt[i].pai=i;
    bt[i].style.cursor="pointer";
    bt[i].onclick=function(){
      $id(this.subj+"_v").innerHTML=$id(this.subj+"_h").getElementsByTagName("blockquote")[this.pai].innerHTML;
      for(var j=0;j<$id(this.subj+"_b").getElementsByTagName("h2").length;j++){
        var _bt=$id(this.subj+"_b").getElementsByTagName("h2")[j];
        var ison=j==this.pai;
        _bt.className=(ison?"":"h2bg");
      }
    }
  }
  $id(str+"_h").className="none";
  $id(str+"_v").innerHTML=$id(str+"_h").getElementsByTagName("blockquote")[0].innerHTML;
}

</script>

修改成:

<script type="text/javascript">
function $id(element) {
  return document.getElementById(element);
}
//切屏--是按钮,_v是内容平台,_h是内容库
function reg(str){
  var bt=$id(str+"_b").getElementsByTagName("h2");
  for(var i=0;i<bt.length;i++){
    bt[i].subj=str;
    bt[i].pai=i;
    bt[i].style.cursor="pointer";
    bt[i].onclick=function(){
      $id(this.subj+"_v").innerHTML=$id(this.subj+"_h").getElementsByTagName("blockquote")[this.pai].innerHTML;
      for(var j=0;j<$id(this.subj+"_b").getElementsByTagName("h2").length;j++){
        var _bt=$id(this.subj+"_b").getElementsByTagName("h2")[j];
        var ison=j==this.pai;
        _bt.className=(ison?"":"h2bg");
      }
    }
  }
  $id(str+"_h").className="none";
  $id(str+"_v").innerHTML=$id(str+"_h").getElementsByTagName("blockquote")[0].innerHTML;
}

function del(){
        var num = document.getElementById("number");
       
        var n = parseInt(num.value);
       
        if(n-1<=0){
                alert("必须选择一个商品");
        }else{
                num.value = n-1;
        }
}
function add(){
       
        var num = document.getElementById("number");
       
        var n = parseInt(num.value);
       
        num.value = n+1;
       
}

</script>

 

 搜索:

<dd>
       <strong>{$lang.number}:</strong>
        <input name="number" type="text" id="number" value="1" size="4" onblur="changePrice()" style="border:1px solid #ccc; "/>
       </dd>

修改成:

<table>
          <tr>
            <td valign="middle" height="40" width="80" align="right"><font class="shop">{$lang.number}:</font> </td>
            <td valign="middle"><img src="images/jian.gif" style="display:block;" onclick="del()" /> </td>
            <td><input name="number" type="text" id="number" value="1" size="4" onblur="changePrice()" style="border:1px solid #ccc; height:25px; width:30px; text-align:center; "/></td>
            <td><img src="images/jia.gif" style="display:block;" onclick="add()" /> </td>
          </tr>
        </table>

 

打开:style.css文件,底部下面添加:

.goods_cut {
background: url("./images/yy.gif") no-repeat scroll 0 0 transparent;
border: 0 none;
cursor: pointer;
display: block;
float: left;
font-size: 0;
height: 15px;
line-height: 0;margin: 8px 3px 0;
width: 15px;
}
input.goodsBuyBox, input.number {
border: 1px solid #DDDDDD;
float: left;
font-size: 10px;
height: 18px;
line-height: 18px;
margin: 5px 6px 0;
padding: 0;
text-align: center;
width: 32px;
}
.goods_add {
background: url("./images/yy.gif") no-repeat scroll 0 -15px transparent;
border: 0 none;
cursor: pointer;
display: block;
float: left;
font-size: 0;
height: 15px;
line-height: 0;
margin: 8px 3px 0;
width: 15px;
}
.goods_number_tit{
    display: block;
    background:none;
    width:60px;
    height:25px;
    line-height:22px;
    float: left;
}  

 

 

图片放到模板目录:

 

 

新手如果没有修改过模板直接覆盖下面附件就可以:

ecshop商品页购买数量加减按钮插件:

下载:www.ecshop119.com/moban-318.html

 

二.购物车页面

打开:flow.dwt

{* 包含脚本文件 *}
{insert_scripts files='common.js,shopping_flow.js'}

<script language="javascript" type="text/javascript">
                function goods_cut($val){
                    var num_val=document.getElementById('number'+$val);
                    var new_num=num_val.value;
                    if(isNaN(new_num)){alert('请输入数字');return false}
                    var Num = parseInt(new_num);
                    if(Num>1)Num=Num-1;
                    num_val.value=Num;
                    document.getElementById('updatecart').click();
                }
                function goods_add($val){
                    var num_val=document.getElementById('number'+$val);
                    var new_num=num_val.value;
                    if(isNaN(new_num)){alert('请输入数字');return false}
                    var Num = parseInt(new_num);
                    Num=Num+1;
                    num_val.value=Num;
                    document.getElementById('updatecart').click();
                }
            </script>

搜索:

<input type="text" name="goods_number[{$goods.rec_id}]" id="goods_number_{$goods.rec_id}" value="{$goods.goods_number}" size="4" class="inputBg" style="text-align:center " onkeydown="showdiv(this)"/> 

修改成:

<span class="goods_cut" onclick="goods_cut('{$goods.rec_id}');"></span>
 
                                   <input type="text"
name="goods_number[{$goods.rec_id}]" id="number{$goods.rec_id}"
value="{$goods.goods_number}" size="4" class="number"
onblur="if(isNaN(this.value)){alert('请输入数字');return
false}else{document.getElementById('updatecart').click();}"
title="{$lang.goods_number_tip}"/>
                                    <span class="goods_add" onclick="goods_add('{$goods.rec_id}');"></span>

 

3.搜索:

$lang.update_cart
<input name="submit" type="submit" class="bnt_blue_1" value="{$lang.update_cart}" /> 
修改成:     

<input name="submit" type="submit" id="updatecart" value="{$lang.update_cart}" class="btn_s3"/>

打开:style.css文件,底部下面添加

.goods_cut {
background: url("./images/yy.gif") no-repeat scroll 0 0 transparent;
border: 0 none;
cursor: pointer;
display: block;
float: left;
font-size: 0;
height: 15px;
line-height: 0;margin: 8px 3px 0;
width: 15px;
}
input.goodsBuyBox, input.number {
border: 1px solid #DDDDDD;
float: left;
font-size: 10px;
height: 18px;
line-height: 18px;
margin: 5px 6px 0;
padding: 0;
text-align: center;
width: 32px;
}
.goods_add {
background: url("./images/yy.gif") no-repeat scroll 0 -15px transparent;
border: 0 none;
cursor: pointer;
display: block;
float: left;
font-size: 0;
height: 15px;
line-height: 0;
margin: 8px 3px 0;
width: 15px;
}
.goods_number_tit{
    display: block;
    background:none;
    width:60px;
    height:25px;
    line-height:22px;
    float: left;
}  

5.图片放到模板目录:

 

新手使用的是默认模板可以直接覆盖下面附件:

ecshop购物车加减插件下载:www.ecshop119.com/moban-318.html

转载请注明:ECshop119模板屋-ECshop教程网(全国最专业的ECSHOP插件制作商-专业ECSHOP二次开发)

帮助目录

在线反馈

可以将问题或建议反馈给我们。

提交在线反馈

与网友交流ECSHOP开发修改。

加入QQ群交流