0
votes

I’m not sure what’s happening but using this template (queldorei.com) I’m unable to update the quantity using CSV import.

Here’s the content of my CSV file:

sku,qty
sku_red,444
sku_green,222
sku_blue,333

However, each time I uploaded it using System > Import/Export > Import > Products : Replace Existing, then it would replace all my products quantity to have : “444” (first record). It’s only taking the first row of the CSV and apply to all my products.

My products setup are:

  1. Red (Simple) - sku_red
  2. Green (Simple) - sku_green
  3. Blue (Simple) - sku_blue
  4. Main (Configurable Product associated with the 3 products above). - sku_main

I tried to emulate the same thing to the base magento website (non-template) and it worked perfectly.

Could you please let me know how to fix this??

Or probably if you can locate on which file (php) that I can look for that is relevant to the magento Product Import process??

Thank you

1
When an import isn't working I always suggest you make add a few entries using the admin backend and then export them. That should show you what Magento thinks your csv file should look like (there will be lots of unnecessary columns but you should be able to pick out the key ones).PedroKTFC

1 Answers

1
votes

I just went through the same problem. I don't know how many versions of magento has the same issue, but you can fix it in file app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php and line somewhere near 1608.

To find that place without using line numbers, just go to method '_saveStockItem'. You'll see there how magento creates data for each row. Main problem starts here:

$row['product_id'] = $this->_newSku[$rowData[self::COL_SKU]]['entity_id'];

Product data is being initiated in that place, but developer forgot to reset $row variable with $row = array(). So instead having initiated array like that:

$row = array(
    'product_id' => $this->_newSku[$rowData[self::COL_SKU]],
    'stock_id'   => 1
);

We have:

$row = array(
    // last $row data ( for instance qty )
    // plus two lines below which don't reset array...
    'product_id' => $this->_newSku[$rowData[self::COL_SKU]],
    'stock_id'   => 1
);

In few next lines magento merges arrays in order:

  1. $defaultStockData
  2. product stock data ( from database if exists )
  3. csv data
  4. $row data ( which should contain only product_id and stock_id )

So we can assume ( without verifying it ), that if $row is not reset with $row = array() then data from first $row will be used as data for all other rows.