//print_r($_SESSION);
 /* $buyerDetails = getBuyerDetails($_SESSION["sess_userid"]);
 //echo "user details";
 //print_r($buyerDetails);
                                    $_SESSION['sessShippingCountry'] = $buyerDetails['country'];
                                    $_SESSION['sessShippingState'] = $buyerDetails['state'];
                                    $_SESSION['sessShippingZIP'] = $buyerDetails['zip'];*/
 $destination_country = $_SESSION['sessShippingCountry'];
 $destination_state = $_SESSION['sessShippingState'];
 $destination_zip = $_SESSION['sessShippingZIP'];
 $product_name = $rw['product_name'];
 $artist_id = $rw['artist_id'];
 $product_id = $rw['product_id'];
 $product_option_id = $rw['product_option_id'];
 $optionsStr = "";
 $optionVal = getProductOptionsName($product_option_id);
 if ($optionVal != "") {
     $optionsStr = "<br>" . $optionVal;
 }
 $productArray[$product_option_id] = $product_name . $optionsStr;
 $quantity = trim($rw['quantity']);
 $product_length = $rw['product_length'];
 $product_height = $rw['product_height'];
 $product_width = $rw['product_width'];
 //print_r($_SESSION['enabledShippingMethods']);
 $rowcartId = $rw['cart_id'];
 $rowproduct_id = $rw['product_id'];
 $rowproduct_option_id = $rw['product_option_id'];
 $resultShippingArray = array();
 for ($i = 0; $i <= count($_SESSION['enabledShippingMethods']); $i++) {
     switch ($_SESSION['enabledShippingMethods'][$i]) {
 public static function getShippingPriceProduct($productid = 0, $productOptionId = 0, $userId = "", $destination_country = "", $destination_state = "", $destination_zip = "")
 {
     global $tableprefix;
     $adminCurrency = GetAdminCurrency();
     if (isCartEmpty($userId)) {
         clsGenerateShippingControl::getNoShippingControl($product_option_id);
         return 0;
     }
     if (get_magic_quotes_gpc()) {
         $_POST = array_map('stripslashes_deep', $_POST);
         $_GET = array_map('stripslashes_deep', $_GET);
         $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
     }
     if ($destination_country == "" && $destination_state == "" && $destination_zip == "") {
         $userAddress = clsGenerateShippingControl::getuserAddress($userId);
         if (count($userAddress) > 0) {
             $destination_state = $userAddress['state'];
             $destination_country = $userAddress['country'];
             $destination_zip = $userAddress['zip'];
         }
     }
     $uspsRequired_Service = array("Express Mail", "Express Mail Hold For Pickup", "Express Mail Sunday/Holiday Delivery", "Priority Mail", "Parcel Post", "Priority Mail Large Flat Rate Box", "\nPriority Mail Medium Flat Rate Box", "Priority Mail Small Flat Rate Box", "Priority Mail Flat Rate Envelope", "Media Mail", "Library Mail");
     //===================Getting Currency Type=========================
     $currency_attributes = displayCurrencyType();
     $flatrateEnabled = getSettingsValue('enable_flatrate');
     /*display the active template*/
     //set shipping gateway and doing basic settings
     include_once 'fedex/fedex.php';
     $sql = "select * from " . $tableprefix . "fedexsettings ";
     $rs = mysql_query($sql) or die(mysql_error());
     if (mysql_num_rows($rs) > 0) {
         $serviceName = array();
         $row = mysql_fetch_array($rs);
         $fedexaccno = stripslashes($row['FedexAccno']);
         $fedexmeterno = stripslashes($row['FedexMeterno']);
         $weightunits = $row['FedexWeight'];
         $server = $row['FedexServer'];
         $dropoff = stripslashes($row['FedexDropOff']);
         $packageTypes = stripslashes($row['FedexPackage']);
         $sName = $row['FedexService'];
         $currency = $row['FedexCurrency'];
         if ($_SESSION["sessShippingMethod"] == "FDXE") {
             $sarry = $fedexService;
             $shippingTitle = "Fedex Express Shipping";
         } else {
             $sarry = $fedexGroundService;
             $shippingTitle = "Fedex Express Ground Shipping";
         }
     }
     // end num rows check
     switch ($server) {
         case "test":
             $fedexserver = "https://gatewaybeta.fedex.com/GatewayDC";
             break;
         case "production":
             // change this to actual server when go on live
             $fedexserver = "https://gatewaybeta.fedex.com/GatewayDC";
             break;
         default:
             $fedexserver = "https://gatewaybeta.fedex.com/GatewayDC";
             break;
     }
     //// check enabled shipping is usps or not
     include_once "usps/xmlparser.php";
     include_once 'usps/usps.php';
     $shippingTitle = "USPS";
     $sql = "select * from " . $tableprefix . "usps_settings ";
     $rs = mysql_query($sql) or die(mysql_error());
     if (mysql_num_rows($rs) > 0) {
         $row = mysql_fetch_array($rs);
         $uspsid = $row['username'];
         $server = $row['server'];
     }
     // end num rows check
     switch ($server) {
         case "test":
             $uspsserver = "http://testing.shippingapis.com/ShippingAPITest.dll";
             break;
         case "production":
             //change this line when usps is on live
             $uspsserver = "http://Production.ShippingAPIs.com/ShippingAPI.dll";
             break;
         default:
             $uspsserver = "http://testing.shippingapis.com/ShippingAPITest.dll";
             break;
     }
     // end switch
     require_once "ups.php";
     include_once "shipping.php";
     include_once 'http_client.php';
     $shippingTitle = "UPS";
     // Shipping setting for UPS Shipping
     $select_shipping_settings = "SELECT * FROM " . $tableprefix . "shipping_settings";
     $result_shipping_settings = mysql_query($select_shipping_settings);
     if (mysql_num_rows($result_shipping_settings) > 0) {
         $rs_ship = mysql_fetch_array($result_shipping_settings);
         $ups_weight = $rs_ship['nShippingweight'];
         $ups_rate = $rs_ship['ups_rate'];
         $ups_container = $rs_ship['container_type'];
         $ups_type = $rs_ship['address_quote_method'];
     }
     $upsrate = new Ups();
     // select product details
     $select_cart_details = "SELECT prd.product_id,prd.product_name,po.product_option_id,po.product_length,po.product_width,po.product_height,crt.quantity,\n                       po.product_shipping_weight,art.country AS origin_country,art.state AS origin_state,art.zip AS origin_zip,art.artist_id,\n                       art.defaultflatrate,art.additionalflatrate, prd.eUps, prd.eUsps , prd.eFedex , prd.fFlatRateShippingAmount, prd.fAdditionalItemCost\n                       FROM " . $tableprefix . "cart crt\n                       INNER JOIN " . $tableprefix . "product_options po ON crt.product_option_id = po.product_option_id\n                       INNER JOIN " . $tableprefix . "products prd ON prd.product_id = po.product_id\n                       INNER JOIN " . $tableprefix . "artists art ON art.artist_id = prd.product_artist_id\n                       WHERE crt.user_id = '" . mysql_real_escape_string($userId) . "' AND po.product_option_id = '" . mysql_real_escape_string($productOptionId) . "' ORDER BY crt.cart_id";
     $result_cart_details = mysql_query($select_cart_details) or die(mysql_error());
     $_SESSION["SHIPPING_DETAILS"] = array();
     $_SESSION["SHIPPING_TOTAL"] = 0;
     $productArray = array();
     $resultShippingArray = array();
     if (mysql_num_rows($result_cart_details) == 0) {
         //as no products there is no point in staying in shipping options
         clsGenerateShippingControl::getNoShippingControl($product_option_id);
         return 0;
     } else {
         //Now we need to take shipping rates a products
         $cart_details_row = mysql_fetch_array($result_cart_details);
         $shipping_weight = trim($cart_details_row['product_shipping_weight']);
         $origin_country = $cart_details_row['origin_country'];
         $origin_state = $cart_details_row['origin_state'];
         $origin_zip = $cart_details_row['origin_zip'];
         $product_name = $cart_details_row['product_name'];
         $artist_id = $cart_details_row['artist_id'];
         $product_id = $cart_details_row['product_id'];
         $product_option_id = $cart_details_row['product_option_id'];
         $optionsStr = "";
         $optionVal = getProductOptionsName($product_option_id);
         if ($optionVal != "") {
             $optionsStr = "<br>" . $optionVal;
         }
         $productArray[$product_option_id] = $product_name . $optionsStr;
         $quantity = trim($cart_details_row['quantity']);
         $product_length = $cart_details_row['product_length'];
         $product_height = $cart_details_row['product_height'];
         $product_width = $cart_details_row['product_width'];
         // Take product shippings
         $productShippingArray = array();
         if ($cart_details_row['eUps'] == 'Y') {
             $productShippingArray[] = 'UPS';
         }
         if ($cart_details_row['eFedex'] == 'Y') {
             $productShippingArray[] = 'FDXG';
         }
         if ($cart_details_row['eUsps'] == 'Y') {
             $productShippingArray[] = 'USPS';
         }
         if ($cart_details_row['fFlatRateShippingAmount'] > 0) {
             $productShippingArray[] = 'Flat Rate';
             $FlatRateShippingAmount = $cart_details_row['fFlatRateShippingAmount'];
             $AdditionalItemCost = $cart_details_row['fAdditionalItemCost'];
         }
         /*  echo '<br>' . $origin_state;
             echo '<br>' . $origin_country;
             echo '<br>' . $origin_zip;
             echo '<br>' . $destination_state;
             echo '<br>' . $destination_country;
             echo '<br>' . $destination_zip;*/
         //print_r($productShippingArray);
         foreach ($productShippingArray as $key => $shippingMethod) {
             //  $shippingMethod = $value; // set product shipping
             //set for ups only
             $shippingMethod = trim($shippingMethod);
             //======================Getting rates for each product from shipping gateways-Santhosh=================================
             switch ($shippingMethod) {
                 case "FDXE":
                 case "FDXG":
                     $shippingMode = $shippingMethod;
                     if (is_array($sarry)) {
                         // check service is an array or not
                         foreach ($sarry as $serviceNames) {
                             $fedex_shipping_weight = $shipping_weight * $quantity;
                             list($service, $serviceName) = split('-', $serviceNames);
                             $fedex = new Fedex();
                             $fedex->setServer($fedexserver);
                             $fedex->setAccountNumber($fedexaccno);
                             //Get your own - this will not work...
                             $fedex->setMeterNumber($fedexmeterno);
                             //Get your own - this will not work...
                             $fedex->setCarrierCode($shippingMode);
                             $fedex->setDropoffType($dropoff);
                             $fedex->setService($service, $serviceName);
                             $fedex->setPackaging($packageTypes);
                             $fedex->setWeightUnits($weightunits);
                             $fedex->setWeight($fedex_shipping_weight);
                             $fedex->setOriginStateOrProvinceCode($origin_state);
                             $fedex->setOriginPostalCode($origin_zip);
                             $fedex->setOriginCountryCode($origin_country);
                             $fedex->setDestStateOrProvinceCode($destination_state);
                             $fedex->setDestPostalCode($destination_zip);
                             $fedex->setDestCountryCode($destination_country);
                             $fedex->setPayorType("SENDER");
                             $fedexprice = $fedex->getPrice();
                             $fedexrate[] = $fedexprice->price->rate;
                             $fedexerror[] = $fedexprice->error->description;
                             if ($fedexprice->error->description == "" && $fedexprice->serviceName != "" && $fedexprice->price->rate != "") {
                                 $resultShippingArray[$product_option_id][] = array("service_name" => $fedexprice->serviceName, "rate" => $fedexprice->price->rate);
                             }
                         }
                         // end foreach
                     }
                     // end array check
                     break;
                 case "USPS":
                     $usps_shipping_weight = $shipping_weight * $quantity;
                     if ($usps_shipping_weight < 1) {
                         $usps_shipping_weight = 1;
                     }
                     $usps_shipping_weightSplit = explode(".", $usps_shipping_weight);
                     $shipping_pounds = $usps_shipping_weightSplit[0];
                     $ouncelength = count_digit($usps_shipping_weightSplit[1]);
                     if ($ouncelength == 0) {
                         $shipping_ounces = 0;
                     }
                     if ($ouncelength == 1) {
                         $shipping_ounces = $usps_shipping_weightSplit[1] / 10 * 16;
                     }
                     if ($ouncelength == 2) {
                         $shipping_ounces = $usps_shipping_weightSplit[1] / 100 * 16;
                     }
                     if ($ouncelength == 3) {
                         $shipping_ounces = $usps_shipping_weightSplit[1] / 1000 * 16;
                     }
                     if ($ouncelength == 4) {
                         $shipping_ounces = $usps_shipping_weightSplit[1] / 10000 * 16;
                     }
                     $usps = new USPS();
                     if ($server == "test") {
                         $usps->setWeight(10, 5);
                         $usps->setDestZip("20008");
                         $usps->setOrigZip("10022");
                     } else {
                         $usps->setDestZip($destination_zip);
                         $usps->setOrigZip($origin_zip);
                         $usps->setWeight($shipping_pounds, $shipping_ounces);
                     }
                     $usps->setServer($uspsserver);
                     $usps->setUserName($uspsid);
                     $uspspaswd = "";
                     $usps->setPass($uspspaswd);
                     $usps->setService("All");
                     //$usps->setContainer("Flat Rate Box");
                     $usps->setCountry("USA");
                     $usps->setMachinable("true");
                     $usps->setSize("REGULAR");
                     $uspsprice = array();
                     $uspsprice = $usps->getPrice();
                     $special_chars = "&lt;sup&gt;&amp;reg;&lt;/sup&gt;";
                     if ($uspsprice->error->description == "") {
                         foreach ($uspsprice->list as $eachItem) {
                             if ($eachItem->mailservice != "" && $eachItem->rate != "") {
                                 $eachItemServicename = str_replace($special_chars, "", $eachItem->mailservice);
                                 if (in_array($eachItemServicename, $uspsRequired_Service)) {
                                     $resultShippingArray[$product_option_id][] = array("service_name" => $eachItemServicename, "rate" => $eachItem->rate);
                                 }
                             }
                         }
                     }
                     break;
                 case "UPS":
                     $ups_types = clsGenerateShippingControl::getupsShippingTypes();
                     $ups_shipping_weight = $shipping_weight * $quantity;
                     $ups_shipping_weight = $ups_shipping_weight < 0.1 ? 0.1 : $ups_shipping_weight;
                     foreach ($ups_types as $types => $ups) {
                         $upsrate->upsProduct($types);
                         // See upsProduct() function for codes
                         $upsrate->origin($origin_zip, $origin_country);
                         // Use ISO country codes!
                         $upsrate->dest($destination_zip, $destination_country);
                         // Use ISO country codes!
                         $upsrate->rate($ups_rate);
                         // See the rate() function for codes
                         $upsrate->container($ups_container);
                         // See the container() function for codes
                         $upsrate->weight(number_format($ups_shipping_weight, 2, ".", ""));
                         $upsrate->rescom($ups_type);
                         // See the rescom() function for codes
                         $quote = $upsrate->getQuote();
                         if ($quote != "error" && $ups != "" && $quote != "") {
                             $resultShippingArray[$product_option_id][] = array("service_name" => $ups, "rate" => $quote);
                         }
                         // end price empty check
                     }
                     //end foreach
                     break;
                 case "Flat Rate":
                     $flat_rate_name = "Flat Rate";
                     $first_Item_charge = $FlatRateShippingAmount;
                     $additional_Item_charge = $AdditionalItemCost;
                     $rate = $first_Item_charge + $additional_Item_charge * ($quantity - 1);
                     $resultShippingArray[$product_option_id][] = array("service_name" => stripslashes($flat_rate_name), "rate" => $rate);
                 default:
             }
             // if the rate array is empty for other shipping Options check whether
             // admin has enabled the flat rate shipping so that customer can still
             // buy with the flat option.
             $Selected_Shipping_options = $shippingTitle;
             if (empty($selectedShippingOption)) {
                 $selectedShippingOption = $shippingTitle;
             }
             $shipping_options_availabe = count($resultShippingArray[$product_option_id]);
         }
         // end while loop
     }
     return $resultShippingArray;
 }
">
						<input type="hidden" name="upload" value="1">


<?php 
$sql_cart = "SELECT c.*,(p.product_price+po.additional_price) AS product_price,p.product_name,p.product_description,p.product_code,p.product_artist_id,po.discount,p.vdigital_product\n\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\tWHERE c.user_id = '" . $userid . "' ";
$res_cart = mysql_query($sql_cart) or die(mysql_error());
$total_product_amt = 0;
if (mysql_num_rows($res_cart) > 0) {
    $i = 1;
    while ($row_cart = mysql_fetch_array($res_cart)) {
        $cart_productid = $row_cart["product_id"];
        $cart_quantity = $row_cart["quantity"];
        $productprice = number_format($row_cart['product_price'], 2, ".", "");
        $cart_productname = stripslashes($row_cart["product_name"]);
        $optionsStr = getProductOptionsName($row_cart["product_option_id"]);
        $product_description = stripslashes($row_cart["product_description"]);
        $productcode = stripslashes($row_cart["product_code"]);
        $productdiscount = $row_cart["discount"];
        $unitprice = $productprice - $productdiscount / 100 * $productprice;
        $unitprice = number_format($unitprice, 2, ".", "");
        $total_product_amt += $unitprice;
        //discounted amt
        ?>
					
						<input type="hidden" name="item_name_<?php 
        echo $i;
        ?>
" value="<?php 
        echo $cart_productname . $optionsStr . ' - ' . strip_tags($product_description);
        ?>
function sendStockreordermail($product_option_id, $quantity = 0)
{
    global $tableprefix;
    $queryOrderDetail = "SELECT p.*,s.*,po.product_stock\n                                    FROM " . $tableprefix . "product_options po\n                                    INNER JOIN " . $tableprefix . "products p ON p.product_id = po.product_id\n                                    INNER JOIN " . $tableprefix . "artists s ON s.artist_id = p.product_artist_id\n                                    WHERE po.product_option_id=" . $product_option_id . " ";
    $orderDetailQ = mysql_query($queryOrderDetail);
    $optionVal = getProductOptionsName($product_option_id);
    if (mysql_num_rows($orderDetailQ) > 0) {
        $productObj = mysql_fetch_object($orderDetailQ);
        $currentStock = $productObj->product_stock - $quantity;
        $mailcontent = '<table width="100%" cellpadding="0" cellspacing="0" border="0" style="background-color:#F5F5F5;font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#000000; ">
		<tr>
		<td style="font-weight:bold; color:#CE0221; font-size:14px; padding:15px 15px 5px 15px;" align="left" valign="top">
		Product Restocking Information
		</td>
		</tr>
		<tr>
		<td  align="left" valign="top" style="padding:5px 15px 15px 15px; ">
		<table width="100%" cellpadding="5" cellspacing="0" border="0" style="background-color:#FFFFFF; border:#D5D5D5 solid 1px;font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#000000; ">
		<tr>
		<td width="40%">Store Name</td>
		<td width="60%" style="font-size:13px; color:#991818; font-weight:bold; ">' . SITE_NAME . '(' . SITE_URL . ')</td>
		</tr>';
        $mailcontent .= '<tr>
		<td >Product Name</td>
		<td  style="font-size:13px; color:#991818; font-weight:bold; ">' . stripslashes($productObj->product_name) . " " . $optionVal . '</td>
		</tr>
		<tr>
		<tr>
		<td >Current Stock </td>
		<td  style="font-size:13px; color:#991818; font-weight:bold; ">' . $currentStock . '</td>
		</tr>
		<tr>
		</table>
		</td>
		</tr></table>';
        $mailcontent_reorder = readEmailTemplate('stock_reorder');
        $mailcontent_reorder = str_replace('[product_details]', $mailcontent, $mailcontent_reorder);
        //   echo $mailcontent_reorder;
        $mail_send_details_seller = '<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   <title>Online reservation</title>
  <link href="' . SITE_URL . '/style/template1-admin.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="103%" cellspacing="10" cellpadding="0" bgcolor="#EAEAEA" >
   <tr>
     <td align="center" valign="top">

         <table width="600" border="0" cellpadding="0" cellspacing="0" bordercolor="#EAEAEA" bgcolor="#FFFFFF" class="manage_table">
            <tr>
               <td align="right" >
              </td>
            </tr>
            <tr>
               <td valign="middle" align="left"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                 <tr>
                   <td bgcolor="#EAEAEA" ><img src=' . SITE_URL . '/banners/' . getSettingsValue('site_logo') . ' width="125" height="60"/></td>
                 </tr>
               </table></td>
            </tr>
			<tr>
			<td align="left" height="50"> Dear ' . $productObj->first_name . '&nbsp;' . $productObj->last_name . ', </td>
			<tr>
			<tr>
			<td align="left">Stock reorder level information - ' . SITE_NAME . ' .The details are as follows</td>
			</tr>

			<tr>
              <td align="center" valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="10">
                <tr>
                  <td align="left">' . $mailcontent_reorder . '</td>
                </tr>

              </table></td>
            </tr>

            <tr>
               <td align="center" bgcolor="#EAEAEA" class="footer">
                  <p>&nbsp;</p>
              </td>
            </tr>
       </table>

     </td>
   </tr>
</table>
</body>
</html>';
        // echo $mail_send_details_seller;
        $headers = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
        $headers .= "From: " . SITE_NAME . "<" . SITE_EMAIL . ">" . "\r\n";
        $headers .= "Reply-To: " . SITE_NAME . "<" . SITE_EMAIL . ">" . "\r\n";
        $headers .= "Return-Path: " . SITE_NAME . "<noreply@" . SITE_NAME . ">" . "\r\n";
        $headers .= "Organization: " . SITE_NAME . "\r\n";
        $ordersubject_fillstock = "Stock Reorder at " . SITE_NAME;
        //echo $productObj->email;
        //$productObj->email="*****@*****.**";
        $mailsent = mail($productObj->email, $ordersubject_fillstock, $mail_send_details_seller, $headers);
    }
    //$productlist_fillstock
}
function UseCase1($google_id, $google_key, $sandbox, $orderid = '', $shipping_check, $digital_check)
{
    global $tableprefix, $_SESSION;
    $gift_coupon_flag = 0;
    $google_id = $google_id;
    // Merchant ID
    $google_key = $google_key;
    // Merchant Key
    $google_demo = $sandbox;
    // "YES" if in test mode, "NO" if in live mode
    $shipping_cost = number_format($_SESSION['SESS_upscost'], 2, ".", "");
    $totaltaxrate = number_format($_SESSION['session_taxrate'], 2, ".", "");
    $referrer = $_SERVER["HTTP_REFERER"];
    if (isset($_SESSION["sess_guest_username"]) && $_SESSION["sess_guest_username"] != '') {
        $usertype = 'guest';
    } else {
        $usertype = 'user';
    }
    if (!isset($_SESSION['SESS_google_checkout'])) {
        $totaltopay = number_format(getCartTotal($_SESSION["sess_userid"]), 2, ".", "");
        $hide_shipping_division = hideShipping();
        /*-------function call to check whether cart contains digital or gift coupon products so as to hide shipping------*/
        $check_shipping_enable = checkShippingEnable();
        if ($check_shipping_enable == "Y" && $hide_shipping_division == 1) {
            $shipping_cost = $_SESSION['SHIPPING_TOTAL'];
            $totaltopay = number_format($totaltopay, 2, ".", "");
            $totaltopay = $totaltopay + $shipping_cost;
        }
        $amountpaid = number_format($_SESSION['amount_paid'], 2, ".", "");
        $sql = "INSERT INTO  " . $tableprefix . "orders (\n\t\t\t\tuser_id,\n\t\t\t\tbilling_first_name,\n\t\t\t\tbilling_last_name,\n\t\t\t\tbilling_address1,\n\t\t\t\tbilling_address2,\n\t\t\t\tbilling_city,\n\t\t\t\tbilling_state,\n\t\t\t\tbilling_country,\n\t\t\t\tbilling_zip,\n\t\t\t\tbilling_fax,\n\t\t\t\tbilling_email,\n\t\t\t\tbilling_phone,\n\t\t\t\tshipping_first_name,\n\t\t\t\tshipping_last_name,\n\t\t\t\tshipping_address1,\n\t\t\t\tshipping_address2,\n\t\t\t\tshipping_city,\n\t\t\t\tshipping_state,\n\t\t\t\tshipping_country,\n\t\t\t\tshipping_zip,\n\t\t\t\tshipping_fax,\n\t\t\t\tshipping_email,\n\t\t\t\tshipping_phone,\n\t\t\t\tprefered_shippin_method,\n\t\t\t\torder_date,\n\t\t\t\torder_total_price,\n\t\t\t\ttaxrate,\n\t\t\t\torder_status,\n\t\t\t\ttransaction_id,\n\t\t\t\tvorder_currency" . $nameCouponCode . ",\n\t\t\t\tnamount_paid,\n                                buyer_comments,\n                                vpayment_status\n\t\t\t\t) VALUES(\n\t\t\t\t'" . addslashes($_SESSION["sess_userid"]) . "',\n\t\t\t\t'" . addslashes($_SESSION["sessBillingFirstName"]) . "',\n\t\t\t\t'" . addslashes($_SESSION["sessBillingLastName"]) . "',\n\t\t\t\t'" . addslashes($_SESSION["sessBillingAddress1"]) . "',\n\t\t\t\t'" . addslashes($_SESSION["sessBillingAddress2"]) . "',\n\t\t\t\t'" . addslashes($_SESSION["sessBillingCity"]) . "',\n\t\t\t\t'" . addslashes($_SESSION["sessBillingState"]) . "',\n\t\t\t\t'" . addslashes($_SESSION["sessBillingCountry"]) . "',\n\t\t\t\t'" . addslashes($_SESSION["sessBillingZIP"]) . "',\n\t\t\t\t'" . addslashes($_SESSION["sessBillingFAX"]) . "',\n\t\t\t\t'" . addslashes($_SESSION["sessBillingEmail"]) . "',\n\t\t\t\t'" . addslashes($_SESSION["sessBillingPhone"]) . "',\n\t\t\t\t'" . addslashes($_SESSION["sessShippingFirstName"]) . "',\n\t\t\t\t'" . addslashes($_SESSION["sessShippingLastName"]) . "',\n\t\t\t\t'" . addslashes($_SESSION["sessShippingAddress1"]) . "',\n\t\t\t\t'" . addslashes($_SESSION["sessShippingAddress2"]) . "',\n\t\t\t\t'" . addslashes($_SESSION["sessShippingCity"]) . "',\n\t\t\t\t'" . addslashes($_SESSION["sessShippingState"]) . "',\n\t\t\t\t'" . addslashes($_SESSION["sessShippingCountry"]) . "',\n\t\t\t\t'" . addslashes($_SESSION["sessShippingZIP"]) . "',\n\t\t\t\t'" . addslashes($_SESSION["sessShippingFAX"]) . "',\n\t\t\t\t'" . addslashes($_SESSION["sessShippingEmail"]) . "',\n\t\t\t\t'" . addslashes($_SESSION["sessShippingPhone"]) . "',\n\t\t\t\t'" . addslashes($_SESSION["sessShippingDisplayName"]) . "',\n\t\t\t\tnow(),\n\t\t\t\t'" . addslashes($totaltopay) . "',\n\t\t\t\t'" . addslashes($totaltaxrate) . "',\n\t\t\t\t'1',\n\t\t\t\t'" . addslashes($tx_token) . "',\n\t\t\t\t'" . $currency_attributes[2] . "'" . $valueCouponCode . ",\n\t\t\t\t'" . addslashes($amountpaid) . "',\n                                '" . addslashes($_SESSION["SESS_BUYER_COMMENTS"]) . "',\n                                'P'\n\t\t\t\t)";
        mysql_query($sql);
        $orderid = mysql_insert_id();
        // Updating Buying Process using Gift Certificate Code
        if ($_SESSION['sess_giftcertificate_code'] != '' && $_SESSION['sess_gift_amount_used'] != '') {
            $sql_up = "UPDATE " . $tableprefix . "orders SET vgiftcertificate_code='" . addslashes($_SESSION['sess_giftcertificate_code']) . "',\n\t\t\t\t\t\tnused_gift_amount=(nused_gift_amount + " . $_SESSION['sess_gift_amount_used'] . " )WHERE order_id='" . $orderid . "' ";
            $rs_up = mysql_query($sql_up) or die(mysql_error());
            $sql_gift = "UPDATE " . $tableprefix . "giftcertificates SET nused_gift_amount=(nused_gift_amount + " . $_SESSION['sess_gift_amount_used'] . " )\n\t\t\t\t\t\t\tWHERE vgift_coupon_code ='" . addslashes($_SESSION['sess_giftcertificate_code']) . "' ";
            $rs_gift = mysql_query($sql_gift) or die(mysql_error());
        }
        // End Gift Certificate Updation
        // Store Coupon Code Details to Order Table // Modified By Asha ON 21-02-2011
        if ($_SESSION['couponCode_det'] != '') {
            // Update Order with Coupon Code Discount
            $sql_coupon_update = "UPDATE " . $tableprefix . "orders SET  couponCodeDiscount ='" . $_SESSION['couponCode_det']['ccDiscount'] . "', couponCode ='" . $_SESSION['couponCode_det']['ccCode'] . "' where order_id='" . $orderid . "' ";
            $rs_update_c = mysql_query($sql_coupon_update) or die(mysql_error());
            // End Update
        }
        // End Coupon Code Modification
        $check_shipping_enable = checkShippingEnable();
        if ($check_shipping_enable == "Y" && $hide_shipping_division == 1) {
            /*---------------inserting the shipping details----------------*/
            $select_cart_products = "SELECT c.product_option_id,c.product_id,p.product_name,po.product_shipping_weight 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                                                    WHERE c.user_id = " . $_SESSION["sess_userid"];
            $result_cart_products = mysql_query($select_cart_products) or die(mysql_error());
            if (mysql_num_rows($result_cart_products) > 0) {
                while ($cart_obj = mysql_fetch_object($result_cart_products)) {
                    if (isset($_SESSION["SHIPPING_DETAILS"][$cart_obj->product_option_id]['preffered_shipping'])) {
                        $product_name = $cart_obj->product_name;
                        $optionVal = getProductOptionsName($cart_obj->product_option_id);
                        $shipping_name = $_SESSION["SHIPPING_DETAILS"][$cart_obj->product_option_id]['preffered_shipping'];
                        $shipping_cost = $_SESSION["SHIPPING_DETAILS"][$cart_obj->product_option_id]['rate'];
                        $product_shipping_weight = $cart_obj->product_shipping_weight;
                        $ship_product_option_id = $cart_obj->product_option_id;
                        $product_name .= $optionVal;
                        $insert_shipping = "INSERT INTO " . $tableprefix . "shipping_details\n                                                                 (\n                                                                 norder_id,\n                                                                 vshipping_currency,\n                                                                 dshipped_date,\n                                                                 nshp_status,\n                                                                 user_id,\n                                                                 nshp_productid,\n                                                                 nproduct_option_id,\n                                                                 nshp_productname,\n                                                                 vshipping_name,\n                                                                 nshipping_cost,\n                                                                 nshipping_weight\n                                                                 )\n                                                                 VALUES\n                                                                 (\n                                                                 " . $orderid . ",\n                                                                 '" . $currency_attributes[2] . "',\n                                                                 now(),\n                                                                 'C',\n                                                                 '" . addslashes($_SESSION["sess_userid"]) . "',\n                                                                 " . $cart_obj->product_id . ",\n                                                                 " . $ship_product_option_id . ",\n                                                                 '" . addslashes($product_name) . "',\n                                                                 '" . addslashes($shipping_name) . "',\n                                                                 '" . $shipping_cost . "',\n                                                                 '" . $product_shipping_weight . "'\n                                                                  )\n                                                                ";
                        mysql_query($insert_shipping) or die(mysql_error());
                    }
                }
                // end while
            }
            // end if
        }
        // end of shipping if
        /************************** Affilate payment block*********************************************/
        $sql = "select * from  " . $tableprefix . "users where user_id='" . addslashes($_SESSION["sess_userid"]) . "'";
        $result = mysql_query($sql);
        $row = mysql_fetch_array($result);
        if ($row["affiliate_id"] != "" && $row["affiliate_id"] != "0" && $row["vaff_type"] != "paid") {
            $aid = $row['affiliate_id'];
            $userid = $row['user_id'];
            $txtUserName = $row['user_name'];
            $txtFirstName = $row['first_name'];
            $txtEmail = $row['email'];
            $txtorderdamount = $totaltopay;
            $sql1 = "SELECT * FROM " . $tableprefix . "settings ";
            $result1 = mysql_query($sql1);
            if (mysql_num_rows($result1) != 0) {
                $row1 = mysql_fetch_array($result1);
                /*referral charge calculation based on the currency type*/
                $txtReferralCharge = $row1["referral_charge"];
            }
            $var_aff_comm = $txtorderdamount * $txtReferralCharge / 100;
            $sql2 = "INSERT INTO " . $tableprefix . "affiliate_registrations (\n\t\t\t\t\t\t\t\t\t\t\taffiliate_id,\n\t\t\t\t\t\t\t\t\t\t\tuser_id,\n\t\t\t\t\t\t\t\t\t\t\torder_id,\n\t\t\t\t\t\t\t\t\t\t\tuser_name ,\n\t\t\t\t\t\t\t\t\t\t\tuser_first_name,\n\t\t\t\t\t\t\t\t\t\t\tuser_last_name,\n\t\t\t\t\t\t\t\t\t\t\tuser_email,\n\t\t\t\t\t\t\t\t\t\t\treferral_charge,\n\t\t\t\t\t\t\t\t\t\t\tregistration_date,\n\t\t\t\t\t\t\t\t\t\t\tuser_totalpurchasedamount\n\t\t\t\t\t\t\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t\t\t\t\t\t'" . addslashes($aid) . "',\n\t\t\t\t\t\t\t\t\t\t\t'" . addslashes($userid) . "',\n\t\t\t\t\t\t\t\t\t\t\t'" . addslashes($orderid) . "',\n\t\t\t\t\t\t\t\t\t\t\t'" . addslashes($txtUserName) . "',\n\t\t\t\t\t\t\t\t\t\t\t'" . addslashes($txtFirstName) . "',\n\t\t\t\t\t\t\t\t\t\t\t'" . addslashes($txtLastName) . "',\n\t\t\t\t\t\t\t\t\t\t\t'" . addslashes($txtEmail) . "',\n\t\t\t\t\t\t\t\t\t\t\t'" . addslashes($var_aff_comm) . "',\n\t\t\t\t\t\t\t\t\t\t\tnow(),'{$totaltopay}'\n\t\t\t\t\t\t\t\t\t\t\t)";
            mysql_query($sql2);
            $sql3 = " update " . $tableprefix . "users set vaff_type='paid' where user_id='" . addslashes($_SESSION["sess_userid"]) . "'";
            $result3 = mysql_query($sql3);
        }
        // end if Affiliate Registraion
        /************************** Affilate payment block*********************************************/
        //echo "sql==".$sql."<br><br>";
        $product_download_details = "Product Download Details\r\n";
        $product_download_details .= "-----------------------\r\n";
        $product_download_flag = 0;
        $download_link = "";
        $sql = "SELECT c.*,(p.product_price+po.additional_price) AS product_price,p.product_name,p.product_code,p.product_artist_id,po.discount,\n\t\t\t\t\t\tp.vdigital_product,ar.commission\n\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                                INNER JOIN " . $tableprefix . "artists ar ON ar.artist_id = p.product_artist_id\n\t\t\t\tWHERE c.user_id = '" . addslashes($_SESSION["sess_userid"]) . "' ";
        $res = mysql_query($sql);
        $product_commission_amt = 0;
        $gift_coupon_flag = 0;
        $artists = array();
        if (mysql_num_rows($res) != 0) {
            $i = 0;
            while ($row = mysql_fetch_array($res)) {
                $productid = $row["product_id"];
                $product_option_id = $row["product_option_id"];
                $quantity = $row["quantity"];
                /*product price is calculated based on currency type*/
                $converted_price = $row["product_price"];
                $productprice = number_format($converted_price, 2, ".", "");
                //$productprice =  $row["product_price"];
                $productname = $row["product_name"];
                $optionVal = getProductOptionsName($product_option_id);
                $productname .= $optionVal;
                $productcode = $row["product_code"];
                $productdiscount = $row["discount"];
                $artistid = $row["product_artist_id"];
                /*========================================Gift Certificate Section=================================*/
                $select_gift_code = "SELECT vgift_coupon_code,ngift_coupon_amount\n\t\t\t\t\t FROM " . $tableprefix . "giftcoupon_master\n\t\t\t\t\t WHERE ngift_product_id = " . $productid;
                $result_gift_code = mysql_query($select_gift_code) or die(mysql_error());
                if (mysql_num_rows($result_gift_code) > 0) {
                    // start of first if
                    $gift_coupon_product_id = $productid;
                    while ($gift_code_row = mysql_fetch_array($result_gift_code)) {
                        // start of while 2
                        /*--------------------creating random gift coupon code and updating the database-----------------------*/
                        $gift_coupon_code = "GC" . randomGiftCouponKey();
                        $giftamount = $productprice * $quantity;
                        $insert_coupon_code = "INSERT INTO " . $tableprefix . "giftcertificates(vgift_coupon_code,ngift_product_id,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tngift_order_id,ngift_coupon_amount,user_id,seller_id)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tVALUES('" . $gift_coupon_code . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" . $row["product_id"] . ",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" . $orderid . ",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" . $giftamount . ",'" . $userid . "','" . $artistid . "')";
                        mysql_query($insert_coupon_code) or die(mysql_error());
                    }
                    $gift_coupon_flag = 1;
                }
                // end of mysql number of rows check
                //=======================End Gift Certificate Section ===================================
                if ($row['vdigital_product'] == "Y") {
                    $digital_product_id = $row["product_id"];
                    $select_product_digital_code = "SELECT vdigital_product_name,vdigital_product_code,ndownload_try,ndownload_expiry,ndownload_expiry_days\n\t\t\t\t\t\t\t\t\t\tFROM " . $tableprefix . "digital_product\n\t\t\t\t\t\t\t\t\t\tWHERE ndigital_productid = " . $row["product_id"] . " AND ndigital_orderid =0 ";
                    $result_product_digital_code = mysql_query($select_product_digital_code);
                    if (mysql_num_rows($result_product_digital_code) > 0) {
                        while ($product_digital_code_row = mysql_fetch_array($result_product_digital_code)) {
                            /*--------------------creating random product download code and updating the database-----------------------*/
                            $digital_product_code = randomDigitalProduct();
                            $expiry_days = $product_digital_code_row['ndownload_expiry_days'];
                            $valid_date_upto = date("Y-m-d H:s:m", mktime(date("H"), date("i"), date("s"), date("m"), date("d") + $expiry_days, date("Y")));
                            /*-------Calculating the download expiry days----------*/
                            /*$update_product_digital_code = "UPDATE ".$tableprefix."digital_product
                            									SET vdigital_product_code = '".$digital_product_code."',
                            									ndigital_orderid = ".$orderid.",
                            									ndownload_expiry = '".$valid_date_upto."'
                            									WHERE ndigital_productid = ".$row["product_id"];
                            		mysql_query($update_product_digital_code) or die(mysql_error());*/
                            /*---------selecting the download try and download expiry date-----------*/
                            $select_digital_product_details = "SELECT ndownload_try,ndownload_expiry\n\t\t\t\t\t\t\t\t\t\t\t\t\t   \t\t\t\t   FROM " . $tableprefix . "digital_product WHERE ndigital_productid = " . $productid;
                            $result_digital_product_details = mysql_query($select_digital_product_details) or die(mysql_error());
                            $digital_product_details_row = mysql_fetch_assoc($result_digital_product_details);
                            $product_download_try = $digital_product_details_row["ndownload_try"];
                            $download_expiry_date = $digital_product_details_row["ndownload_expiry"];
                            /*---------selecting the download try and download expiry date-----------*/
                            $select_digital_count = "SELECT ndigital_id FROM " . $tableprefix . "digital_product WHERE ndigital_orderid = " . $orderid;
                            $result_digital_count = mysql_query($select_digital_count) or die(mysql_error());
                            //echo "digital count = ".mysql_num_rows($result_digital_count)."\n";
                            //echo "order count = ".$row["quantity"];
                            for ($i = 1; $i <= $row["quantity"]; $i++) {
                                /*-------Calculating the download expiry days----------*/
                                $expiry_days = $product_digital_code_row['ndownload_expiry_days'];
                                $valid_date_upto = date("Y-m-d H:s:m", mktime(date("H"), date("i"), date("s"), date("m"), date("d") + $expiry_days, date("Y")));
                                /*-------Calculating the download expiry days----------*/
                                $digital_product_code = randomDigitalProduct();
                                $insert_product_digital_code = "INSERT INTO " . $tableprefix . "digital_product(vdigital_product_name,ndigital_productid,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tndigital_orderid,vdigital_product_code,ndownload_try,ndownload_count,ndownload_expiry,ndownload_expiry_days,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tndownload_status)VALUES('" . addslashes($product_digital_code_row['vdigital_product_name']) . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" . $row["product_id"] . ",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" . $orderid . ",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'" . $digital_product_code . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" . $product_digital_code_row['ndownload_try'] . ",0,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'" . $valid_date_upto . "'," . addslashes($product_digital_code_row['ndownload_expiry_days']) . ",0)";
                                mysql_query($insert_product_digital_code) or die(mysql_error());
                            }
                            // end for loop
                            //exit;
                        }
                        // end ehile
                    }
                    // emd if number of rows check
                    $product_download_flag = 1;
                }
                // end digital product check
                /*----------------------------------End check Digital Products--------------------------------------------------
                /*----------------------------------Updating Gift Products----------------------------------------------------------*/
                $product_tax = $_SESSION["TAX_DETAILS"][$product_option_id];
                // Product Based Commission Calculation
                $price_amt = $productprice * $quantity;
                if ($row['discount'] != 0) {
                    $discountprice = $productprice - $productprice * $row["discount"] / 100;
                    $discountprice = number_format($discountprice, 2, ".", "");
                    $discount_amount = $discountprice * $quantity;
                } else {
                    $discount_amount = $price_amt;
                }
                $product_commission_amt = $discount_amount * $row["commission"] / 100;
                // Product Based Commission Calculation End
                $sql = "INSERT INTO  " . $tableprefix . "order_details (\n\t\t\t\torder_id,\n\t\t\t\tproduct_id,\n\t\t\t\tproduct_name,\n\t\t\t\tproduct_code,\n\t\t\t\tproduct_price,\n\t\t\t\tproduct_quantity,\n\t\t\t\tproduct_discount,\n\t\t\t\tartist_id,\n\t\t\t\titem_status,\n\t\t\t\tartist_payment_status,\n                                product_tax,\n                                product_option_id,\n                                product_commission_amount\n\t\t\t\t)VALUES(\n\t\t\t\t'" . addslashes($orderid) . "',\n\t\t\t\t'" . addslashes($productid) . "',\n\t\t\t\t'" . addslashes($productname) . "',\n\t\t\t\t'" . addslashes($productcode) . "',\n\t\t\t\t'" . addslashes($productprice) . "',\n\t\t\t\t'" . addslashes($quantity) . "',\n\t\t\t\t'" . addslashes($productdiscount) . "',\n\t\t\t\t'" . addslashes($artistid) . "',\n\t\t\t\t'1',\n\t\t\t\t'0',\n                                '" . $product_tax . "',\n                                '" . $product_option_id . "',\n                                 '" . $product_commission_amt . "'\n\t\t\t\t)";
                mysql_query($sql);
                //echo "sql==".$sql."<br><br>";
                $artists[$i] = $artistid;
                $i++;
                $sql = "";
                if ($product_download_flag == 1) {
                    $update_order_details = "UPDATE " . $tableprefix . "order_details\n\t\t\t\t\t\tSET item_status = 4\n\t\t\t\t\t\tWHERE order_id  = " . $orderid . " AND product_id = " . $digital_product_id;
                    mysql_query($update_order_details) or die(mysql_error());
                }
                $reorderlevelcheck = checkSellerStock($product_option_id, $quantity);
                if ($reorderlevelcheck == 1) {
                    // Send Stock Reorder Mail To Seller
                    sendStockreordermail($product_option_id, $quantity);
                }
            }
            // end while
        }
        // end number of rows
        isset($_SESSION['SESS_orderid']) ? session_unregister('SESS_orderid') : session_register('SESS_orderid');
        $_SESSION['SESS_orderid'] = $orderid;
        if ($gift_coupon_flag == 1) {
            if (isset($_SESSION['SESS_digital_product']) && $_SESSION['SESS_digital_product'] != '') {
                session_unregister($_SESSION['SESS_digital_product']);
            }
            $update_order_details = "UPDATE " . $tableprefix . "order_details\n\t\t\t\t\t\t\t\t\t SET item_status = 4\n\t\t\t\t\t\t\t\t\t WHERE order_id  = " . $orderid . " ";
            mysql_query($update_order_details) or die(mysql_error());
        }
        // end if gift flag
        if ($product_download_flag == 1) {
            $update_order_details = "UPDATE " . $tableprefix . "order_details\n\t\t\t\t\t\t\t\t\t\t SET item_status = 4\n\t\t\t\t\t\t\t\t\t\t WHERE order_id  = " . $orderid . " AND product_id = " . $digital_product_id;
            mysql_query($update_order_details) or die(mysql_error());
        }
        if ($product_download_flag == 1) {
            isset($_SESSION['SESS_digital_product']) ? session_unregister('SESS_digital_product') : session_register('SESS_digital_product');
            $_SESSION['SESS_digital_product'] = 1;
        }
        // Send Giftcertificate Mails
        /*	if($gift_coupon_flag == 1)
        		{
        			sendgiftCertificateMail_Buyer($orderid,$_SESSION["sess_userid"],$usertype);
        			sendgiftCertificateMail_Seller($orderid,$_SESSION["sess_userid"]);
        			sendgiftCertificateMail_Admin($orderid,$_SESSION["sess_userid"]);
        		}
        
        		//Send Digital Certificate Mails
        
        		if($product_download_flag == 1)
        		{
        			sendDigitalCertificateMail_Buyer($orderid,$_SESSION["sess_userid"],$usertype);
        			sendDigitalCertificateMail_Seller($orderid,$_SESSION["sess_userid"]);
        			sendDigitalCertificateMail_Admin($orderid,$_SESSION["sess_userid"]);
        		}
        
        
        
        
        		if($product_download_flag!=1 && $gift_coupon_flag!=1)
        		{
        			//sendBuyerEmail($orderid,$_SESSION["sess_userid"],$usertype);
        			//sendSellerEmail($orderid,$_SESSION["sess_userid"]);
        			//sendAdminEmail($orderid,$_SESSION["sess_userid"]);
        
        		}*/
    }
    // end of first if condition
    //$cost			= $total_amount_topay; // price
    $currency = getSettingsValue("admin_currency");
    if ($google_demo == "YES") {
        $server_type = "sandbox";
    } else {
        $server_type = "checkout";
    }
    // Create a new shopping cart object
    $cart = new GoogleCart($google_id, $google_key, $server_type, $currency);
    $total = 0;
    $cartitems = "";
    $price = 0;
    $sql = "SELECT c.*,(p.product_price+po.additional_price) AS product_price,p.product_name,p.product_description,p.product_code,p.product_artist_id,po.discount,p.vdigital_product,po.product_option_id\n\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\tWHERE c.user_id = '" . $_SESSION["sess_userid"] . "' ";
    $res = mysql_query($sql);
    $cart_id = 1;
    $discountstr = "";
    $unit_price = 0;
    $shipping_cost = 0;
    $product_tax = 0;
    if (mysql_num_rows($res) > 0) {
        while ($rw = mysql_fetch_array($res)) {
            $cart_no = "item_" . $cart_id;
            $ship_no = "ship_" . $cart_id;
            $restriction_no = "restriction_" . $cart_id;
            $product_option_id = $rw["product_option_id"];
            $productname = $rw["product_name"];
            $rate = $rw["product_price"];
            $qty = $rw["quantity"];
            $price = $qty * $rate;
            if ($rw["discount"] != "0") {
                $price = $price - $price * $rw["discount"] / 100;
                //$discountstr="<br>discount(".$rw["discount"]."%)";
            }
            $check_shipping_enable = checkShippingEnable();
            $hide_shipping_division = hideShipping();
            if ($check_shipping_enable == "Y" && $hide_shipping_division == 1) {
                if (!empty($_SESSION["SHIPPING_DETAILS"])) {
                    $shipping_cost = $_SESSION["SHIPPING_DETAILS"][$product_option_id]['rate'];
                }
            }
            if (!empty($_SESSION["TAX_DETAILS"])) {
                $product_tax = $_SESSION["TAX_DETAILS"][$product_option_id];
            }
            $unit_price = $price + $shipping_cost + $product_tax;
            $cart_no = new GoogleItem($productname, $rw["product_description"], 1, $unit_price);
            // Unit price
            $cart->AddItem($cart_no);
            $cart_id++;
        }
    }
    $_SESSION['google_order_id'] = '';
    $_SESSION['gift_coupon_flag'] = '';
    $_SESSION['product_download_flag'] = '';
    $_SESSION['google_order_id'] = $orderid;
    $_SESSION['gift_coupon_flag'] = $gift_coupon_flag;
    $_SESSION['product_download_flag'] = $product_download_flag;
    $merchantdata = $orderid . "@" . $gift_coupon_flag . "@" . $product_download_flag;
    $cart->SetMerchantPrivateData($merchantdata);
    // continue link page
    $cart->SetContinueShoppingUrl(SITE_URL . "/google_checkout_payment.php?google_check=1");
    $cart->AddRoundingPolicy("HALF_UP", "PER_LINE");
    // Display XML data
    // Display Google Checkout button
    echo $cart->CheckoutButtonCode("LARGE");
    //$_SESSION["SHIPPING_DETAILS"] = array();
    //$_SESSION['SHIPPING_TOTAL'] = 0;
}