Always check your magento log

The error shown in /var/log/exception.log was the following:

exception ‘PDOException’ with message ‘SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ‘product/6685-1-1′ for key ‘UNQ_CORE_URL_REWRITE_ID_PATH_IS_SYSTEM_STORE_ID” in /var/www/http/lib/Zend/Db/Statement/Pdo.php:228

If you can see something similar to above then do the following tests to rectify the problem.

Check for duplicate URL keys

Using the following MySQL query is the easiest way to figure out which products are using the same URL keys:

SELECT url_key,
COUNT(url_key) AS NumOccurrences
FROM catalog_product_flat_1
GROUP BY url_key HAVING ( COUNT(url_key) > 1 );

In case there are records responding to these conditions, you will have to change their URL keys making them unique or just remove the old ones which are obsolete.

Check for duplicate SKUs

Use the following MySQL query to find out if there are products with the same SKU codes:

SELECT
DISTINCT(sku) as sku,
COUNT(sku) as skuCount,entity_id

FROM catalog_product_entity
GROUP BY sku HAVING (skuCount > 1);

If this query shows no records, you are doing fine, otherwise you will have to manually modify all the records sharing the same SKU.

Check for duplicate products’ names

Usually, if there are two or more items with the same name, Magento SHOULD append each product’s SKU code to the URL key field, thus preventing duplicate URL paths to be generated. This doesn’t always happen and, in that case, you will have to check for duplicate names using this query:

SELECT name,
COUNT(name) AS NumOccurrences
FROM catalog_product_flat_1
GROUP BY name HAVING ( COUNT(name) > 1 );

Original post credited: http://www.albertomariarossi.it/howto-solve-url-rewrite-indexing-errors-in-magento/

Categorized in: