We have upgraded to 1.4.1.0 and have problems with the re-index URL rewrites. We have 56 stores setup in magento and the problem appears to be related this. For every product a new URL rewrite is created for every store and the index process seems to work for 1 store only but the second it starts to index the next store we get the error saving URL rewrites message.
With some debugging and database monitoring, the actual exception being thrown is complaining about a duplicate entry in the url rewrites table but the data is being saved in the database for the record implying that mySQL is not throwing the error because the data would not save if this was the case. We have also noticed that is not a duplicate entry as the primary key is made up of id_path, is_system, & store_id and there are no records matching this even though this error is being thrown.
I have simply commented out the exception being thrown, re-indexed the URL’s and now everything seems to function correctly. I know this is not the fix but it has worked for us temporarily and we know have nice URL’s that work for every product in every store.
I have seen other comments about URL indexing with multiple stores causing problems in this version and was wondering if anybody else has come across this or found a proper fix yet?
The line I commented out to actually get the indexer to work and finish was line 253 in app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Url.php
try { $this->_getWriteAdapter()->insert($this->getMainTable(), $rewriteData); } catch (Exception $e) { //var_dump($e); die(); //Mage::throwException(Mage::helper('catalog')->__('An error occurred while saving the URL rewrite.')); }
If you uncomment the var_dump line and run the indexer you will see the error being thrown complaining about the duplicate entry that is not a duplicate entry.
That’s much help for me.
I looking a lot solution but not much help
I got 2 store and 3 view and I am 100% sure i not duplicate any item url key but I getting this error.
Thanks Ashley, that the only way we can do for now.
We have upgraded to 1.4.1.0 and have problems with the re-index URL rewrites. We have 56 stores setup in magento and the problem appears to be related this. For every product a new URL rewrite is created for every store and the index process seems to work for 1 store only but the second it starts to index the next store we get the error saving URL rewrites message.
With some debugging and database monitoring, the actual exception being thrown is complaining about a duplicate entry in the url rewrites table but the data is being saved in the database for the record implying that mySQL is not throwing the error because the data would not save if this was the case. We have also noticed that is not a duplicate entry as the primary key is made up of id_path, is_system, & store_id and there are no records matching this even though this error is being thrown.
I have simply commented out the exception being thrown, re-indexed the URL’s and now everything seems to function correctly. I know this is not the fix but it has worked for us temporarily and we know have nice URL’s that work for every product in every store.
I have seen other comments about URL indexing with multiple stores causing problems in this version and was wondering if anybody else has come across this or found a proper fix yet?
The line I commented out to actually get the indexer to work and finish was line 253 in app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Url.php
try { $this->_getWriteAdapter()->insert($this->getMainTable(), $rewriteData); } catch (Exception $e) { //var_dump($e); die(); //Mage::throwException(Mage::helper('catalog')->__('An error occurred while saving the URL rewrite.')); }
If you uncomment the var_dump line and run the indexer you will see the error being thrown complaining about the duplicate entry that is not a duplicate entry.
I recently created a new store in a multi-store 1.4.2 environment in which the same product would be listed in multiple categories. I immediately ran into the same URL Re-indexing error as reported above. Rather than simply commenting out the exception I decided to explore a bit. The problem in my case was definitely related to the fact that the same product was listed in multiple sub-categories. It seems that a problem exists in the generatePath function of /app/code/core/Mage/Catalog/Model/Url.php. At around line 780 the following code exists:
It seems that $category->getLevel() fails to return a value, therefore the logic falls through and the id_path is created as product/productid for all records inserted into core_url_rewrite where the same product is found in multiple categories for the same store! Thus violating the UNQ_PATH constraint. Rather than modifying several core files to address this, I took the following expedient hack:
This fixed my problem. Unfortunately, core_url_rewrite has one record for every category to which a product is assigned including the root. This is expected behavior but makes for a long running index process. I hope the *bug* and the index performance is addressed in 1.5.
Alternative to changing the core file, you can always remove the unique constraint for UNQ_PATH via phpMyAdmin or similar. However, there may be unforeseen consequences in doing so. This was my temporary fix before diving into the code. I have 6 stores with a total of 60K skus and while the index was changed I didn\’t see any problems, but your mileage may vary.
I am still experiencing this problem in 1.5.1. This particular index “url rewriting” stays in the status “processing”. However with the same version some days ago, it finished ... Anybody has a solution for this?
I recently created a new store in a multi-store 1.4.2 environment in which the same product would be listed in multiple categories. I immediately ran into the same URL Re-indexing error as reported above. Rather than simply commenting out the exception I decided to explore a bit. The problem in my case was definitely related to the fact that the same product was listed in multiple sub-categories. It seems that a problem exists in the generatePath function of /app/code/core/Mage/Catalog/Model/Url.php. At around line 780 the following code exists:
It seems that $category->getLevel() fails to return a value, therefore the logic falls through and the id_path is created as product/productid for all records inserted into core_url_rewrite where the same product is found in multiple categories for the same store! Thus violating the UNQ_PATH constraint. Rather than modifying several core files to address this, I took the following expedient hack:
This fixed my problem. Unfortunately, core_url_rewrite has one record for every category to which a product is assigned including the root. This is expected behavior but makes for a long running index process. I hope the *bug* and the index performance is addressed in 1.5.
Alternative to changing the core file, you can always remove the unique constraint for UNQ_PATH via phpMyAdmin or similar. However, there may be unforeseen consequences in doing so. This was my temporary fix before diving into the code. I have 6 stores with a total of 60K skus and while the index was changed I didn\’t see any problems, but your mileage may vary.
Hope this helps someone else.
Cheers
This method works for me i’m using Magento 1.5.1.0, installed on a windows server 2008 enviroment.
Before geting this code works correctly, i made a change erasing the backslashes \ form the code and after do that the code let magento
to finish reindexing CATALOG URL REWRITES in less time.
If like me you have a problem by reindexing the url rewrites. I invite you to check if you don’t have a conflict with an other module which overwrites or use the class Mage_Catalog_Model_Resource_Eav_Mysql4_Url
It’s the case if you use the OSCommerce module for Magento like me. There is a conflict, the database query doesn’t ask to load the level of a category. And so, in the core code, $category->getLevel() is empty.
The solution with oscommerce is to do return parent::_getCategories(...) at the very first line of the same method name of the class Mage_Oscommerce_Model_Mysql4_Catalog_Url or remove the class completely (php file and confix.xml)