fclose($file2); fclose($file3); logger("Looking up Set SKU..."); $notFound = 0; // Reset to zero $file1 = fopen($amazonNotFound2, "r"); $file2 = fopen($amazonFound, "a+"); $file3 = fopen($amazonNotFound, "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 = check_set_sku_by_file($newSKU, $amazonSetList); 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 $amazonFound, $amazonNotFound, $amazonNotFound2");
logger("Updating inventory..."); $inventory = AMAZON_UPLOAD . $uid . '/' . "inventory.txt"; $file1 = fopen($vendorStock, "r"); $file2 = fopen($inventory, "w+"); if ($file1 && $file2) { while (!feof($file1)){ $line = fgets($file1); $data = explode("\t", $line); if (!empty($data[0])) { $sku = trim($data[0]); $qty = trim($data[1]); $qty = empty($qty) ? 0 : $qty; if (preg_match('/Y/', $qty)) $qty = 20; $qty = ($qty < 0) ? 0 : $qty; $sku = filter_sku_by_file($sku, $vendorFilter); $str = $sku . "\t" . $qty; fwrite($file2, $str . PHP_EOL); } } } else { logger("Failed to open $vendorStock, $inventory"); } fclose($file1); fclose($file2); truncate_inventory(); update_inventory_by_file($inventory); $count = inventory_record_count(); logger("Done: Inventory updated with $count records!"); }