<?php


require_once('config.php');





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

if(($response["error"] == false))
{
    if((isset($_POST["request"])) && ($_POST["request"] == "get_product_info"))
    {
        $url        =   "";
        $params     =   array();
        $logs       =   array();
        if((!isset($_POST["url"])) || (empty($_POST["url"])))
        {
            $response["error"]      =   true;
            $response["error_msg"]  =   "An Error Occurred. One or more required parameters are missing.";
        }
        else
        {
            $url    =   $_POST["url"];
        }
        

        if(($response["error"] == false))
        {
            $url_components     =   parse_url($url);
            $query              =   $url_components["query"];
            $parts              =   explode("=", $query);
            $params["TITLE"]    =   $parts[1];

        }

        if(($response["error"] == false))
        {
            $sql            =   "   SELECT M.id ID, M.title TITLE, M.description DESCRIPTION, M.category_id CATEGORY_ID, C.category_name CATEGORY_NAME, 
                                    M.price PRICE, M.discount_price DISCOUNT_PRICE, M.product_status PRODUCT_STATUS, M.register_on REGISTER_ON, 
                                    M.quantity QUANTITY, D.image_name IMAGE, REPLACE(LOWER(M.title), ' ', '-') PRODUCT_KEYWORD, 
                                    REPLACE(LOWER(C.category_name), ' ', '-') CATEGORY_KEYWORD 
                                    FROM product_mst M, product_images D, category C
                                    WHERE M.id = D.product_mst_id
                                    AND M.category_id = C.id
                                    AND D.primary_image = 'Y'
                                    AND REPLACE(LOWER(M.title),' ', '-') = ?";
            $stmt = $db->prepare($sql); 
            $stmt->bind_param("s", $params["TITLE"]);
            $stmt->execute();
            $result     =   $stmt->get_result();
            $row = mysqli_fetch_assoc($result);
            if(($row))
            {
                $logs["PRODUCT"]    =   $row;
            }
            else
            {
                $response["error"]      =   true;
                $response["error_msg"]  =   "An Error Occurred. No product found in the system";
            }
        } 

        if(($response["error"] == false))
        {
            $html   =   '<div class="col-lg-6">';
            $html  .=   '<div class="card">';
            $html  .=   '<div class="card-body">';
            $html  .=   '<div class="content-carousel">';
            $html  .=   '<div class="owl-carousel">';
            $html  .=   '<div><img src="'.$base_url.'uploads/products/'.$logs["PRODUCT"]["IMAGE"].'"></div>';
            $html  .=   '</div>';
            $html  .=   '</div>';
            $html  .=   '</div>';
            $html  .=   '</div>';
            $html  .=   '</div>';
            $html  .=   '<div class="col-lg-6">';
            $html  .=   '<p class="badge bg-primary">'.$logs["PRODUCT"]["CATEGORY_NAME"].'</p>';
            $html  .=   '<h2>'.$logs["PRODUCT"]["TITLE"].'</h2>';
            $html  .=   '<p style="color: #f0484f; font-weight: 500; font-size: 28px;">'.$logs["PRODUCT"]["PRICE"].' £</p>';
            $html  .=   '<div class="row">';
            $html  .=   '<div class="col-lg-12">';
            $html  .=   '<input id="pid" name="pid" type="text" value="'.$logs["PRODUCT"]["ID"].'" class="form-control" hidden readonly />';
            $html  .=   '<input id="orderquantity" name="orderquantity" type="number" value="" class="form-control" style="height: 50px" placeholder="Enter Quantity" />';
            $html  .=   '</div>';
            $html  .=   '</div>';
            $html  .=   '<div class="row" style="margin-top: 15px;">';
            $html  .=   '<div class="col-lg-12">';
            $html  .=   '<button id="ATCB" class="btn btn-danger" style="height: 50px; width: 100%"><i class="bi bi-cart-fill"></i>&nbsp;&nbsp;Add to Cart</button>';
            $html  .=   '</div>';
            $html  .=   '</div>';
            $html  .=   '<div class="row" style="margin-top: 10px;">';
            $html  .=   '<div class="col-lg-12">';
            $html  .=   '<a href="'.$base_url.'checkout" class="btn btn-dark" style="width: 100%; height: 50px; background-color: #333; color: white; padding-top: 10px;"><i class="bi bi-credit-card-2-back-fill"></i>&nbsp;&nbsp;Proceed to Checkout</a>';
            $html  .=   '</div>';
            $html  .=   '</div>';
            $html  .=   '<div class="d-flex flex-row" style="margin-top: 20px;">';
            $html  .=   '<div class="p-2"><i class="bi bi-truck" style="font-size: 20px;"></i> Quick Delivery</div>';
            $html  .=   '<div class="p-2"><i class="bi bi-shield-check" style="font-size: 20px;"></i> Secure Checkout</div>';
            $html  .=   '<div class="p-2"><i class="bi bi-patch-check" style="font-size: 20px;"></i>&nbsp;Quality Guranteed </div>';
            $html  .=   '</div>';
            $html  .=   '</div>';
            $response["html"]   =   $html;
        }
        echo(json_encode($response));
    }

}












































?>