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

2016-09-07 22:02 来源:www.chinab4c.com 作者:ecshop专家

 把以下代码加到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']);
   }
  }
 }

(责任编辑:chinab4c)