Domanda

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

È stato utile?

Soluzione

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top