Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 20th, 2010 | Syntax: None | Size: 1.63 KB | Hits: 71 | Expires: Never
Copy text to clipboard
  1. <?php
  2. require('includes/application_top.php');
  3. ini_set('max_execution_time',0);
  4. try
  5. {
  6.         // handle postback
  7.         if (strtolower($_SERVER['REQUEST_METHOD']) == 'post')
  8.         {
  9.                         if ($_FILES['csv']['error'] == UPLOAD_ERR_OK)
  10.                         {
  11.                                         $fileHandle = fopen($_FILES['csv']['tmp_name'],'r');
  12.          
  13.                                         // READ FILE
  14.                                         while (!feof($fileHandle))
  15.                                         {
  16.                                                         $csv[] = fgetcsv($fileHandle);
  17.                                         }
  18.          
  19.          
  20.                                         foreach ($csv as $row)
  21.                                         {
  22.                                                         $query =
  23.                                                                 "UPDATE products_with_attributes_stock pwas ".
  24.                                                                 "INNER JOIN products_attributes_skus pas on pwas.stock_attributes = pas.products_attributes_ids ".
  25.                                                                 "SET quantity = '".$row[2]."' ".
  26.                                                                 "WHERE pas.sku = '" .$row[1] ."'";
  27.          
  28.                                                         $result = $db->Execute($query);
  29.                                                        
  30.                                                         if (mysql_affected_rows() == 0)
  31.                                                         {
  32.                                                                 // die(mysql_error());  
  33.                                                         }
  34.                                         }
  35.                                        
  36.                                         // Set to Inactive products with no quantity
  37.                                         $query2 =
  38.                                                         "UPDATE products p ".
  39.                                                         "INNER JOIN products_with_attributes_stock pwas on p.products_id = pwas.products_id ".
  40.                                                         "SET p.products_status = '0' ".
  41.                                                         "WHERE pwas.quantity = 0";
  42.                                                        
  43.                                         $result = $db->Execute($query2);
  44.                                        
  45.                                         if (mysql_affected_rows() == 0) {}
  46.                                        
  47.                                         // Set to Active products with quantity
  48.                                         $query3 =
  49.                                                         "UPDATE products p ".
  50.                                                         "INNER JOIN products_with_attributes_stock pwas on p.products_id = pwas.products_id ".
  51.                                                         "SET p.products_status = '1' ".
  52.                                                         "WHERE pwas.quantity > 0";
  53.                                                        
  54.                                         $result = $db->Execute($query3);
  55.                                        
  56.                                         if (mysql_affected_rows() == 0) {}
  57.                                        
  58.                         }
  59.         }
  60. }
  61. catch (Exception $ex)
  62. {
  63.         // Log
  64. }
  65.  
  66. ?>