<?php
session_start();
//session_destroy();
include('../config/database.php');
$productId = $_GET['productId'];
$qty = $_GET['qty'];
$polishId = $_GET['polishId'];
$sizeId = $_GET['sizeId'];
$status = 1;
$msg = "WISHLIST UPDATED SUCCESSFULLY.";
$subTotal = 0; $deliveryCharges = 0; $orderTotal = 0;
if(isset($_SESSION['kxproductList']))
{
if(count($_SESSION['kxproductList'])>0)
{
$_SESSION['kxproductList2'] = array();
foreach($_SESSION['kxproductList'] as $pL)
{
if($pL['productId']==$productId && $pL['polishId']==$polishId && $pL['sizeId']==$sizeId)
{
$sqlProduct = mysqli_query($cn,"select * from `tbl_product` where `id`='".$pL['productId']."'");
$sqlProductData = mysqli_fetch_array($sqlProduct);
array_push($_SESSION['kxproductList2'],array("productId" =>$pL['productId'], "qty"=>$qty, "polishId"=>$pL['polishId'], "sizeId"=>$pL['sizeId'], "productName"=>$pL['productName'], "productPrice"=>currencyPrice($sqlProductData['price']), "productPhoto"=>productDefaultPhoto($pL['productId']), "productSlugURL"=>$sqlProductData['slug_url']));
$subTotal = $subTotal + ($qty * $sqlProductData['price']);
$deliveryCharges = $deliveryCharges + $sqlProductData['delivery_charge'];
}
else
{
$sqlProduct = mysqli_query($cn,"select * from `tbl_product` where `id`='".$pL['productId']."'");
$sqlProductData = mysqli_fetch_array($sqlProduct);
$subTotal = $subTotal + ($pL['qty'] * $sqlProductData['price']);
$deliveryCharges = $deliveryCharges + $sqlProductData['delivery_charge'];
array_push($_SESSION['kxproductList2'],array("productId" =>$pL['productId'], "qty"=>$pL['qty'], "polishId"=>$pL['polishId'], "sizeId"=>$pL['sizeId'], "productName"=>$pL['productName'], "productPrice"=>currencyPrice($sqlProductData['price']), "productPhoto"=>productDefaultPhoto($pL['productId']), "productSlugURL"=>$sqlProductData['slug_url']));
}
}
$_SESSION['kxproductList'] = array();
$_SESSION['kxproductList'] = $_SESSION['kxproductList2'];
$orderTotal = $subTotal + $deliveryCharges;
$arr = array('status'=>$status, 'msg'=>$msg, 'productCount'=>count($_SESSION['kxproductList']), 'subTotal'=>currencyPrice($subTotal), 'deliveryCharges'=>currencyPrice($deliveryCharges), 'orderTotal'=>currencyPrice($orderTotal), 'productList'=>$_SESSION['kxproductList']);
echo json_encode($arr);
}
else
{
$msg = "Somethig Went Wrong. Try Again.";
$arr = array('status'=>2, 'msg'=>$msg);
echo json_encode($arr);
}
}
else
{
$msg = "Somethig Went Wrong. Try Again.";
$arr = array('status'=>2, 'msg'=>$msg);
echo json_encode($arr);
}
?>