Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#9113 fix url_path attribute value is not populated #12012

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/code/Magento/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*
Expand Down
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 */
private $productUrlPathGenerator;

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

/**
* @param \Magento\Framework\Event\Observer $observer
* @return void
*/
public function execute(Observer $observer)
{
/** @var Product $product */
$product = $observer->getEvent()->getProduct();
$product->setUrlKey($this->productUrlPathGenerator->getUrlPath($product));
Copy link
Contributor

@ihor-sviziev ihor-sviziev Nov 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Looks like you was thinking to us $product->setUrlPath() method instead
  2. Would be great to add some unit or integration test there. Could you add it?

If you need any help - feel free to ask

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sure! I need more coffee :P

}
}
1 change: 1 addition & 0 deletions app/code/Magento/CatalogUrlRewrite/etc/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand Down