首页建站经验 ecshop购物车无刷新更新

ecshop购物车无刷新更新

ecshop的购物车使用是相当的不方便.ecshop购物车一旦加入了商品,就必须点更新数量的按扭才能够更新.这样对ecshop使用者相当的不方便。我们将结合ecshop ajax的思路。来讲讲用e…

ecshop的购物车使用是相当的不方便.ecshop购物车一旦加入了商品,就必须点更新数量的按扭才能够更新.这样对ecshop使用者相当的不方便。我们将结合ecshop ajax的思路。来讲讲用ecshop的ajax无刷新更新购物车.

1:首先要包含js/shopping_flow.js 该文件主要是针对ecshop购买流程控制的js.我们将增加以下函数.

function submit_update_cart(rec_id){

var goods_number = document.getElementById("goods_number_"+rec_id).value;

Ajax.call('flow.php?step=ajax_update_cart', 'goods_number=' + goods_number+'&rec_id='+rec_id, submit_update_cartResponse_cart, 'GET', 'JSON');

}

2:在flow.dwt中。我们要修改input输入框.

3:在ecshop的购物车函数中。什么json来结合ecshop ajax处理更新结果.部分程序如下

include_once('includes/cls_json.php');

$result = array('error' => '', 'content' => '', 'fanliy_number' => '0', 'rec_id' => '');

$json = new JSON();

/* AJAX修改购物车 */

$rec_id = $_REQUEST['rec_id']; //购物车ID

$goods_number = $_REQUEST['goods_number'];//

/* 判断库存 */

$num = $db -> getOne("select g.goods_number from ".$ecs->table('goods')." g ,".$ecs->table('cart')." c where c.rec_id = '$rec_id' and g.goods_id = c.goods_id ");

if($goods_number > $num){

$goods_number = $num;

$result['error'] = 1;

$result['fanliy_number']= $num;

$result['rec_id'] = $rec_id;

$result['content'] = '该商品库存不足'.$goods_number." 件,只有".$num."件";

die($json->encode($result));

}

/* 修改商品购物车 */

$sql = "update ".$ecs->table('cart')." set goods_number = '".$goods_number."' where rec_id = '".$rec_id."' and session_id = '" . SESS_ID . "' ";

$db -> query($sql);

4:通过flow.php中的php.返回更新数量后的结果.

function submit_update_cartResponse_cart(result){

if(result.error == '1'){

document.getElementById("goods_number_"+result.rec_id).value = result.fanliy_number;

alert(result.content)

}else{

var layer = document.getElementById("xianshi_price");

layer.innerHTML = (typeof result == "object") ? result.content : result;

}

}

通过以上ecshop二次开发例子,我们完成了ecshop购物车无刷新更新。

本文来自网络,不代表1号站长-站长学院|资讯交流平台立场。转载请注明出处: https://www.1cn.cc/jianzhan/jingyan/18715.html
上一篇WordPress将选中文字转发到微博的方法
下一篇 wordpress分类页面的meta描述和关键词的修改方法
admin

作者: admin

这里可以再内容模板定义一些文字和说明,也可以调用对应作者的简介!或者做一些网站的描述之类的文字或者HTML!

为您推荐

评论列表()

    联系我们

    联系我们

    0898-88888888

    在线咨询: QQ交谈

    邮箱: email@wangzhan.com

    工作时间:周一至周五,9:00-17:30,节假日休息

    关注微信
    微信扫一扫关注我们

    微信扫一扫关注我们

    关注微博
    返回顶部