Skip to content

Commit

Permalink
magento#9113 fix url_path attribute value is not populated
Browse files Browse the repository at this point in the history
thiagolima-bm committed Nov 4, 2017
1 parent 9d75bca commit 56b9b19
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/code/Magento/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@
* @method \Magento\Catalog\Model\ResourceModel\Product\Collection getCollection()
* @method string getUrlKey()
* @method Product setUrlKey(string $urlKey)
* @method Product setUrlPath(string $urlKey)
* @method Product setRequestPath(string $requestPath)
* @method Product setWebsiteIds(array $ids)
*
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CatalogUrlRewrite\Observer;

use Magento\Catalog\Model\Product;
use Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

class ProductUrlPathAutogeneratorObserver implements ObserverInterface
{
/** @var ProductUrlPathGenerator */
protected $productUrlPathGenerator;

/**
* @param ProductUrlPathGenerator $productUrlPathGenerator
*/
public function __construct(ProductUrlPathGenerator $productUrlPathGenerator)
{
$this->productUrlPathGenerator = $productUrlPathGenerator;
}

/**
* @param \Magento\Framework\Event\Observer $observer
* @return void
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
/** @var Product $product */
$product = $observer->getEvent()->getProduct();
$product->setUrlPath($this->productUrlPathGenerator->getUrlPath($product));
}
}
1 change: 1 addition & 0 deletions app/code/Magento/CatalogUrlRewrite/etc/events.xml
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@
</event>
<event name="catalog_product_save_before">
<observer name="product_url_key_autogeneration" instance="Magento\CatalogUrlRewrite\Observer\ProductUrlKeyAutogeneratorObserver"/>
<observer name="product_url_path_autogeneration" instance="Magento\CatalogUrlRewrite\Observer\ProductUrlPathAutogeneratorObserver"/>
</event>
<event name="catalog_product_save_after">
<observer name="process_url_rewrite_saving" instance="Magento\CatalogUrlRewrite\Observer\ProductProcessUrlRewriteSavingObserver"/>

0 comments on commit 56b9b19

Please sign in to comment.