<?php
/**
 * Ultra-fast QR Code Generator - Generates QR URLs without downloading
 */

$dataFile = __DIR__ . '/data/products.json';

// Read products JSON
$jsonContent = file_get_contents($dataFile);
$products = json_decode($jsonContent, true);

echo "Updating products with QR code URLs...\n\n";

$updated = 0;

foreach ($products as $idx => $product) {
    $id = $product['id'] ?? 0;
    if (!$id) continue;
    
    // Check if already has QR code
    if (!empty($product['qr_code'])) {
        echo "⊘ ID {$id}: Already has QR code\n";
        continue;
    }
    
    // Set QR code API URL
    $productUrl = 'http://localhost/ecoms/product.php?id=' . $id;
    $products[$idx]['qr_code'] = 'https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=' . urlencode($productUrl);
    
    $updated++;
    echo "✓ Product {$id}: QR code URL added\n";
}

// Save products
file_put_contents($dataFile, json_encode($products, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));

echo "\n========================================\n";
echo "✓ Complete! Updated: {$updated} products\n";
echo "\nQR codes will be generated on-the-fly from API\n";
?>
