$cartitems = "";
if (isset($_SESSION["sess_userid"]) and $_SESSION["sess_userid"] != "") {
    $sql_cart = "SELECT c.*, p.product_name,(p.product_price+po.additional_price) AS product_price,po.discount,p.vdigital_product,p.product_id,p.product_artist_id,\n\t\t\t\t\t\t\t\tctry.gift_certificate_flag,p.fAdditionalItemCost,\n                                                 (SELECT pm.vimage_name FROM " . $tableprefix . "product_view_images pm where pm.nimage_productid=p.product_id LIMIT 0,1)AS smallimage\n\t\t\t\t\t\t FROM " . $tableprefix . "cart c\n                                                 INNER JOIN " . $tableprefix . "product_options po ON po.product_option_id = c.product_option_id\n                                                 INNER JOIN " . $tableprefix . "products p ON p.product_id = po.product_id\n                                                 INNER JOIN " . $tableprefix . "categories ctry ON ctry.category_id = p.product_category\n                                                 WHERE c.user_id = '" . addslashes($_SESSION["sess_userid"]) . "'";
} else {
    $sql_cart = "SELECT c.*, p.product_name,(p.product_price+po.additional_price) AS product_price,po.discount,p.product_artist_id,p.fAdditionalItemCost,\n                                                (SELECT pm.vimage_name FROM " . $tableprefix . "product_view_images pm where pm.nimage_productid=p.product_id LIMIT 0,1)AS smallimage\n\t\t\t\t\t\tFROM " . $tableprefix . "cart c \n                                                INNER JOIN " . $tableprefix . "product_options po ON po.product_option_id = c.product_option_id\n                                                INNER JOIN " . $tableprefix . "products p ON p.product_id = po.product_id\n                                                WHERE  c.visitor_cart_id = '" . addslashes(session_id()) . "' ";
}
$res_cart = mysql_query($sql_cart);
if (mysql_num_rows($res_cart) > 0) {
    while ($rw_cart = mysql_fetch_array($res_cart)) {
        if (isset($_SESSION["sess_userid"]) and $_SESSION["sess_userid"] != "") {
            if ($rw_cart['vdigital_product'] == 'Y' || $rw_cart['gift_certificate_flag'] == 'Y') {
                /*---------Checking if shipping is enable-----------*/
                //$check_shipping_enable = checkShippingEnable();
                //if($check_shipping_enable == "Y")
                //{
                cartClearDigital($_SESSION["sess_userid"]);
                //}
                /*---------Checking if shipping is enable-----------*/
            }
        }
        $_SESSION['gift_certificate_flag'] = $rw_cart['gift_certificate_flag'];
    }
}
if (isset($_SESSION["sess_userid"]) and $_SESSION["sess_userid"] != "") {
    $sql = "SELECT c.*, p.product_category,p.product_name,(p.product_price+po.additional_price) AS product_price,po.discount,po.image_small,p.product_artist_id,po.product_stock,p.fAdditionalItemCost,p.eProductTaxExempt,\n                        (SELECT pm.vimage_name FROM " . $tableprefix . "product_view_images pm where pm.nimage_productid=p.product_id LIMIT 0,1)AS smallimage\n\t\t\t\t\tFROM " . $tableprefix . "cart c\n                                        INNER JOIN " . $tableprefix . "product_options po ON po.product_option_id = c.product_option_id\n                                        INNER JOIN " . $tableprefix . "products p ON p.product_id = po.product_id\n\t\t\t\t\tWHERE c.user_id = '" . addslashes($_SESSION["sess_userid"]) . "'";
} else {
    $sql = "SELECT c.*,p.product_category, p.product_name,(p.product_price+po.additional_price) AS product_price,po.discount,po.image_small,p.product_artist_id,po.product_stock,p.fAdditionalItemCost,p.eProductTaxExempt,\n                        (SELECT pm.vimage_name FROM " . $tableprefix . "product_view_images pm where pm.nimage_productid=p.product_id LIMIT 0,1)AS smallimage\n\t\t\t\t\tFROM " . $tableprefix . "cart c\n                                        INNER JOIN " . $tableprefix . "product_options po ON po.product_option_id = c.product_option_id\n                                        INNER JOIN " . $tableprefix . "products p ON p.product_id = po.product_id\n                                        WHERE c.visitor_cart_id = '" . addslashes(session_id()) . "' ";
}
//echo $sql;
$res = mysql_query($sql);
$res1 = mysql_query($sql);
 }
 if (isset($_SESSION["sess_affiliateid"]) and $_SESSION["sess_affiliateid"] != "") {
     // Logging OutSeller  from same window
     session_unregister($_SESSION["sess_artistid"]);
 }
 // End check
 /*---------------Multicart 2.0 Upgradation------------------*/
 /*-------function call to manage the different sessions--------*/
 manageSession(3);
 /*---------------Multicart 2.0 Upgradation------------------*/
 if (!isVisitorCartEmpty(session_id())) {
     mergeVisitorCartToUserCart(session_id(), $row["user_id"]);
 }
 // Check Gift Products Exists in Cart  // Then delete NON gift Products
 if (checkGiftProductsExistsinCart($row["user_id"])) {
     cartClearDigital($row["user_id"]);
 }
 if ($wishMessage == 'Product added successfully!') {
     header("Location:" . SITE_URL . "/mywishlist.php");
     exit;
 }
 if ($action != "") {
     switch ($action) {
         case "checkout":
             header("Location:viewcart.php?action=checkout");
             exit;
             break;
         case "postartistfeedback":
             header("Location:postartistfeedback.php?artistid={$artistid}&productid={$productid}");
             exit;
             break;
    $_SESSION["TAX_TOTAL"] += $_SESSION["TAX_DETAILS"][$product_option_id];
}
// End Tax
//=========================If rate per state is not activated and default rate is activated
$exchangeRate = getCurrencyrate($currency_attributes[2]);
//===========================================
if ($_SESSION["TAX_TOTAL"] != 0) {
    // if tax rate is not null include tax rate
    $taxrates = $_SESSION["TAX_TOTAL"];
}
$_SESSION['session_taxrate'] = $taxrates;
// if Gift Certificate Order placed
if (checkGiftProductsExistsinCart($userid)) {
    $_SESSION['session_taxrate'] = '';
    $_SESSION['SHIPPING_TOTAL'] = '';
    cartClearDigital($userid);
}
//===============================End Tax Calulation===================================
/*function call to fetch details from site settings*/
//echo "hi".$_SESSION['SESS_digital_product'];exit;
if (!checkGiftProductsExistsinCart($userid)) {
    if ($_SESSION['SESS_upscost'] != '') {
        if ($_SESSION["sessBillingFirstName"] == '' || $_SESSION["sessBillingEmail"] == '' || $_SESSION["sessShippingFirstName"] == '' || $_SESSION["sessShippingEmail"] == '') {
            $_SESSION["sess_addresses_collected"] = false;
            header("Location:checkout.php");
            exit;
        }
    }
}
$digital_product_count = digitalProductsCartCount($userid);
if ($digital_product_count == 1) {