<?php
include_once '../../../config.php';
include_once '../../../ACP/database1.php';
include_once "../../../validation.php";
include_once "../../../Helper.php";

require_once '../../../check_edit_page_ajax.php';
require_once '../check_session_ajax_return.php';
$user = checkSessionReturn();


class EditAjax extends database{
	public function index($id)
	{
		$sqlWhere = '';
		$where[] = $id;
		
		$sql = ' SELECT COUNT(*) AS total_values, vp.cl_id, vp.cl_supplier_price, vp.cl_monthly_price,vp.cl_weight FROM tb_variable_product_attributes vpa INNER JOIN tb_variable_product vp ON vp.cl_id=vpa.cl_variable_product_id WHERE vp.cl_deleted_at IS NULL AND vpa.cl_deleted_at IS NULL AND vp.cl_show=1  AND vp.cl_product_id=? AND vp.cl_default=1 ';
		return $this->callQuery($sql, $where);
	}
}

$obj = new EditAjax();
$res = $obj->index($id);
foreach($res AS $eachCount)
{
	if($filterCount == $eachCount['total_values'])
	{
		http_response_code(200);
		echo json_encode(array('message' => 'Variable Product Available', 'id' => $eachCount['cl_id'], 'supplier_price' => $eachCount['cl_supplier_price'], 'monthly_price' => $eachCount['cl_monthly_price'], 'weight' => $eachCount['cl_weight']));
		exit;
	}
}


	http_response_code(400);
	echo json_encode(array('error_text' => 'NO Product Available'));
	exit;


