Posted by askmatt
May 10th, 2011
No Comments
Magento update stock levels after AFM delivery
<?php
$dir = "/home/afm/incoming/deliveries";
$pattern = "*.CSV";
if (is_dir($dir))
{
if ($dh = opendir($dir))
{
// iterate over file list
while (($filename = readdir($dh)) !== false)
{
if (fnmatch($pattern, $filename))
{
$file= $dir . "/" . $filename;
$row = 1;
if (($handle = fopen($file, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$row++;
if (is_numeric($data[3])){
echo "UPDATE cataloginventory_stock_item SET qty = qty + $data[3] WHERE product_id = "
."(select entity_id from catalog_product_entity WHERE sku = "$data[1]");\n";
}
}
fclose($handle);
}
//end process csv
rename ($file,"$file.processed");
}
}
// close directory
closedir($dh);
}
}
?>


