服务报价 | 域名主机 | 网络营销 | 软件工具| [加入收藏]
 热线电话: #
当前位置: 主页 > php教程 > ecshop教程 >

ecshop自动把赠品添加到购物车的开发

时间:2012-09-09 12:13来源:未知 作者:最模板 点击:
把以下代码加到flow.php文件(165行),$result['confirm_type'] = !empty($_CFG['cart_confirm']) ? $_CFG['cart_confirm'] : 2;的上面 /* 取得优惠活动 */ $favourable_list = favourable_list($_SESSION['user_rank']); // 自动把赠

 把以下代码加到flow.php文件(165行),$result['confirm_type'] = !empty($_CFG['cart_confirm']) ? $_CFG['cart_confirm'] : 2;的上面


    /* 取得优惠活动 */
    $favourable_list = favourable_list($_SESSION['user_rank']);


 // 自动把赠品添加到购物车
 foreach($favourable_list as $v)
 {
if(!$v['available']) continue;
  /* 取得优惠活动信息 */
  $act_id = $v['act_id'];
  $favourable = favourable_info($act_id);
 
  /* 检查购物车中是否已有该优惠 */
  $cart_favourable = cart_favourable();
  if (favourable_used($favourable, $cart_favourable))
  {
   continue;
  }
  $gift = array();
  foreach($v['gift'] as $g)
  {
   $gift[] = $g['id'];
  }
  
  /* 赠品(特惠品)优惠 */
  if ($favourable['act_type'] == FAT_GOODS)
  {
   /* 检查是否已在购物车 */
   $sql = "SELECT goods_name" .
     " FROM " . $ecs->table('cart') .
     " WHERE session_id = '" . SESS_ID . "'" .
     " AND rec_type = '" . CART_GENERAL_GOODS . "'" .
     " AND is_gift = '$act_id'" .
     " AND goods_id " . db_create_in($gift);
   $gift_name = $db->getCol($sql);
   if (!empty($gift_name))
   {
    continue;
   }
 
   /* 检查数量是否超过上限 */
   $count = isset($cart_favourable[$act_id]) ? $cart_favourable[$act_id] : 0;
   if ($favourable['act_type_ext'] > 0 && $count + count($gift) > $favourable['act_type_ext'])
   {
    continue;
   }
 
   /* 添加赠品到购物车 */
   foreach ($favourable['gift'] as $g)
   {
    add_gift_to_cart($act_id, $g['id'], $g['price']);
   }
  }
 }

(责任编辑:最模板)
顶一下
(2)
100%
踩一下
(0)
0%
------分隔线----------------------------