class Scraper_Store_A { public static function fetch_discounted_products() { $url = 'https://store-a.com/discounts'; $html = @file_get_contents($url); if (!$html) { error_log("[DPS] Failed to fetch: $url"); return []; // fail gracefully } $dom = new DOMDocument(); @$dom->loadHTML($html); // suppress warnings $xpath = new DOMXPath($dom); $products = []; foreach ($xpath->query("//div[contains(@class, 'product')]") as $node) { $old_price = $xpath->query(".//span[@class='price-old']", $node); if ($old_price->length == 0) continue; $name = $xpath->query(".//h2", $node)->item(0)->nodeValue ?? 'Unnamed'; $price = $xpath->query(".//span[@class='price-new']", $node)->item(0)->nodeValue ?? ''; $url = $xpath->query(".//a", $node)->item(0)->getAttribute('href') ?? ''; $img = $xpath->query(".//img", $node)->item(0)->getAttribute('src') ?? ''; $products[] = [ 'name' => trim($name), 'price' => trim($price), 'url' => trim($url), 'image' => trim($img), 'category_slug' => 'tech-deals' ]; } return $products; } }