Simple question: where can I find the function in Magento 2 which generates an url key from a products name?
1 Answer
Following class is responsible for generating url key: vendor/magento/module-catalog-url-rewrite/Observer/ProductUrlKeyAutogeneratorObserver.php
/**
* @param \Magento\Framework\Event\Observer $observer
* @return void
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
/** @var Product $product */
$product = $observer->getEvent()->getProduct();
$urlKey = $this->productUrlPathGenerator->getUrlKey($product);
if (null !== $urlKey) {
$product->setUrlKey($urlKey);
}
}