首页建站经验 ecshop购物车AJAX更新数量与价格-最模板最完整版

ecshop购物车AJAX更新数量与价格-最模板最完整版

ECShop版本:V2.7.3涉及修改文件:1. themes/default/flow.dwt2. flow.php详细修改记录:1. themes/default/flow.dwt第一步:搜索,共有两处,这里取第一处(53行左右),将其下一行的修改成…

ECShop版本:V2.7.3

ecshop购物车AJAX更新数量与价格-最模板最完整版

涉及修改文件:

1. themes/default/flow.dwt

2. flow.php

详细修改记录:

1. themes/default/flow.dwt

第一步:搜索

共有两处,这里取第一处(53行左右),将其下一行的修改成

第二步:搜索

只有一处(91行左右),将其修改为

第三步:搜索

{$goods.subtotal}

只有一处(96行左右),将其修改为

{$goods.subtotal}

第四步:搜索

{$your_discount}

共两处,这里取第一处(108行左右,2.7.2版在110行左右),将其上一行

修改为

第五步:搜索

只有一处(124行左右,2.7.2版在126行左右),在该行前面添加如下代码

2.flow.php

第一步:搜索

elseif ($_REQUEST['step'] == 'update_cart')

只有一处(1800行左右),在其前面添加如下代码

/*------------------------------------------------------*/

//-- Ajax更新购物车add 20120118

/*------------------------------------------------------*/

elseif ($_REQUEST['step']== 'ajax_update_cart')

{

require_once(ROOT_PATH .'includes/cls_json.php');

$json = new JSON();

$result = array('error' => 0, 'message'=> '');

if (isset($_POST['rec_id']) &&isset($_POST['goods_number']))

{

$key = $_POST['rec_id'];

$val = $_POST['goods_number'];

$val = intval(make_semiangle($val));

if ($val <= 0 &&!is_numeric($key))

{

$result['error'] = 99;

$result['message'] = '';

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

}

//查询:

$sql = "SELECT `goods_id`, `goods_attr_id`,`product_id`, `extension_code` FROM" .$GLOBALS['ecs']->table('cart').

" WHERE rec_id='$key' AND session_id='" . SESS_ID . "'";

$goods =$GLOBALS['db']->getRow($sql);

$sql = "SELECT g.goods_name,g.goods_number ".

"FROM ".$GLOBALS['ecs']->table('goods'). " AS g, ".

$GLOBALS['ecs']->table('cart'). " AS c ".

"WHERE g.goods_id =c.goods_id AND c.rec_id = '$key'";

$row = $GLOBALS['db']->getRow($sql);

//查询:系统启用了库存,检查输入的商品数量是否有效

if(intval($GLOBALS['_CFG']['use_storage']) > 0 &&$goods['extension_code'] != 'package_buy')

{

if ($row['goods_number'] < $val)

{

$result['error'] = 1;

$result['message'] =sprintf($GLOBALS['_LANG']['stock_insufficiency'], $row['goods_name'],$row['goods_number'], $row['goods_number']);

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

}

/* 是货品*/

$goods['product_id'] = trim($goods['product_id']);

if (!empty($goods['product_id']))

{

$sql = "SELECT product_number FROM " .$GLOBALS['ecs']->table('products'). " WHERE goods_id = '" . $goods['goods_id'] . "' AND product_id = '" .$goods['product_id'] . "'";

$product_number =$GLOBALS['db']->getOne($sql);

if ($product_number < $val)

{

$result['error'] = 2;

$result['message'] =sprintf($GLOBALS['_LANG']['stock_insufficiency'], $row['goods_name'],

$product_number['product_number'], $product_number['product_number']);

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

}

}

}

elseif (intval($GLOBALS['_CFG']['use_storage'])> 0 && $goods['extension_code'] == 'package_buy')

{

if(judge_package_stock($goods['goods_id'], $val))

{

$result['error'] = 3;

$result['message'] =$GLOBALS['_LANG']['package_stock_insufficiency'];

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

}

}

/* 查询:检查该项是否为基本件 以及是否存在配件*/

/* 此处配件是指添加商品时附加的并且是设置了优惠价格的配件 此类配件都有parent_idgoods_number为1 */

$sql = "SELECT b.goods_number,b.rec_id

FROM ".$GLOBALS['ecs']->table('cart') . " a, ".$GLOBALS['ecs']->table('cart') . " b

WHERE a.rec_id = '$key'

AND a.session_id = '" .SESS_ID . "'

AND a.extension_code <>'package_buy'

AND b.parent_id = a.goods_id

AND b.session_id = '" .SESS_ID . "'";

$offers_accessories_res =$GLOBALS['db']->query($sql);

//订货数量大于0

if ($val > 0)

{

/* 判断是否为超出数量的优惠价格的配件 删除*/

$row_num = 1;

while ($offers_accessories_row =$GLOBALS['db']->fetchRow($offers_accessories_res))

{

if ($row_num > $val)

{

$sql = "DELETE FROM" . $GLOBALS['ecs']->table('cart') .

" WHERE session_id = '" . SESS_ID . "' " .

"AND rec_id ='" . $offers_accessories_row['rec_id'] ."' LIMIT 1";

$GLOBALS['db']->query($sql);

}

$row_num ++;

}

/* 处理超值礼包*/

if ($goods['extension_code'] =='package_buy')

{

//更新购物车中的商品数量

$sql = "UPDATE ".$GLOBALS['ecs']->table('cart').

" SET goods_number= '$val' WHERE rec_id='$key' AND session_id='" . SESS_ID . "'";

}

/* 处理普通商品或非优惠的配件*/

else

{

$attr_id = empty($goods['goods_attr_id']) ? array(): explode(',', $goods['goods_attr_id']);

$goods_price =get_final_price($goods['goods_id'], $val, true, $attr_id);

//更新购物车中的商品数量

$sql = "UPDATE ".$GLOBALS['ecs']->table('cart').

" SET goods_number= '$val', goods_price = '$goods_price' WHERE rec_id='$key' AND session_id='" . SESS_ID . "'";

}

}

//订货数量等于0

else

{

/* 如果是基本件并且有优惠价格的配件则删除优惠价格的配件*/

while ($offers_accessories_row =$GLOBALS['db']->fetchRow($offers_accessories_res))

{

$sql = "DELETE FROM ". $GLOBALS['ecs']->table('cart') .

" WHERE session_id= '" . SESS_ID . "' " .

"AND rec_id ='" . $offers_accessories_row['rec_id'] ."' LIMIT 1";

$GLOBALS['db']->query($sql);

}

$sql = "DELETE FROM ".$GLOBALS['ecs']->table('cart').

" WHERE rec_id='$key' AND session_id='" .SESS_ID. "'";

}

$GLOBALS['db']->query($sql);

/* 删除所有赠品*/

$sql = "DELETE FROM " .$GLOBALS['ecs']->table('cart') . " WHERE session_id = '" .SESS_ID."' AND is_gift <> 0";

$GLOBALS['db']->query($sql);

$result['rec_id'] = $key;

$result['goods_number'] = $val;

$result['goods_subtotal'] = '';

$result['total_desc'] = '';

$result['cart_info'] =insert_cart_info();

/* 计算合计*/

$cart_goods = get_cart_goods();

foreach ($cart_goods['goods_list'] as$goods )

{

if ($goods['rec_id'] == $key)

{

$result['goods_subtotal'] =$goods['subtotal'];

break;

}

}

$shopping_money =sprintf($_LANG['shopping_money'], $cart_goods['total']['goods_price']);

$market_price_desc = sprintf($_LANG['than_market_price'],$cart_goods['total']['market_price'],$cart_goods['total']['saving'], $cart_goods['total']['save_rate']);

/* 计算折扣*/

$discount = compute_discount();

$favour_name = empty($discount['name'])? '' : join(',', $discount['name']);

$your_discount =sprintf($_LANG['your_discount'], $favour_name,price_format($discount['discount']));

if ($discount['discount'] > 0)

{

$result['total_desc'] .=$your_discount . '
';

}

$result['total_desc'] .=$shopping_money;

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

}

else

{

$result['error'] = 100;

$result['message'] = '';

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

}

}

本文来自网络,不代表1号站长-站长学院|资讯交流平台立场。转载请注明出处: https://www.1cn.cc/jianzhan/jingyan/17888.html
上一篇php目录拷贝实现方法
下一篇 Discuz(Can not write to cache files)有关问题解决办法汇总
admin

作者: admin

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

为您推荐

评论列表()

    联系我们

    联系我们

    0898-88888888

    在线咨询: QQ交谈

    邮箱: email@wangzhan.com

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

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

    微信扫一扫关注我们

    关注微博
    返回顶部