<?php
require('config.php');

// Check if productCode and productID are set
if (!isset($_GET['productCode']) || !isset($_GET['productID'])) {
    echo 0;
    exit;
}

$productCode = $connect->real_escape_string($_GET['productCode']);
$productID = $connect->real_escape_string($_GET['productID']);

// Query to get the product ID based on productCode
$productQuery = "SELECT id FROM products WHERE productCode = '$productCode' LIMIT 1";
$productResult = $connect->query($productQuery);

if ($productResult->num_rows > 0) {
    $productRow = $productResult->fetch_assoc();
    $queriedProductID = $productRow['id'];

    // Query to get the product price from store_stock
    $priceQuery = "SELECT productPrice FROM store_stock WHERE id = '$productID' AND productID = '$queriedProductID' LIMIT 1";
    $priceResult = $connect->query($priceQuery);

    if ($priceResult->num_rows > 0) {
        $priceRow = $priceResult->fetch_assoc();
        echo (int)$priceRow['productPrice'];
    } else {
        echo 0;
    }
} else {
    echo 0;
}
?>
