/**
 * 删除购物车中的商品
 *
 * @access  public
 * @param   integer $id
 * @return  void
 */
function flow_drop_cart_goods($id)
{
    /* 取得商品id */
    $sql = "SELECT * FROM " . $GLOBALS['ecs']->table('cart') . " WHERE rec_id = '{$id}'";
    $row = $GLOBALS['db']->getRow($sql);
    if ($row) {
        //如果是超值礼包
        if ($row['extension_code'] == 'package_buy') {
            $sql = "DELETE FROM " . $GLOBALS['ecs']->table('cart') . " WHERE session_id = '" . SESS_ID . "' " . "AND rec_id = '{$id}' LIMIT 1";
        } elseif ($row['parent_id'] == 0 && $row['is_gift'] == 0) {
            /* 检查购物车中该普通商品的不可单独销售的配件并删除 */
            $sql = "SELECT c.rec_id\n                    FROM " . $GLOBALS['ecs']->table('cart') . " AS c, " . $GLOBALS['ecs']->table('group_goods') . " AS gg, " . $GLOBALS['ecs']->table('goods') . " AS g\n                    WHERE gg.parent_id = '" . $row['goods_id'] . "'\n                    AND c.goods_id = gg.goods_id\n                    AND c.parent_id = '" . $row['goods_id'] . "'\n                    AND c.extension_code <> 'package_buy'\n                    AND gg.goods_id = g.goods_id\n                    AND g.is_alone_sale = 0 AND c.group_id='" . $row['group_id'] . "'";
            //by mike add
            $res = $GLOBALS['db']->query($sql);
            $_del_str = $id . ',';
            while ($id_alone_sale_goods = $GLOBALS['db']->fetchRow($res)) {
                $_del_str .= $id_alone_sale_goods['rec_id'] . ',';
            }
            $_del_str = trim($_del_str, ',');
            $sql = "DELETE FROM " . $GLOBALS['ecs']->table('cart') . " WHERE session_id = '" . SESS_ID . "' " . "AND (rec_id IN ({$_del_str}) OR parent_id = '{$row['goods_id']}' OR is_gift <> 0) AND group_id='" . $row['group_id'] . "'";
        } else {
            $sql = "DELETE FROM " . $GLOBALS['ecs']->table('cart') . " WHERE session_id = '" . SESS_ID . "' " . "AND rec_id = '{$id}' LIMIT 1";
        }
        $GLOBALS['db']->query($sql);
    }
    flow_clear_cart_alone();
}
Exemple #2
0
/**
 * 删除购物车中的商品
 *
 * @access  public
 * @param   integer $id
 * @return  void
 */
function flow_drop_cart_goods($id)
{
    /* 取得商品id */
    $sql = "SELECT * FROM " . $GLOBALS['ecs']->table('cart') . " WHERE rec_id = '{$id}'";
    $row = $GLOBALS['db']->getRow($sql);
    if ($row) {
        $sql_where = $_SESSION['user_id'] > 0 ? "user_id='" . $_SESSION['user_id'] . "' " : "session_id = '" . SESS_ID . "' AND user_id=0 ";
        //添加 www.68ecshop.com
        //如果是超值礼包
        if ($row['extension_code'] == 'package_buy') {
            /* 代码修改_start  By  www.68ecshop.com  将这块替换掉*/
            $sql = "DELETE FROM " . $GLOBALS['ecs']->table('cart') . " WHERE {$sql_where} " . "AND rec_id = '{$id}' LIMIT 1";
            /* 代码修改_end  By  www.68ecshop.com  */
        } elseif ($row['parent_id'] == 0 && $row['is_gift'] == 0) {
            /* 检查购物车中该普通商品的不可单独销售的配件并删除 */
            $sql = "SELECT c.rec_id\n                    FROM " . $GLOBALS['ecs']->table('cart') . " AS c, " . $GLOBALS['ecs']->table('group_goods') . " AS gg, " . $GLOBALS['ecs']->table('goods') . " AS g\n                    WHERE gg.parent_id = '" . $row['goods_id'] . "'\n                    AND c.goods_id = gg.goods_id\n                    AND c.parent_id = '" . $row['goods_id'] . "'\n                    AND c.extension_code <> 'package_buy'\n                    AND gg.goods_id = g.goods_id\n                    AND g.is_alone_sale = 0";
            $res = $GLOBALS['db']->query($sql);
            $_del_str = $id . ',';
            while ($id_alone_sale_goods = $GLOBALS['db']->fetchRow($res)) {
                $_del_str .= $id_alone_sale_goods['rec_id'] . ',';
            }
            $_del_str = trim($_del_str, ',');
            /* 代码修改_start  By  www.68ecshop.com  将这块替换掉*/
            $sql = "DELETE FROM " . $GLOBALS['ecs']->table('cart') . " WHERE {$sql_where} " . "AND (rec_id IN ({$_del_str}) OR parent_id = '{$row['goods_id']}' OR is_gift <> 0)";
            /* 代码修改_end  By  www.68ecshop.com  */
        } else {
            /* 代码修改_start  By  www.68ecshop.com  将这块替换掉*/
            $sql = "DELETE FROM " . $GLOBALS['ecs']->table('cart') . " WHERE {$sql_where} " . "AND rec_id = '{$id}' LIMIT 1";
            /* 代码修改_end  By  www.68ecshop.com  */
        }
        $GLOBALS['db']->query($sql);
    }
    flow_clear_cart_alone();
}