当前位置: 动力学知识库 > 问答 > 编程问答 >

Magento url_key for products does not work. Magento adds an increasing ID for each update,

问题描述:

during importing products to magento I use setUrlKey method for setting the url_key property:

$products_name = "I am a test product";

$product->setUrlKey($products_name);

This works fine, but when I open the product in the shop the url is not

"i-am-a-test-product". The url is "i-am-a-test-product-1". When I restart my import script the url will be "i-am-a-test-product-2". Magento adds an ID after the url_key and increases it for each run.

Of the course all products names are unique.

How can I stop magento adding these ID's inside the url_key?

For categories I do not have these problems.

网友答案:

Try to make your own url key by this code:

$urlKey = preg_replace('#[^0-9a-z]+#i', '-', $products_name);
$urlKey = strtolower($urlKey);
$product->setUrlKey($urlKey);
分享给朋友:
您可能感兴趣的文章:
随机阅读: