<?php


require_once('config.php');





if(($response["error"] == true))
{
    echo(json_encode($response));
}

if(($response["error"] == false))
{
    if((isset($_POST["request"])) && ($_POST["request"] == "add_to_cart"))
    {
        $product_id     =   "";
        $quantity       =   "";

        if((!isset($_SESSION["GOLDFAYRE"])))
        {
            $response["error"]          =   true;
            $response["error_msg"]      =   "You are requested to login to your account first and try again.";
        }

        if(($response["error"] == false))
        {
            if((count($_SESSION["GOLDFAYRE"]["CART"]) > 0))
            {
                foreach($_SESSION["GOLDFAYRE"]["CART"] as $k => $v)
                {
                    if(($v["PID"] == $product_id))
                    {
                        $v["QTY"]   =   (intval($v["QTY"]) + 1);
                    }
                    else
                    {
                        $item                               =   array();
                        $item["PID"]                        =   intval($product_id);
                        $item["QTY"]                        =   intval($quantity);
                        $_SESSION["GOLDFAYRE"]["CART"][]    =   $item;
                    }
                    $_SESSION["GOLDFAYRE"]["CART"][$k]  =   $v;
                }
            }
            else
            {
                $item                               =   array();
                $item["PID"]                        =   intval($product_id);
                $item["QTY"]                        =   intval($quantity);
                $_SESSION["GOLDFAYRE"]["CART"][]    =   $item;
            }
        }
        if(($response["error"] == false))
        {
            $response["message"]    =   "The product has been added to the cart successfully.";
        }
        echo(json_encode($response));
    }

}












































?>