質問

I want to rewrite the url of product from

www.example.com/product-name.html

To

www.example.com/SKU.html

Someone can help me? The products we sell are unique, but share the same name. So when we add two different products with the same name, it throws back the error that that URL already exists.

役に立ちましたか?

解決

Please created a custom module to override

/vendor/magento/module-catalog-url-rewrite/Model/ProductUrlPathGenerator.php

Where in prepareProductUrlKey()

From

return $product->formatUrlKey($urlKey === '' || $urlKey === null ? $product->getName() : $urlKey);

To

return $product->formatUrlKey($urlKey === '' || $urlKey === null ? $product->getName() . "-" . $product->getSku() : $urlKey);

Thanks

ライセンス: CC-BY-SA帰属
所属していません magento.stackexchange
scroll top