Hello very honourable comrades
I've read many forum threads, many search engine results, but can't find a solution! From all the synthesized information, I understand that ajax collects information about the availability of products with combinations. Someone please guide me, how with php can I extract a list in (standalone external file) which php script show me only ID or Ref# of products and which currently have 0 quantity in any of their sale attributes ?
I tried to achieve this process through API, but somewhere my knowledge falls short and I can't pull out the availability.
<?php // API URL for products $url_products = 'https://example.com/api/products/?display=[id,reference,name,active]&output_format=JSON'; // API Key $api_key = 'fullaccess'; // Initialize cURL for products $ch_products = curl_init($url_products); // Set cURL options for products curl_setopt($ch_products, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch_products, CURLOPT_HTTPHEADER, array( 'Authorization: Basic ' . base64_encode($api_key . ':') )); // Execute cURL request for products $response_products = curl_exec($ch_products); // Check for cURL errors for products if(curl_errno($ch_products)) { echo 'Error:' . curl_error($ch_products); } else { // Decode JSON response for products $data_products = json_decode($response_products, true); // Check if there are any products returned if(isset($data_products['products'])) { // Loop through products foreach($data_products['products'] as $product) { // Check if product is active if($product['active']) { // Extract product names from nested array of objects $product_names = array_column($product['name'], 'value'); // Combine product names into a single string $product_name = implode(', ', $product_names); // Output product ID, Ref, and Name echo "ID: " . $product['id'] . ", Ref: " . $product['reference'] . ", Name: " . $product_name . "<br>"; // API URL for product combinations $url_combinations = 'https://example.com/api/combinations/?display=[reference,quantity]&filter[id_product]=' . $product['id'] . '&output_format=JSON'; // Initialize cURL for product combinations $ch_combinations = curl_init($url_combinations); // Set cURL options for product combinations curl_setopt($ch_combinations, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch_combinations, CURLOPT_HTTPHEADER, array( 'Authorization: Basic ' . base64_encode($api_key . ':') )); // Execute cURL request for product combinations $response_combinations = curl_exec($ch_combinations); // Check for cURL errors for product combinations if(curl_errno($ch_combinations)) { echo 'Error:' . curl_error($ch_combinations); } else { // Decode JSON response for product combinations $data_combinations = json_decode($response_combinations, true); // Check if there are any combinations returned if(isset($data_combinations)) { // Loop through combinations and output reference and quantity foreach($data_combinations as $combination) { // Check if 'reference' and 'quantity' keys exist in the combination if(isset($combination['reference']) && isset($combination['quantity'])) { // Output reference echo "Size Ref: " . $combination['reference'] . ", "; // Output quantity attributes and their quantities foreach($combination['quantity'] as $attribute => $quantity) { echo $attribute . ": " . $quantity . " броя, "; } } else { echo "No combinations found for this product."; } // Add a line break echo "<br>"; } } else { echo "No combinations found for this product."; } } // Close cURL session for product combinations curl_close($ch_combinations); // Add a line break for better readability echo "<br>"; } } } else { echo "No products found."; } } // Close cURL session for products curl_close($ch_products); ?>
For me, it's irrelevant whether I get the list via the API protocol or with programming code that directly messes with mysql and outputs the information. I just want to see that on product ID100, there are 0 quantity per size M and 0 quantity per size XXXL
Thank you for your time and attention.
Best regards