File "add_product_id-20260219041217.php"

Full Path: /home/magicrsz/public_html/actions/add_product_id-20260219041217.php
File size: 3.99 KB
MIME-type: text/x-php
Charset: utf-8

<?php
session_start();
include "../admin/database.php" ;

$user_id=NULL;

$user_id=session_id();

$product_id=$_POST['product_id'];
$quantity= $_POST['quantity'];

$res="SELECT * from temp_cart where user_id='$user_id' ";
$ress = db::getRecords($res);

$size="";
if(isset($_POST['size']))
{
    $size=$_POST['size'];
    $sizeVal = filter_var($size, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
    $getprice=$_POST['getprice'];
    $getpriceVal = filter_var($getprice, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
}

if($ress!=null)
{
    $res1="SELECT * from temp_cart where product_id='$product_id' && user_id='$user_id' && size='$size'";
    $ress1 = db::getRecord($res1);
    if($ress1!=null){
        $data=$ress1['product_id'];
        //     echo "$data";
        if($product_id==$data)
        {
            $myyquan = $ress1['quantity'];
            $newquan = $quantity + $myyquan;
            //check before add
            $getSizeQuery = "SELECT * from sizes where product_id='$product_id' && size='$size'";
            $getSizeData = db::getRecord($getSizeQuery);
            if($getSizeData['quantity'] == 0) {
                echo "Product out of stock";
            }
            else if($getSizeData['quantity'] < $quantity){
                echo "Product out of stock";
            }
            else {
                $total = $newquan * $getpriceVal;

                $query = "UPDATE temp_cart SET quantity='$newquan',total='$total',size='$size' where product_id='$product_id' && user_id='$user_id' && size='$size'";
                $run = db::query($query);
                echo "Product Quantity Added To Cart.";
            }
           
        }
        else
        {
            $getSizeQuery = "SELECT * from sizes where product_id='$product_id' && size='$size'";
            $getSizeData = db::getRecord($getSizeQuery);
            if($getSizeData['quantity'] == 0) {
                echo "Product out of stock";
            }
            else if($getSizeData['quantity'] < $quantity){
                echo "Product out of stock";
            }
            else {
                $total = $quantity * $getpriceVal;

                $query="INSERT into temp_cart (user_id,product_id,quantity,total,size) VALUES ('$user_id','$product_id','$quantity','$total','$size')";
                $insert=db::query($query);

                echo "Product Added To Cart.";
            }
        }
    }                                                    
    else{
            $getSizeQuery = "SELECT * from sizes where product_id='$product_id' && size='$size'";
            $getSizeData = db::getRecord($getSizeQuery);
            if($getSizeData['quantity'] == 0) {
                echo "Product out of stock";
            }
            else if($getSizeData['quantity'] < $quantity){
                echo "Product out of stock";
            }
            else {
                
                $total = $quantity * $getpriceVal;


                $query="INSERT into temp_cart (user_id,product_id,quantity,total,size) VALUES ('$user_id','$product_id','$quantity','$total','$size')";
                $insert=db::query($query);

                echo "Product Added To Cart.";
            }
    }

}
else{
            $getSizeQuery = "SELECT * from sizes where product_id='$product_id' && size='$size'";
            $getSizeData = db::getRecord($getSizeQuery);
            if($getSizeData['quantity'] == 0) {
                echo "Product out of stock";
            }
            else if($getSizeData['quantity'] < $quantity){
                echo "Product out of stock";
            }
            else {
                $total = $quantity * $getpriceVal;


                $query="INSERT into temp_cart (user_id,product_id,quantity,total,size) VALUES ('$user_id','$product_id','$quantity','$total','$size')";
                $insert=db::query($query);

                echo "First Product Added To Cart.";
            }
}



?>