0

I am trying to use following code with latest Magento V1.7.1:

http://www.sonassi.com/knowledge-base/magento-kb/mass-update-stock-levels-in-magento-fast/

I updates stock quantities from CSV file.

It works fine with the following fields:

"sku","qty"
"prod1","11"

However, it does not work, if there are any additional fields.

I tried:

"sku","qty","is_in_stock" 
"prod1","11","1"

then qty gets updated, but is_in_stock or any other fields that follow qty are not being imported into the database.

I tried to switch fields and tried the following:

"sku","is_in_stock","qty"
"prod1","1","11"

and now is_in_stock gets updated, but qty does not.

Instruction say to use a minimum of two plus any of additional fields listed, but it does not work.

Would you be able to share updated code?

Thank you.

Jürgen Thelen
  • 12,745
  • 7
  • 52
  • 71
user1481153
  • 169
  • 2
  • 5
  • 13

2 Answers2

0

I don't know the mentioned import extension, but most probably it'll use fgetcsv() calls to read the CSV file, like Magento does.

The fgetcsv() function uses the regular (", Shift+2) double quote as enclosure delimiter by default.

If you really copied the CSV lines 1:1 from your CSV file into this post, containing up to three different enclosure delimiters (“, ” and ") per line, then fgetcsv() has no chance to properly return the field values.

To fix this, just replace all double quotes in your CSV file with the regular one, save and import again.

Jürgen Thelen
  • 12,745
  • 7
  • 52
  • 71
  • I think “, ” was from when I was copying and pasting. I checked all the enclosures and they are all correct ". When I run the script, it does not give any errors. It completes the process successfully but qty is updated but not the other. – user1481153 Aug 13 '12 at 14:29
  • I just checked that extension code under EE 1.11 (no CE 1.7.1 at hand, sorry) using `"sku","qty","is_in_stock"` and `"911","100","1"` where 911 was an existing product. Works fine. So this sould be either a character encoding, corrupted database or Magento version issue. – Jürgen Thelen Aug 13 '12 at 16:51
  • I found out the each line has blanks at the end. For example, second line "911","100","1" has around 25 blanks after "1" which is causing the problem. Is there any way to trim that in PHP? I can see command trim will trim strings but this is at the end of the line not within string so I don't know what to do. – user1481153 Aug 13 '12 at 18:20
  • Why would yoo try to trim these lines using PHP? You're working with a manually created CSV test file. Just open the CSV file using a text editor, remove the spaces at the line endings and save again. – Jürgen Thelen Aug 13 '12 at 18:49
  • CSV file is generated nightly by our POS system then uploaded to automatically then cron job updates the stock daily...so I don't want any human opening the file. It's supposed to be all automated daily so stock is updated every night. – user1481153 Aug 13 '12 at 19:55
0

Remember that depending on your os, the line endings aren't always the same. Windows editors have a nasty habit of adding an extra Carriage Return at the end of each line (learned this the hard way when I wrote a Linux parser for this sort of job in C++). Best check your csv by using something like Notepad++ to see what's at the end of each record.

I'd recommend using Magmi for simple updates such as this. It takes a little effort to set-up (but has very solid documentation to walk you through the process), but once done, is fast, stable and contains a lot of additional plugins that you can use for more functionality than just stock updates in the future.