Magento – How to replace existing values by NULL or removing them using CSV import

csvimportmagento-enterprise

Our client uses Magento CSV import/export functionality to import and export stocks and pricing regularly.

Special prices for the products keeps changing. While importing special prices, if we keep the special price row as blank it won't replace the special pricing in the product. Also, if we pass NULL the special pricing becomes 0 and we start giving customer freebies.

we need to remove the special price when customer imports using CSV. It is fine to pass some parameters if required.

Can anyone guide me how this needs to be done?

Best Answer

Good question, unfortunately it's impossible with default Magento. If you absolutely need it, you can extend the method Mage_ImportExport_Model_Import_Entity_Product::_filterRowData or its Enterprise counterpart. Add something like the following lines:

foreach($rowData as $key => $fieldValue) {
    if (!trim($fieldValue) && $key == 'special_price') {
        $rowData[$key] = NULL;
    } 
}

We have done something similar for AvS_FastSimpleImport, see https://github.com/avstudnitz/AvS_FastSimpleImport/blob/master/src/app/code/community/AvS/FastSimpleImport/Model/Import/Entity/Product.php#L1283. We remove the value if a special value ("###EMPTY###") is found in the import.

Please, don't put that code into the core class directly, but make a rewrite or at least copy the whole file to app/code/local/Mage/ImportExport/Model/Import/Entity/Product.php.

Related Topic