2

After updating some products by importing csv file, there are some of them that display 404 error in frontend product view page.

  • Saving these products manually solves the issue.
  • Saving these products by using "update attributes" action, does NOT solve the issue
  • Re-indexing product data does NOT solve the issue
  • I have a single website/store/view in magento.

Does anybody know where does this issue come from and how can i fix it, without having to re-save products one by one?

-------- UPDATE ---------

I have noticed that these products have no records in "URL Rewrite Management".

The strange thing is that reindexing does not re-generate urls rewrites, but saving product does.

enter image description here

  • Does a full reindex (not only product attributes) solves the issue ? Because issue could come from the url reindex, or category product association reindex. – Julien Loizelet Feb 13 at 14:43
  • No, full re-index is not working. I just noticed that it has to do with url rewrites. Saving the product re-creates rewritres, but updating by import does not work that way? – zekia Feb 13 at 14:45
  • Maybe you have to set the url path somewhere in your csv (in fact I have no idea). – Julien Loizelet Feb 13 at 15:22
  • @zekia Check my updated answer, i think you miss to add url_key in your import csv file. If that solves the issue great, else try update #2. – Haijerome Feb 14 at 16:37
1

Update

BTW make sure in your import csv url_key field/column is added with respective values, if not magento will not add the url rewrites, this minor mistake could be the possible cause of the issue that you face right now. Kindly add url_key in your import csv and update.

If still the issue persists then try update #2.

Saving these products manually solves the issue.

Re-indexing product data does NOT solve the issue

Both of your statements confirm that the respective indexers were not refreshed after import. Though you manually re-indexed all the indexers these products didn't show up, its weird.When you save the products manually from the admin panel your products appear on the store front, which means the indexers refreshed update on save.

So to quickly answer your question and make your products show up on storefront without having to re-save products one by one. You need to write a quick script which will refresh all the indexers for the given product which makes it appear on the store front.

Added below a quick code to refresh all the indexers of the products which do not show up in the store front. just add your product ids in productIdsToRefreshIndex array.

//add all your products ids to this array
$productIdsToRefreshIndex = array(2014,2015,2016,2017,2018,2019,2020);

$event = Mage::getModel('index/event');
$event->setNewData(array(
    'product_ids' => &$productIdsToRefreshIndex
));

Mage::getResourceSingleton('catalog/category_indexer_product')->catalogProductMassAction($event);

// Reindex prices
Mage::getResourceModel('catalog/product_indexer_price')->reindexProductIds($productIdsToRefreshIndex);

// Reindex stock
Mage::getResourceModel('cataloginventory/indexer_stock')->reindexProducts($productIdsToRefreshIndex); 

// Reindex attributes
Mage::getResourceModel('catalog/product_indexer_eav_source')->reindexEntities($productIdsToRefreshIndex);

 //Reindex catalogsearch fulltext
$catalogSearchIndexer = Mage::getResourceModel('catalogsearch/fulltext');
$catalogSearchIndexer->rebuildIndex(null, $productIdsToRefreshIndex);

Update #2 - Refreshing Product URL Rewrites

//add all your products ids to this array
$productIdsToRefreshIndex = array(2014,2015,2016,2017,2018,2019,2020);



// check Mage_Catalog_Model_Url::refreshProductRewrite method for more details

// create a catalog url instance    
$_catalogUrl = Mage::getSingleton('catalog/url');

foreach($productIdsToRefreshIndex as $key => $productId) {
    $_catalogUrl->refreshProductRewrite($productId);      
}

This piece of code will create url rewrites for your products. Just pass the right product ids and store ids.

As well as , When you save the product from the admin panel, the url rewrites of the product will be updated based on the url key provided, which is the behavior you observed.

  • Thank you for your answer. I tried running the code but nothing changed. – zekia Feb 14 at 7:03
  • I noticed that there are no records for these products in Url Rewrite Management. After saving products the url rewrites are generated again. I guess that's the issue here. Is your code supposed to re-generate url rewrites? – zekia Feb 14 at 7:06
  • @zekia Yes the code given above is to refresh the respective indexers which also includes catalog url rewrites. Check my updated answer, i think you miss to add url_key in your import csv file. If that solves the issue great, else try update #2. – Haijerome Feb 14 at 16:37
  • url_key is not included in import csv file. This is an import proccess used to update stock qts, that's why url key is not included. Do you know that this is obligatory column? These products have already url keys, they are not new. There were url rewrites for them, but I assume that updating the by import, deletes existing url rewrites. Unfortunately, both scripts fail to regenerate url rewrites for these products. – zekia Feb 19 at 8:41
  • I'll try to import product with url_key column – zekia Feb 19 at 8:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.