catalog_product_flat_1 has wrong url_path

While reviewing the google merchant center dashboard, I’d notice every now and then that there would be errors listed as ‘wrong url’.  At first, there were only a few skus, so I simply ignored the issue until each week there’d be more and more skus listed.

Doing some research into it, the google feed file seemed to be processing correctly (out of 9000+ skus, only a few issues) but I noticed that the skus in question had a number appended to the url_path – most likely because the url_key was duplicated. The issue though was that there were multiple entries of the same sku with different url_paths with different numbers.

It appeared that it kept adding additional url_paths – probably when the url rewrites were reindexed. So, I started searching for a solution to the duplicate product urls.

The solution was found here

COPY: app/code/core/Mage/Catalog/Model/Url.php

TO: app/code/local/Mage/Catalog/Model/Url.php

and make one simple change on line 809 (comment out and add the line below):

//if ($product->getUrlKey() == '' && !empty($requestPath)
if (!empty($requestPath)

I didn’t want to truncate the table because there were a lot of custom rewrites that I’d lose, so instead I ran a sql query that gave me the mismatch records –

SELECT catalog_product_flat_1.entity_id, core_url_rewrite.product_id,, catalog_product_flat_1.url_key, catalog_product_flat_1.url_path, core_url_rewrite.request_path, core_url_rewrite.options
FROM catalog_product_flat_1 INNER JOIN core_url_rewrite ON catalog_product_flat_1.entity_id = core_url_rewrite.product_id
WHERE (((catalog_product_flat_1.url_path)<>core_url_rewrite.request_path));

Because there were only a few, I simply deleted the core_url_rewrite records manually (You could change the ‘select’ query to a ‘delete’  query using the same criteria to delete the core_url_rewrite records)

Reindex the catalog url rewrites and product flat data – run the selct query again and if no errors/mismatches are listed – you’re good to go!!

As noted in the stackexchange board – Thanks to Jahnni and snowcountry at the Magento Board:

Leave a Reply