Jump to content

Strange Inventory Issues


rseigel

Recommended Posts

Here's the script that I use to update my inventory:

 

mysql_query("DROP TABLE IF EXISTS tmp_BF")
or die(mysql_error());
mysql_query("CREATE TABLE IF NOT EXISTS tmp_BF (
supplier_reference varchar(32) DEFAULT NULL,
quantity int(10) NOT NULL DEFAULT '0',
price decimal(20,6) NOT NULL DEFAULT '0.000000',
wholesale_price decimal(20,6) NOT NULL DEFAULT '0.000000'
) ENGINE=InnoDB  DEFAULT CHARSET=utf8")
or die(mysql_error());
copy('http://www.bnfusa.com/utilities/cgen.lasso?an8=10012538&fmt=csv', 'GeneratedList.csv');
ini_set('auto_detect_line_endings', true);
$fname ="GeneratedList.csv";
$chk_ext = explode(".",$fname);
if(strtolower($chk_ext[1]) == "csv")
{
$filename = "GeneratedList.csv";
$handle = fopen($filename, "r");
$header = true;
while (($data = fgetcsv($handle, 100000, ",")) !== FALSE) {
if ($header == true) {
 $header = false;
 continue;
}
$sql = "INSERT into tmp_BF(supplier_reference,quantity,price,wholesale_price) values('$data[0]','$data[1]','$data[2]','$data[3]')";
mysql_query($sql) or die(mysql_error());
$supplier_reference = $data[0];
$quantity = $data[1];
$price = $data[2];
   $wholesale_price = $data[3];
mysql_query("UPDATE stock_available, product_attribute SET stock_available.quantity = $quantity WHERE stock_available.id_product_attribute = product_attribute.id_product_attribute AND product_attribute.supplier_reference = '$supplier_reference'")
or die(mysql_error());
mysql_query("UPDATE stock_available, product SET stock_available.quantity = $quantity WHERE stock_available.id_product = product.id_product AND product.supplier_reference = '$supplier_reference'")
or die(mysql_error());
mysql_query("UPDATE product SET product.quantity = $quantity WHERE product.supplier_reference = '$supplier_reference'")
or die(mysql_error());
//mysql_query("INSERT INTO tmp_price_compare VALUES('$supplier_reference',$quantity,$price,$wholesale_price)")
// or die(mysql_error());
}
echo "Successfully Imported";
}
else
{
echo "Invalid File";
}
fclose($handle);

 

It's not perfect but it works - at least it used to until I upgraded to 1.5.4.1

 

I have two types of products in my shop:

 

1) Those that I imported into my shop with the built in PS import.

 

and

 

2) Those that I've added through the Add New interface.

 

The script works perfectly for products from group #1.

 

It doesn't work for group #2.

 

No matter when the inventory numbers in the quantity field itself it is 0.

 

If you look at these products in the Admin product list the quantity shows up as --

 

This has to be a bug of some sort (posting to bug tracker as well).

 

Any thoughts?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...