网上方法很多,但都不能用的,有的是老版本的,有的方法本身就不完整。
应大多数客户要求,我们重新整理下教程,希望对大家有用。
亲测可用!ecshop立即购买和加入购物车按钮共存的方法 第一步:修改ecshop模板文件:goods.dwt模板
<a href="javascript:addToCart1({$goods.goods_id})"><img src="data:images/bnt_cat.gif" />
(提示:是在购物车按钮旁边增加个:立即购买)
亲测可用!ecshop立即购买和加入购物车按钮共存的方法 第二步:修改ecshop系统的js文件:js/common.js
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'];
var quick = 0;
// 检查是否有商品规格
if (formBuy)
{
spec_arr = getSelectedAttributes(formBuy);
if (formBuy.elements['number'])
{
number = formBuy.elements['number'].value;
}
quick = 1;
}
goods.quick = quick;
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 + '&spec=' + result.product_spec;
}
}
// 没选规格,弹出属性选择框
else if (result.error == 6)
{
openSpeDiv(result.message, result.goods_id, result.parent);
}
else
{
alert(result.message);
}
}
else
{
var cartInfo = document.getElementById('ECS_CARTINFO');
var cart_url = 'flow.php?step=cart';
if (cartInfo)
{
cartInfo.innerHTML = result.content;
}
location.href = cart_url; }
} 3第三步:flow.php
elseif ($_REQUEST['step'] == 'add_to_cart1')
{
include_once('includes/cls_json.php');
$_POST['goods'] = json_str_iconv($_POST['goods']);
if (!empty($_REQUEST['goods_id']) && empty($_POST['goods']))
{
if (!is_numeric($_REQUEST['goods_id']) || intval($_REQUEST['goods_id']) <= 0)
{
ecs_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']);
/* 检查:如果商品有规格,而post的数据没有规格,把商品的规格属性通过JSON传到前台 */
if (empty($goods->spec) AND empty($goods->quick))
{
$sql = "SELECT a.attr_id, a.attr_name, a.attr_type, ".
"g.goods_attr_id, g.attr_value, g.attr_price " .
'FROM ' . $GLOBALS['ecs']->table('goods_attr') . ' AS g ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('attribute') . ' AS a ON a.attr_id = g.attr_id ' .
"WHERE a.attr_type != 0 AND g.goods_id = '" . $goods->goods_id . "' " .
'ORDER BY a.sort_order, g.attr_price, g.goods_attr_id';
$res = $GLOBALS['db']->getAll($sql);
if (!empty($res))
{
$spe_arr = array();
foreach ($res AS $row)
{
$spe_arr[$row['attr_id']]['attr_type'] = $row['attr_type'];
$spe_arr[$row['attr_id']]['name'] = $row['attr_name'];
$spe_arr[$row['attr_id']]['attr_id'] = $row['attr_id'];
$spe_arr[$row['attr_id']]['values'][] = array(
'label' => $row['attr_value'],
'price' => $row['attr_price'],
'format_price' => price_format($row['attr_price'], false),
'id' => $row['goods_attr_id']);
}
$i = 0;
$spe_array = array();
foreach ($spe_arr AS $row)
{
$spe_array[]=$row;
}
$result['error'] = ERR_NEED_SELECT_ATTR;
$result['goods_id'] = $goods->goods_id;
$result['parent'] = $goods->parent;
$result['message'] = $spe_array;
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);
if (is_array($goods->spec))
{
$result['product_spec'] = implode(',', $goods->spec);
}
else
{
$result['product_spec'] = $goods->spec;
}
}
}
$result['confirm_type'] =3;
die($json->encode($result));
}

  

测可用!ecshop立即购买和加入购物车按钮共存的方法的更多相关文章

  1. 阿里云服务器centos7,docker部署mysql+Redis+vue+springboot+Nginx+fastdfs,亲测可用

    一.购买云服务器 我是今年双十一期间在阿里云购买的服务器, 简单配置2核_4G_40G_3M,三年用了不到800块,不过当时我记得腾讯云更便宜,个人感觉,阿里的云服务器更加的稳定, 毕竟身经百战, 经 ...

  2. C#读取Excel设置(亲测可用)

    OpenFileDialog openFD = new OpenFileDialog(); openFD.FileName = ""; openFD.Filter = " ...

  3. IntelliJ13+tomcat+jrebel实现热部署(亲测可用)

       网上有很多介绍intellij idea整合jrebel插件实现热部署的文章,但是有的比较复杂,有的不能成功,最后经过各种尝试,实现了整合,亲测可用!步骤说明如下:   一.先下载jrebel安 ...

  4. Linux下通过crontab及expect实现自动化处理 --亲测可用

    #!/usr/bin/expect -fspawn /home/scripts/bckup.shexpect "Enter password: "  send "WWQQ ...

  5. ecshop二次开发之购物车常见问题

    1.ecshop二次开发中保存注册用户购物车数据解决方法:ecshop购物车是数据库中cart表来支持的,在ecshop表中rec_id是编号,user_id是注册用户的id,session_id表示 ...

  6. 亲测可用!!!golang如何在idea中保存时自动进行代码格式化

    亲测可用,golang在idea中的代码自动格式化 1.ctrl+alt+s打开设置界面,选择[Plugins] -> [Install JetBrains plugin...] -> 搜 ...

  7. Spring4.0.1+Quartz2.2.1实现定时任务调度[亲测可用]

    Spring4.0.1+Quartz2.2.1实现定时任务调度[亲测可用] tip:只需要配置xml文件即可 1.第三方依赖包的引入 <properties> <project.bu ...

  8. Sublime Text3注册码,亲测可用

    将以下复制在输入框即可 ,亲测可用 . 不过还是希望大家多多支持正版 . -– BEGIN LICENSE -– TwitterInc 200 User License EA7E-890007 1D7 ...

  9. IDEA 使用Mybatis效率飞起来的必备工具:MybatisCodeHelperPro 最新破解版,亲测可用!

    IDEA 2018.3.5 最新版本亲测可用. Git地址:https://github.com/pengzhile/MyBatisCodeHelper-Pro-Crack/releases 下载最新 ...

随机推荐

  1. strcpy  复制字符串函数

    #include<stdio.h> #include<assert.h> char *strcopy(char * strDest , const char * strSrc) ...

  2. c#如实现将一个数字转化为其他进制字符串输出

    之前在  os  上看到有人说过 一直想整理 但是一直没时间 后来 从csdn 上  知道了一份 下面内容 来自 (1)http://bbs.csdn.net/topics/60512816 tost ...

  3. LDA-math-神奇的Gamma函数

    http://cos.name/2013/01/lda-math-gamma-function/ 1. 神奇的Gamma函数1.1 Gamma 函数诞生记学高等数学的时候,我们都学习过如下一个长相有点 ...

  4. delphi 读取excel 两种方法

    http://www.cnblogs.com/ywangzi/archive/2012/09/27/2705894.html 两种方法,一是用ADO连接,问题是Excel文件内容要规则,二是用OLE打 ...

  5. JSP-09-使用EL显示数据

    目的:为了使JSP写起来更加简单. 9.1  EL表达式 ${EL表达式}  :  ${unsername} 操作符:   “. ”操作符: 用来访问对象的属性    ${news.title} “[ ...

  6. 关于科台斯k97gprs调试记录(1)

    模块调试 1.gprs模块了解 用流量上网的模块,可以发短信,打电话. 2.AT指令的学习 AT+UART=波特率,流控位,数据位长度,校验控制,停止位长度 AT+NET=TCP/UDP 选择,APN ...

  7. 【海岛帝国系列赛】No.3 海岛帝国:运输资源

    海岛帝国:运输资源 [试题描述] YSF考虑到“药师傅”帝国现在资源极度不平均,于是,商讨启用南水北调工程.YZM为首席工程师.现在,YSF由于工作紧张,准备军用物资和民用物资.但他要时时关注运输工程 ...

  8. 五分钟打造自己的sql性能分析工具

    1.首先要有一个trace文件 2. 打开trace文件 3. 另存为跟踪表 4.登录你要保存到的目标sqlserver服务器 5. 选择要保存的数据库和表名称 6. 保存完成(左下角出现进度直到显示 ...

  9. 面向生产环境的大集群模式安装Hadoop

    一.实验说明 1.本实验将使用DNS而不是hosts文件解析主机名: 2.使用NFS共享密钥文件,而不是逐个手工拷贝添加密钥: 3.复制Hadoop时使用批量拷贝脚本而不是逐台复制. 测试环境: Ho ...

  10. 28、Oracle(四)用户权限控制

    一)用户Oracle中的用户分为二大类1)Oracle数据库服务器创建时,由系统自动创建的用户,叫系统用户,如sys.2)利用系统用户创建的用户,叫普通用户,如scott,hr,c##tiger,zh ...