Untitled
By: a guest | Mar 20th, 2010 | Syntax:
None | Size: 1.63 KB | Hits: 71 | Expires: Never
<?php
require('includes/application_top.php');
ini_set('max_execution_time',0);
try
{
// handle postback
if (strtolower($_SERVER['REQUEST_METHOD']) == 'post')
{
if ($_FILES['csv']['error'] == UPLOAD_ERR_OK)
{
$fileHandle = fopen($_FILES['csv']['tmp_name'],'r');
// READ FILE
while (!feof($fileHandle))
{
$csv[] = fgetcsv($fileHandle);
}
foreach ($csv as $row)
{
$query =
"UPDATE products_with_attributes_stock pwas ".
"INNER JOIN products_attributes_skus pas on pwas.stock_attributes = pas.products_attributes_ids ".
"SET quantity = '".$row[2]."' ".
"WHERE pas.sku = '" .$row[1] ."'";
$result = $db->Execute($query);
if (mysql_affected_rows() == 0)
{
// die(mysql_error());
}
}
// Set to Inactive products with no quantity
$query2 =
"UPDATE products p ".
"INNER JOIN products_with_attributes_stock pwas on p.products_id = pwas.products_id ".
"SET p.products_status = '0' ".
"WHERE pwas.quantity = 0";
$result = $db->Execute($query2);
if (mysql_affected_rows() == 0) {}
// Set to Active products with quantity
$query3 =
"UPDATE products p ".
"INNER JOIN products_with_attributes_stock pwas on p.products_id = pwas.products_id ".
"SET p.products_status = '1' ".
"WHERE pwas.quantity > 0";
$result = $db->Execute($query3);
if (mysql_affected_rows() == 0) {}
}
}
}
catch (Exception $ex)
{
// Log
}
?>