客户需要修改ecshop购物流程。在ecshop中,想实现既可以放在购物车里面,也可以实现直接购买,就是购买方式共存的两种方式.首先,需要在goods.php中增加一个直接购买的按扭.
- <a href="javascript:addToCart1({$goods.goods_id})"><img src="images/add_cart.gif" alt="Add to cart" width="87" height="20" /></a>
- function addToCart1(goodsId, parentId)
- {
-
var goods = new Object();
-
var spec_arr = new Array();
-
var fittings_arr = new Array();
-
var number = 1;
-
var formBuy = document.forms['ECS_FORMBUY'];
-
// 检查是否有商品规格
-
if (formBuy)
-
{
-
spec_arr = getSelectedAttributes(formBuy);
-
if (formBuy.elements['number'])
-
{
-
number = formBuy.elements['number'].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_cart1', 'goods=' + goods.toJSONString(), addToCartResponse1, 'POST', 'JSON');
- }
- function addToCartResponse1(result)
- {
-
if (result.error > 0)
-
{
-
// 如果需要缺货登记,跳转
-
if (result.error == 2)
-
{
-
if (confirm(result.message))
-
{
-
location.href = 'user.php?act=add_booking&id=' + result.goods_id;
-
}
-
}
-
// 没选规格,跳到商品详情页
-
else if (result.error == 9)
-
{
-
location.href = 'goods.php?id=' + result.goods_id;
-
}
-
else
-
{
-
alert(result.message);
-
}
-
}
-
else
-
{
-
var cartInfo = document.getElementByIdx_x('ECS_CARTINFO');
-
if (cartInfo)
-
{
-
cartInfo.innerHTML = result.content;
-
}
-
location.href = 'flow.php';
-
-
}
- }
4:在flow.php中增加直接购买的代码
- elseif ($_REQUEST['step'] == 'add_to_cart1'){
-
include_once('includes/cls_json.php');
-
if (!empty($_REQUEST['goods_id']) && empty($_POST['goods']))
-
{
-
if (!is_numeric($_REQUEST['goods_id']) || intval($_REQUEST['goods_id']) <= 0)
-
{
-
header("location:./\n");
-
}
-
$goods_id = intval($_REQUEST['goods_id']);
-
exit;
-
}
-
$result = array('error' => 0, 'message' => '', 'content' => '', 'goods_id' => '');
-
$json = new JSON;
-
if (empty($_POST['goods']))
-
{
-
$result['error'] = 1;
-
die($json->encode($result));
-
}
-
$goods = $json->decode($_POST['goods']);
-
-
if (empty($goods->spec))
-
{
-
$sql = "SELECT COUNT(*) " .
-
"FROM " . $ecs->table('goods_attr') . " AS ga, " .
-
$ecs->table('attribute') . " AS a " .
-
"WHERE ga.attr_id = a.attr_id " .
-
"AND ga.goods_id = '" . $goods->goods_id . "' " .
-
"AND a.attr_type = 1";
-
if ($db->getOne($sql) > 0)
-
{
-
$result['error'] = 9;
-
$result['goods_id'] = $goods->goods_id;
-
die($json->encode($result));
-
}
-
}
-
-
if ($_CFG['one_step_buy'] == '1')
-
{
-
clear_cart();
-
}
-
else
-
{
-
if (cart_goods_exists($goods->goods_id, $goods->spec, CART_GENERAL_GOODS))
-
{
-
// 商品已经存在于购物车中,返回错误信息
-
$result['error'] = 1;
-
$result['message'] = $_LANG['goods_exists'];
-
die($json->encode($result));
-
}
-
}
-
-
if (!is_numeric($goods->number) || intval($goods->number) <= 0)
-
{
-
$result['error'] = 1;
-
$result['message'] = $_LANG['invalid_number'];
-
}
-
else
-
{
-
-
if (addto_cart($goods->goods_id, $goods->number, $goods->spec, $goods->parent))
-
{
-
if ($_CFG['cart_confirm'] > 2)
-
{
-
$result['message'] = '';
-
}
-
else
-
{
-
$result['message'] = $_CFG['cart_confirm'] == 1 ? $_LANG['addto_cart_success_1'] : $_LANG['addto_cart_success_2'];
-
}
-
$result['content'] = insert_cart_info();
-
$result['one_step_buy'] = $_CFG['one_step_buy'];
-
}
-
else
-
{
-
$result['message'] = $err->last_message();
-
$result['error'] = $err->error_no;
-
$result['goods_id'] = stripslashes($goods->goods_id);
-
}
-
}
-
$result['confirm_type'] = 4;
-
die($json->encode($result));
- }
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。
相关文章
ecshop出现Warning: Invalid argument supplied for foreach()错误2019-02-26
Ecshop 分类页产品列表不同分类调用不同产品属性2018-03-08
ECSHOP商品属性调用到任意页面方法2018-03-01
ECSHOP商品列表页显示每个商品的品牌2018-02-28
Ecshop 分类页品牌调用商品数量2018-02-28
ecshop调整默认商品图片排序2018-02-27
ecshop各个页面调用商品销售量方法2016-09-23
ecshop mobile首页循环显示分类及分类下商品2016-09-23
ecshop后台添加虚拟销量以及前台显示销量2016-09-22
ecshop重新导入数据库,管理员和密码正确登录失败2016-09-21