51可用代码模板网站

咨询热线:

181-1164-6936
  • 1
ECSHOP商城
当前位置:首页>实用代码>ECSHOP商城>

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

时间:2017-08-10 17:19点击:
把以下代码加到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']);
   }
  }
}

51可用模板(代码)网站专为广大站长朋友提供精品模板与代码,同时免费提供网站收录。
本站域名: WWW.51KYDM.COM    联系方式:QQ:182468923    手机:18111646936
本站关键词:网站链接收录网址收录入口网站免费提交收录网站收录提交入口    网站地图
51可用模板
展开