2

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

1 Answer 1

4

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.