Magento – How to Enforce Product Status Import on Product Import

importimportexportproductstatus

I'm Importing products from another shop system to a new magento installation (1.9.0.1). Therefore I have created a CSV which gets imported via a import profile. The import process shows no errors but after the import the products don't show up in Catalog -> Manage Products. But they do show up in Catalog -> Manage Categories and they can also be edited/accessed via the url /catalog_product/edit/id/{manually enter new ID here}.

In the edit form and when exporting the products again and comparing them to correct products (which do show up and which I created regularly) I noticed, that the status attribute is missing. When I set it from "– Please Select –" in the edit mask to "Enabled" or "Disabled" and save, the product shows up and seems to work properly.

However I have found no way, to get the import profile to import the status in the first place. I have a "status" field in my CSV and I have tried 1, "1", 2, "2", Enabled, "Enabled", Disabled and "Disabled". I have also tried to change the position of my status field but absolutely no luck. Everything else (including media links) gets imported correctly.

What am I missing or what can I do? I also wouldn't mind to bulk fix the products after the import as it is a one time import but as I cannot see them in the catalog list, I am not sure if there is a good way to do so. Or where would be the place to hook into the import process and fix this problem quick and dirty with some php lines that would just enforces that a status is set on every product import (I'm new to magento, so I'm not really sure where I should start looking).

Thanks for any tips!

Best Answer

Meanwhile I have digged some further and it looks like more people have similar problems. Unfortunately there is nowhere a real clue why this kind of problems occur on some imports in the first place.

But there are workarounds. For the sake of completeness here two similar cases with similar workaround suggestions: Magento products not showing up after import https://stackoverflow.com/questions/12953584/product-is-not-displaying-in-listing-in-magento-after-import

Based on these threads and some other suggestions I found I now built a little PHP CLI script for my specific case which only adds the status and only when its missing:

require_once $pathToYourMagentoDirectory.'/app/Mage.php';
Mage::app();

$allProducts = Mage::getModel('catalog/product')->getCollection();
$count = 0;
foreach($allProducts as $product) {
    $currentStatus = Mage::getResourceModel('catalog/product')->getAttributeRawValue($product->getEntityId(), 'status');
    if ($currentStatus != 1 && $currentStatus != 2) {
        $product->setData('status', 1)->getResource()->saveAttribute($product, 'status');
        $count++;
    }
}
echo ('Fixed '.$count.' products by adding a valid status.');
echo ("\n");

In my case a SQL based fix like suggested in the comments above wouldn't have worked as catalog_product_entity_id simply had no entries for the newly imported products and the status attribute which could have been updated.

Still an odd problem and maybe there would be a better way to approach this - i. e. getting the initial import to work properly...

Related Topic