All configurable products wich all simple products have the same product url.
When you try the Product Url in the frontend it shows some numbers at the end.
http://www.yourshop.com/beach-ball-422.html
Case
http://www.yourshop.com/rechargeable-electric-corkscrew-1912.html
instead of
http://www.yourshop.com/rechargeable-electric-corkscrew.html
Why have the products a number at the end?
Magento fixes the duplicate product urls adding the product_id or the position number.
This is due to multi store from version 1.4.0.1 and multi store.
If you look at any configurable product in the sample data, and at each of the standard products that make up that configurable product – they all have the same URL key set. It appears that the products with a lower-numbered product id (Which I presume this means they were added earlier.) are claiming the URL, and the ones with higher numbers are getting stuck with URL + -1, -2, etc…
How could I fix it?
Right now, that’s Magento default behaviour. If you need to modify the path of a product just go to:
1) Catalog >>> Manage Products
2) Open every single product no visible and add the SKU Option to the end of the “Url Key” (Handpicked tab)
837 – Rechargeable Electric Corkscrew (Black)
URL Key: rechargeable-electric-corkscrew-black
1911 – Rechargeable Electric Corkscrew (Black)
URL Key: rechargeable-electric-corkscrew-silver
1912 – Rechargeable Electric Corkscrew !important: This is the product that you want to have the URL like rechargeable-electric-corkscrew.html
URL Key: rechargeable-electric-corkscrew
3) System >>> Index management
Reindex Catalog Url Rewrites
Note: after doing this, the product still keeps the old wrong URL. Please send us a message to force a reindex from database.
Alternatively, I used to use this script before… but it’s not 100% effective
$visibility = array(
Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE
);
$status = array(
Mage_Catalog_Model_Product_Status::STATUS_ENABLED
);
echo "Simple Products Not Visible but Enabled - delete product_url...<br/>";
$products = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect("url_key")
->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner', null)
->addAttributeToFilter('visibility', $visibility)
->addAttributeToFilter('status', $status);
$i=0;
foreach ($products as $product) {
$product->setData("url_key", "");//$product->getData("url_key")."-".$product->getData("product_id"));
$product->setData("url_key", $product->getData("url_key")."-".$product->getData("product_id"));
$product->save();
//echo $product->getData("url_key");
echo "<br/>";
$i++;
}
echo "Total:$i"."<br/>";
echo "Configurable Products<br/>";
$products = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect("url_key")
->addAttributeToSelect('type_id')
->addAttributeToFilter('status', $status)
->addAttributeToFilter('type_id', Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE);
$i=0;
foreach ($products as $product) {
$product->setData("url_key", "");//$product->getData("url_key")."-".$product->getData("product_id"));
$product->setData("url_key", $product->getData("url_key")."-".$product->getData("product_id"));
$product->save();
//echo $product->getData("url_key");
echo "<br/>";
$i++;
}
echo "Total:$i"."<br/>";
David
on Jan 19th, 2011
@ 3:43 pm:
Hi Ignacio,
I’m having the same issue with Magento…
Can you tell me from where you run that script?
Thx a million ;-)
admin
on Jan 21st, 2011
@ 12:24 am:
Hi David,
Check the post updated for the solution.
Best regards
David
on Dec 1st, 2011
@ 2:04 am:
Where to run this script? I am having the same issue in 1.5.10