Question

Simple question: where can I find the function in Magento 2 which generates an url key from a products name?

Was it helpful?

Solution

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);
    }
}

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top