本文整理汇总了PHP中insert_cart_info函数的典型用法代码示例。如果您正苦于以下问题:PHP insert_cart_info函数的具体用法?PHP insert_cart_info怎么用?PHP insert_cart_info使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了insert_cart_info函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ajax_update_cart
/**
* 点击刷新购物车
*/
public function ajax_update_cart()
{
//格式化返回数组
$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));
}
// 查询:
$condition = " rec_id='{$key}' AND session_id='" . SESS_ID . "'";
$goods = $this->model->table('cart')->field('goods_id,goods_attr_id,product_id,extension_code')->where($condition)->find();
$sql = "SELECT g.goods_name,g.goods_number " . "FROM " . $this->model->pre . "goods AS g, " . $this->model->pre . "cart AS c " . "WHERE g.goods_id =c.goods_id AND c.rec_id = '{$key}'";
$res = $this->model->query($sql);
$row = $res[0];
// 查询:系统启用了库存,检查输入的商品数量是否有效
if (intval(C('use_storage')) > 0) {
if ($row['goods_number'] < $val) {
$result['error'] = 1;
$result['message'] = sprintf(L('stock_insufficiency'), $row['goods_name'], $row['goods_number'], $row['goods_number']);
$result['err_max_number'] = $row['goods_number'];
die(json_encode($result));
}
/* 是货品 */
$goods['product_id'] = trim($goods['product_id']);
if (!empty($goods['product_id'])) {
$condition = " goods_id = '" . $goods['goods_id'] . "' AND product_id = '" . $goods['product_id'] . "'";
$product_number = $this->model->table('products')->field('product_number')->where($condition)->getOne();
if ($product_number < $val) {
$result['error'] = 2;
$result['message'] = sprintf(L('stock_insufficiency'), $row['goods_name'], $product_number, $product_number);
die(json_encode($result));
}
}
}
/* 查询:检查该项是否为基本件 以及是否存在配件 */
/* 此处配件是指添加商品时附加的并且是设置了优惠价格的配件 此类配件都有parent_idgoods_number为1 */
$sql = "SELECT b.goods_number,b.rec_id\r\n\t\t\tFROM " . $this->model->pre . "cart a, " . $this->model->pre . "cart b\r\n\t\t\t\tWHERE a.rec_id = '{$key}'\r\n\t\t\t\tAND a.session_id = '" . SESS_ID . "'\r\n\t\t\tAND b.parent_id = a.goods_id\r\n\t\t\tAND b.session_id = '" . SESS_ID . "'";
$offers_accessories_res = $this->model->query($sql);
// 订货数量大于0
if ($val > 0) {
/* 判断是否为超出数量的优惠价格的配件 删除 */
$row_num = 1;
foreach ($offers_accessories_res as $offers_accessories_row) {
if ($row_num > $val) {
$sql = "DELETE FROM" . $this->model->pre . "cart WHERE session_id = '" . SESS_ID . "' " . " AND rec_id ='" . $offers_accessories_row['rec_id'] . "' LIMIT 1";
$this->model->query($sql);
}
$row_num++;
}
$attr_id = empty($goods['goods_attr_id']) ? array() : explode(',', $goods['goods_attr_id']);
$goods_price = model('GoodsBase')->get_final_price($goods['goods_id'], $val, true, $attr_id);
// 更新购物车中的商品数量
$sql = "UPDATE " . $this->model->pre . "cart SET goods_number= '{$val}', goods_price = '{$goods_price}' WHERE rec_id='{$key}' AND session_id='" . SESS_ID . "'";
} else {
/* 如果是基本件并且有优惠价格的配件则删除优惠价格的配件 */
foreach ($offers_accessories_res as $offers_accessories_row) {
$sql = "DELETE FROM " . $this->model->pre . "cart WHERE session_id= '" . SESS_ID . "' " . "AND rec_id ='" . $offers_accessories_row['rec_id'] . "' LIMIT 1";
$this->model->query($sql);
}
$sql = "DELETE FROM " . $this->model->pre . "cart WHERE rec_id='{$key}' AND session_id='" . SESS_ID . "'";
}
$this->model->query($sql);
/* 删除所有赠品 */
$sql = "DELETE FROM " . $this->model->pre . "cart WHERE session_id = '" . SESS_ID . "' AND is_gift <> 0";
$this->model->query($sql);
$result['rec_id'] = $key;
$result['goods_number'] = $val;
$result['goods_subtotal'] = '';
$result['total_desc'] = '';
$result['cart_info'] = insert_cart_info();
/* 计算合计 */
$cart_goods = model('Order')->get_cart_goods();
foreach ($cart_goods['goods_list'] as $goods) {
if ($goods['rec_id'] == $key) {
$result['goods_subtotal'] = $goods['subtotal'];
break;
}
}
$market_price_desc = sprintf(L('than_market_price'), $cart_goods['total']['market_price'], $cart_goods['total']['saving'], $cart_goods['total']['save_rate']);
/* 计算折扣 */
$discount = model('Order')->compute_discount();
$favour_name = empty($discount['name']) ? '' : join(',', $discount['name']);
$your_discount = sprintf('', $favour_name, price_format($discount['discount']));
$result['total_desc'] = $cart_goods['total']['goods_price'];
$result['total_number'] = $cart_goods['total']['total_number'];
$result['market_total'] = $cart_goods['total']['market_price'];
//市场价格
die(json_encode($result));
} else {
$result['error'] = 100;
$result['message'] = '';
//.........这里部分代码省略.........
示例2: clear_cart
if ($_CFG['one_step_buy'] == '1') {
clear_cart();
}
/* 商品数量是否合法 */
if (!is_numeric($package->number) || intval($package->number) <= 0) {
$result['error'] = 1;
$result['message'] = $_LANG['invalid_number'];
} else {
/* 添加到购物车 */
if (add_package_to_cart($package->package_id, $package->number)) {
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['package_id'] = stripslashes($package->package_id);
}
}
$result['confirm_type'] = !empty($_CFG['cart_confirm']) ? $_CFG['cart_confirm'] : 2;
die($json->encode($result));
} else {
/* 标记购物流程为普通商品 */
$_SESSION['flow_type'] = CART_GENERAL_GOODS;
/* 如果是一步购物,跳到结算中心 */
if ($_CFG['one_step_buy'] == '1') {
ecs_header("Location: flow.php?step=checkout\n");
示例3: add_to_gift
public function add_to_gift()
{
//对goods处理
$_POST['goods'] = strip_tags(urldecode($_POST['goods']));
$_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");
}
exit;
}
// 初始化返回数组
$result = array('error' => 0, 'message' => '', 'content' => '', 'goods_id' => '', 'product_spec' => '');
if (empty($_POST['goods'])) {
$result['error'] = 1;
die(json_encode($result));
}
$json = new EcsJson();
$goods = $json->decode($_POST['goods']);
$result['goods_id'] = $goods->goods_id;
$result['product_spec'] = $goods->spec;
// 检查:如果商品有规格,而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 ' . $this->model->pre . 'goods_attr AS g ' . 'LEFT JOIN ' . $this->model->pre . '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 = $this->model->query($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));
}
}
// 购买礼包商品清空购物车
model('Order')->clear_cart(CART_GIFT_GOODS);
// 查询:系统启用了库存,检查输入的商品数量是否有效
// 查询
$arrGoods = $this->model->table('goods')->field('goods_name,goods_number,extension_code')->where('goods_id =' . $goods->goods_id)->find();
$goodsnmber = model('Users')->get_goods_number($goods->goods_id);
$goodsnmber += $goods->number;
if (intval(C('use_storage')) > 0) {
if ($arrGoods['goods_number'] < $goodsnmber) {
$result['error'] = 1;
$result['message'] = sprintf(L('stock_insufficiency'), $arrGoods['goods_name'], $arrGoods['goods_number'], $arrGoods['goods_number']);
if (C('use_how_oos') == 1) {
$result['message'] = L('oos_tips');
}
die(json_encode($result));
}
}
// 检查:商品数量是否合法
if (!is_numeric($goods->number) || intval($goods->number) <= 0) {
$result['error'] = 1;
$result['message'] = L('invalid_number');
} else {
// 更新:添加到购物车
$_SESSION['flow_type'] = CART_GIFT_GOODS;
$_SESSION['extension_code'] = "gift_goods";
$_SESSION['extension_id'] = CART_GIFT_GOODS;
if (model('Order')->addto_cart($goods->goods_id, $goods->number, $goods->spec, $goods->parent, CART_GIFT_GOODS)) {
if (C('cart_confirm') > 2) {
$result['message'] = '';
} else {
$result['message'] = C('cart_confirm') == 1 ? L('addto_cart_success_1') : L('addto_cart_success_2');
}
$result['content'] = insert_cart_info();
$result['one_step_buy'] = C('one_step_buy');
} else {
$result['message'] = ECTouch::err()->last_message();
$result['error'] = ECTouch::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;
}
}
}
$cart_confirm = C('cart_confirm');
$result['confirm_type'] = !empty($cart_confirm) ? C('cart_confirm') : 2;
// 返回购物车商品总数量
$result['cart_number'] = insert_cart_info_number();
die(json_encode($result));
}
示例4: add_package_to_cart
/**
* 添加礼包到购物车
*/
public function add_package_to_cart()
{
$_POST['package_info'] = json_str_iconv($_POST['package_info']);
$result = array('error' => 0, 'message' => '', 'content' => '', 'package_id' => '');
if (empty($_POST['package_info'])) {
$result['error'] = 1;
die(json_encode($result));
}
$json = new EcsJson();
$package = $json->decode($_POST['package_info']);
/* 如果是一步购物,先清空购物车 */
if (C('one_step_buy') == '1') {
model('Order')->clear_cart();
}
/* 商品数量是否合法 */
if (!is_numeric($package->number) || intval($package->number) <= 0) {
$result['error'] = 1;
$result['message'] = L('invalid_number');
} else {
/* 添加到购物车 */
if (model('Order')->add_package_to_cart($package->package_id, $package->number)) {
if (C('cart_confirm') > 2) {
$result['message'] = '';
} else {
$result['message'] = C('cart_confirm') == 1 ? L('addto_cart_success_1') : L('addto_cart_success_2');
}
$result['content'] = insert_cart_info();
$result['one_step_buy'] = C('one_step_buy');
} else {
$result['message'] = ECTouch::err()->last_message();
$result['error'] = ECTouch::err()->error_no;
$result['package_id'] = stripslashes($package->package_id);
}
}
$cart_confirm = C('cart_confirm');
$result['confirm_type'] = !empty($cart_confirm) ? $cart_confirm : 2;
die(json_encode($result));
}
示例5: content_559878bbf3b0e7_68420577
function content_559878bbf3b0e7_68420577($_smarty_tpl)
{
if (!is_callable('smarty_function_insert_scripts')) {
include 'D:\\WWW\\ecshoptk\\ThinkPHP\\Library\\Vendor\\Smarty\\plugins\\function.insert_scripts.php';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Keywords" content="<?php
echo $_smarty_tpl->tpl_vars['keywords']->value;
?>
" />
<meta name="Description" content="<?php
echo $_smarty_tpl->tpl_vars['description']->value;
?>
" />
<!-- TemplateBeginEditable name="doctitle" -->
<title><?php
echo $_smarty_tpl->tpl_vars['page_title']->value;
?>
</title>
<!-- TemplateEndEditable -->
<!-- TemplateBeginEditable name="head" -->
<!-- TemplateEndEditable -->
<link rel="shortcut icon" href="favicon.ico" />
<link rel="icon" href="animated_favicon.gif" type="image/gif" />
<link href="<?php
echo $_smarty_tpl->tpl_vars['ecs_css_path']->value;
?>
" rel="stylesheet" type="text/css" />
<link rel="alternate" type="application/rss+xml" title="RSS|<?php
echo $_smarty_tpl->tpl_vars['page_title']->value;
?>
" href="<?php
echo $_smarty_tpl->tpl_vars['feed_url']->value;
?>
" />
<?php
echo smarty_function_insert_scripts(array('files' => 'common.js,index.js'), $_smarty_tpl);
?>
</head>
<body>
<?php
echo $_smarty_tpl->getSubTemplate((string) $_smarty_tpl->tpl_vars['tplstyle']->value . "/library/page_header.lbi", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array(), 0);
?>
<div class="blank"></div>
<div class="block clearfix">
<!--left start-->
<div class="AreaL">
<!--站内公告 start-->
<div class="box">
<div class="box_1">
<h3><span><?php
echo $_smarty_tpl->tpl_vars['lang']->value['shop_notice'];
?>
</span></h3>
<div class="boxCenterList RelaArticle">
<?php
echo $_smarty_tpl->tpl_vars['shop_notice']->value;
?>
</div>
</div>
</div>
<div class="blank5"></div>
<!--站内公告 end-->
<!-- TemplateBeginEditable name="左边区域" -->
<!-- #BeginLibraryItem "/library/cart.lbi" -->
<?php
echo smarty_function_insert_scripts(array('files' => 'transport.js'), $_smarty_tpl);
?>
<div class="cart" id="ECS_CARTINFO">
<?php
echo insert_cart_info(array(), $_smarty_tpl);
?>
</div>
<div class="blank5"></div>
<!-- #EndLibraryItem -->
<!-- #BeginLibraryItem "/library/category_tree.lbi" -->
<div class="box">
<div class="box_1">
<div id="category_tree">
<?php
$_smarty_tpl->tpl_vars['cat'] = new Smarty_Variable();
$_smarty_tpl->tpl_vars['cat']->_loop = false;
$_from = $_smarty_tpl->tpl_vars['categories']->value;
if (!is_array($_from) && !is_object($_from)) {
settype($_from, 'array');
}
foreach ($_from as $_smarty_tpl->tpl_vars['cat']->key => $_smarty_tpl->tpl_vars['cat']->value) {
//.........这里部分代码省略.........
开发者ID:highestgoodlikewater,项目名称:ecshoptk,代码行数:101,代码来源:c7fdbaeaec37d99e71d63277e9bd10d7a782518b.file.index.dwt.php
示例6: receive_gift
public function receive_gift()
{
//对goods处理
$_POST['goods'] = strip_tags(urldecode($_POST['gift']));
$_POST['goods'] = json_str_iconv($_POST['gift']);
// 初始化返回数组
$result = array('error' => 0, 'message' => '', 'content' => '', 'goods_id' => '', 'product_spec' => '');
if (empty($_POST['goods'])) {
$result['error'] = 1;
die(json_encode($result));
}
$json = new EcsJson();
$gift = $json->decode($_POST['gift']);
$result['sn'] = $gift->sn;
$result['product_spec'] = $gift->spec;
// 购买礼包商品清空购物车
model('Order')->clear_cart(CART_RECEIVE_GIFTS);
// 查询:系统启用了库存,检查输入的商品数量是否有效
// 查询
$Gift = $this->model->table('gift_sn')->field('goods_name,amount,sn_id,goods_id')->where("sn_id='" . $gift->sn . "'")->find();
if ($gift->number > $Gift['amount']) {
$result['error'] = 1;
$result['message'] = sprintf(L('stock_insufficiency'), $Gift['goods_name'], $Gift['goods_number'], $Gift['goods_number']);
if (C('use_how_oos') == 1) {
$result['message'] = L('oos_tips');
}
die(json_encode($result));
}
// 检查:商品数量是否合法
if (!is_numeric($gift->number) || intval($gift->number) <= 0) {
$result['error'] = 1;
$result['message'] = L('invalid_number');
} else {
// 更新:添加到购物车
$_SESSION['flow_type'] = CART_RECEIVE_GIFTS;
$_SESSION['extension_code'] = "receive_gift";
$_SESSION['extension_id'] = CART_RECEIVE_GIFTS;
if (model('Order')->addto_cart($Gift['goods_id'], $gift->number, $gift->spec, $gift->parent, CART_RECEIVE_GIFTS)) {
if (C('cart_confirm') > 2) {
$result['message'] = '';
} else {
$result['message'] = C('cart_confirm') == 1 ? L('addto_cart_success_1') : L('addto_cart_success_2');
}
$result['content'] = insert_cart_info();
$result['one_step_buy'] = C('one_step_buy');
} else {
$result['message'] = ECTouch::err()->last_message();
$result['error'] = ECTouch::err()->error_no;
$result['goods_id'] = stripslashes($Gift['goods_id']);
if (is_array($goods->spec)) {
$result['product_spec'] = implode(',', $gift->spec);
} else {
$result['product_spec'] = $gift->spec;
}
}
}
$cart_confirm = C('cart_confirm');
$result['confirm_type'] = !empty($cart_confirm) ? C('cart_confirm') : 2;
// 返回购物车商品总数量
$result['cart_number'] = insert_cart_info_number();
die(json_encode($result));
}
示例7: add_to_cart_cf
public function add_to_cart_cf()
{
//对goods处理
$_POST['goods'] = strip_tags(urldecode($_POST['goods']));
$_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");
}
exit;
}
// 初始化返回数组
$result = array('error' => 0, 'message' => '', 'content' => '', 'goods_id' => '', 'product_spec' => '');
if (empty($_POST['goods'])) {
$result['error'] = 1;
die(json_encode($result));
}
$json = new EcsJson();
$goods = $json->decode($_POST['goods']);
$result['goods_id'] = $goods->goods_id;
$result['product_spec'] = $goods->spec;
// 清空众筹购物车
model('Order')->clear_cart(CART_CF_GOODS);
//TODO 查询众筹库存
/*
$arrGoods = $this->model->table('goods')->field('goods_name,goods_number,extension_code')->where('goods_id =' . $goods->goods_id)->find();
$goodsnmber = model('Users')->get_goods_number($goods->goods_id);
$goodsnmber+=$goods->number;
if ($arrGoods ['goods_number'] < $goodsnmber) {
$result['error'] = 1;
$result['message'] = sprintf(L('stock_insufficiency'), $arrGoods ['goods_name'], $arrGoods ['goods_number'], $arrGoods ['goods_number']);
if (C('use_how_oos') == 1){
$result['message'] =L('oos_tips');
}
die(json_encode($result));
}
*/
// 检查:商品数量是否合法
if (!is_numeric($goods->number) || intval($goods->number) <= 0) {
$result['error'] = 1;
$result['message'] = L('invalid_number');
} else {
// 更新:添加到购物车
$_SESSION['flow_type'] = CART_CF_GOODS;
$_SESSION['extension_code'] = "Crowdfunding";
$_SESSION['extension_id'] = CART_CF_GOODS;
if (model('Order')->addto_cart($goods->goods_id, $goods->number, $goods->spec, $goods->parent, CART_CF_GOODS)) {
if (C('cart_confirm') > 2) {
$result['message'] = '';
} else {
$result['message'] = C('cart_confirm') == 1 ? L('addto_cart_success_1') : L('addto_cart_success_2');
}
$result['content'] = insert_cart_info();
$result['one_step_buy'] = C('one_step_buy');
} else {
$result['message'] = ECTouch::err()->last_message();
$result['error'] = ECTouch::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;
}
}
}
$cart_confirm = C('cart_confirm');
$result['confirm_type'] = !empty($cart_confirm) ? C('cart_confirm') : 2;
// 返回购物车商品总数量
$result['cart_number'] = insert_cart_info_number();
die(json_encode($result));
}