avstudnitz / AvS_FastSimpleImport

Wrapper for Magento ImportExport functionality, which imports products and customers from arrays
308 stars 146 forks source link

Import field qty_increments #4

Closed riker09 closed 11 years ago

riker09 commented 12 years ago

I don't know if it's related to your module but I cannot import values for the qty_increment feature. I have data like the following:

$data = array(
    // Import data
);

$data['qty_increments'] = 40;
$data['enable_qty_increments'] = true;
$data['use_config_qty_increments '] = false;
$data['use_config_enable_qty_increments'] = false;

From my understanding the above code should set the value for qty_increments to 40, set the field "Use Qty Increments" ("Verpackungseinheiten verwenden") to TRUE and uncheck the checkboxes for "use configuration settings" so that my custom settings take effect. Unfortunately, it doesn't, nothing happens at all.

All other fields get set properly. The PDF file from Vinai Kopp states on page 19 a list of fields, I've taken the fieldnames from there.

riker09 commented 12 years ago

I found out several things. Some attributes were wrong, here's the correct version:

$data['enable_qty_increments'] = 1;
$data['use_config_enable_qty_inc'] = 0;
$data['qty_increments'] = 40;
$data['use_config_qty_increments'] = 0;

There is a bug in app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php around lines 1617-1621:

                $row = array_merge(
                    $defaultStockData,
                    array_intersect_key($existStockData, $defaultStockData),
                    array_intersect_key($rowData, $defaultStockData),
                    $row
                );

Should be

                $row = array_merge(
                    $row,
                    $defaultStockData,
                    array_intersect_key($existStockData, $defaultStockData),
                    array_intersect_key($rowData, $defaultStockData)
                );

The variable $row in the original code gets merged at the end which overwrites all data with the data from the first imported article. See issue #3

It's still not working, though. The value for the field use_config_enable_qty_inc seems to be ignored by the ImportExport module although it is merged nicely in the above mentioned core file (I dumped the value for $row right after the merge and the value was "0").

paales commented 11 years ago

The data you used probably is old 1.5 data or something.

If you take look at Mage_CatalogInventory_Model_Stock_Item, you'll find:

$this->_oldFieldsMap = array(
    'stock_status_changed_automatically' => 'stock_status_changed_auto',
    'use_config_enable_qty_increments'   => 'use_config_enable_qty_inc'
);

The stock data issue is fixed in https://github.com/avstudnitz/AvS_FastSimpleImport/commit/df0d5cb870425cf6762bf9261855a6cb137d4cf6 if not, i'm not really following :)

As for the problem of not importing your values, I can't really test right now. The thing that the importer does it fills the cataloginventory_stock_item without using the models save function. So the values you import should be reflected in the table. If you can't find the values in the table, something else is going on.

Have you checked the import errors?

echo $importer->getErrorMessage();
mklooss commented 11 years ago

@avstudnitz so i think this issue is already fixed?

avstudnitz commented 11 years ago

The bug @riker09 mentioned is fixed since a few months. I never tested the field qty_increments though.

mklooss commented 11 years ago

@riker09 is actually on holiday, i will ask him when he return :)

riker09 commented 11 years ago

If everyone agrees that this bug is closed then let's close it! If anyone ever encouters this issue again he/she at least has some starting points here.

peterjaap commented 10 years ago

This problem is apparently not solved; when the unsetOldData() function is ran on this line, it unsets both 'use_config_enable_qty_increments' AND 'use_config_enable_qty_inc'. This is due to the fact that $this->_syncFieldsMap is filled with BOTH the new and old values, as happens in the _prepareSyncFieldsMap() in Varien_Object. I can't see the reasoning behind this.

The only way I can see to set the 'use_config_enable_qty_inc' field is by changing this line;

$stockData[] = $stockItem->unsetOldData()->getData();

to;

$stockItemData = $stockItem->unsetOldData()->getData();
$stockItemData['use_config_enable_qty_inc'] = $row['use_config_enable_qty_inc'];
$stockData[] = $stockItemData;

But this feels hacky. Does anyone have a better idea?

krlecarp commented 9 years ago

Peter, thanks for the hacky-enough-for-me-cuz-it's-works fix as long as I'm using modules and not overwriting core files. Was a more elegant solution ever discovered for this?