File "arrayTest.php"

Full Path: /home/krishnamexports/public_html/ajax/arrayTest.php
File size: 4.83 KB
MIME-type: text/x-php; charset=us-ascii
Charset: utf-8

<?php

session_start();

//session_destroy();

include('../config/database.php');			



$productId = 15;

$sqlProduct     = mysqli_query($cn,"select * from `tbl_product` where `id`='".$productId."'");

$sqlProductData = mysqli_fetch_array($sqlProduct);



if($sqlProductData['bulk_order']==1)

{		

	$status         = 0;

	$msg            = "CART ADDED.";

	

	$_SESSION['kxproductListTemp'] = array();

	$_SESSION['kxproductListAll']  = array();

	

	array_push($_SESSION['kxproductListTemp'],array("productId" =>$productId, "qty"=>5, "polishId"=>"", "sizeId"=>3,  "productName"=>$sqlProductData['name'], "productPrice"=>currencyPrice($sqlProductData['price']), "productPhoto"=>productDefaultPhoto($productId), "productSlugURL"=>$sqlProductData['slug_url']));															

	array_push($_SESSION['kxproductListTemp'],array("productId" =>$productId, "qty"=>10, "polishId"=>"", "sizeId"=>2,  "productName"=>$sqlProductData['name'], "productPrice"=>currencyPrice($sqlProductData['price']), "productPhoto"=>productDefaultPhoto($productId), "productSlugURL"=>$sqlProductData['slug_url']));

	array_push($_SESSION['kxproductListTemp'],array("productId" =>$productId, "qty"=>15, "polishId"=>"", "sizeId"=>1,  "productName"=>$sqlProductData['name'], "productPrice"=>currencyPrice($sqlProductData['price']), "productPhoto"=>productDefaultPhoto($productId), "productSlugURL"=>$sqlProductData['slug_url']));																														

	

	array_push($_SESSION['kxproductList'],array("productId" =>$productId, "qty"=>5, "polishId"=>"", "sizeId"=>3,  "productName"=>$sqlProductData['name'], "productPrice"=>currencyPrice($sqlProductData['price']), "productPhoto"=>productDefaultPhoto($productId), "productSlugURL"=>$sqlProductData['slug_url']));															

	array_push($_SESSION['kxproductList'],array("productId" =>$productId, "qty"=>10, "polishId"=>"", "sizeId"=>2,  "productName"=>$sqlProductData['name'], "productPrice"=>currencyPrice($sqlProductData['price']), "productPhoto"=>productDefaultPhoto($productId), "productSlugURL"=>$sqlProductData['slug_url']));														



	array_push($_SESSION['kxproductListAll'],array("productId" =>$productId, "qty"=>5, "polishId"=>"", "sizeId"=>3,  "productName"=>$sqlProductData['name'], "productPrice"=>currencyPrice($sqlProductData['price']), "productPhoto"=>productDefaultPhoto($productId), "productSlugURL"=>$sqlProductData['slug_url']));															

	array_push($_SESSION['kxproductListAll'],array("productId" =>$productId, "qty"=>10, "polishId"=>"", "sizeId"=>2,  "productName"=>$sqlProductData['name'], "productPrice"=>currencyPrice($sqlProductData['price']), "productPhoto"=>productDefaultPhoto($productId), "productSlugURL"=>$sqlProductData['slug_url']));															

	

	foreach($_SESSION['kxproductListTemp'] as $pL)

	{																						

		$productStatus = 1;

		foreach($_SESSION['kxproductList'] as $pLT)

		{						

			if($pL['productId']==$pLT['productId'] && $pL['polishId']==$pLT['polishId'] && $pL['sizeId']==$pLT['sizeId'])

			{				

				$productStatus = 2;

				$status        = 4;			

				$msg           = "Cart Updated Successfully.";

			}						

		}	

		if($productStatus==1)

		{											

			array_push($_SESSION['kxproductListAll'],array("productId" =>$productId, "qty"=>$pLT['qty'], "polishId"=>$pLT['polishId'], "sizeId"=>$pLT['sizeId'], "productName"=>$pLT['productName'], "productPrice"=>$pLT['productPrice'], "productPhoto"=>$pLT['productPhoto'], "productSlugURL"=>$pLT['productSlugURL']));

		}																																					

	}	

														

	$subTotal = 0; $deliveryCharges = 0; $orderTotal = 0;																														

	$_SESSION['kxproductList2'] = array();

	foreach($_SESSION['kxproductListAll'] as $pL)

	{				

		$sqlProduct2     = mysqli_query($cn,"select * from `tbl_product` where `id`='".$pL['productId']."'");

		$sqlProductData2 = mysqli_fetch_array($sqlProduct2);

		$subTotal        = $subTotal + ($pL['qty'] * $sqlProductData2['price']);	

		$deliveryCharges = $deliveryCharges + $sqlProductData2['delivery_charge'];					

		array_push($_SESSION['kxproductList2'],array("productId" =>$pL['productId'], "qty"=>$pL['qty'], "polishId"=>$pL['polishId'], "sizeId"=>$pL['sizeId'], "productName"=>$sqlProductData2['name'], "productPrice"=>currencyPrice($sqlProductData2['price']), "productPhoto"=>productDefaultPhoto($sqlProductData2['id']), "productSlugURL"=>$sqlProductData2['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);	

}

?>