$amazonNotFound2 = AMAZON_DOWNLOAD . $uid . "/notFound2.txt"; $found = $notFound = 0; logger("Looking up stock..."); $file1 = fopen($amazonSKU, "r"); $file2 = fopen($amazonFound, "w+"); $file3 = fopen($amazonNotFound2, "w+"); if ($file1 && $file2 && $file3) { while (!feof($file1)){ $line = fgets($file1); $data = explode("\t", $line); if (!empty($data[0])) { $sku = trim($data[0]); $price = trim($data[1]); $newSKU = filter_sku_by_file($sku, $amazonFilter); $qty = query_stock($newSKU); if ($qty == -1) { $str = $sku . "\t" . $price; fwrite($file3, $str . PHP_EOL); $notFound++; } else { $str = $sku . "\t" . $price . "\t" . $qty; fwrite($file2, $str . PHP_EOL); $found++; } } } logger("Found: $found, Not Found: $notFound"); } else { logger("Failed to open $amazonSKU, $amazonFound, $amazonNotFound2"); }
function check_set_sku_by_file($sku, $filePath) { global $debug; $file = fopen($filePath, "r"); $qtyArray = array(); while (!feof($file)) { $line = fgets($file); if (!empty($line)) { $skus = explode("\t", $line); $setSKU = trim($skus[0]); if ($sku == $setSKU) { for ($i = 1; $i < count($skus); $i++) { $skus[$i] = trim($skus[$i]); $qty = query_stock($skus[$i]); array_push($qtyArray, $qty); } } } } fclose($file); if (!empty($qtyArray)) { if ($debug) logger("Lookup $sku found " . min($qtyArray)); return min($qtyArray); } else { if ($debug) logger("Lookup $sku not found"); return -1; } }