|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2013-2017 Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\CatalogUrlRewrite\Observer; |
| 7 | + |
| 8 | +use Magento\Framework\Event\ObserverInterface; |
| 9 | +use Magento\Framework\Message\ManagerInterface; |
| 10 | +use Magento\Framework\Escaper; |
| 11 | + |
| 12 | +class DuplicateUrlControllerAfterSaveObserver implements ObserverInterface |
| 13 | +{ |
| 14 | + /** |
| 15 | + * @var \Magento\Framework\Message\ManagerInterface |
| 16 | + */ |
| 17 | + private $messageManager; |
| 18 | + |
| 19 | + /** |
| 20 | + * @var Escaper |
| 21 | + */ |
| 22 | + private $escaper; |
| 23 | + |
| 24 | + /** |
| 25 | + * @param ManagerInterface $messageManager |
| 26 | + * @param Escaper $escaper |
| 27 | + */ |
| 28 | + public function __construct( |
| 29 | + ManagerInterface $messageManager, |
| 30 | + Escaper $escaper |
| 31 | + ) { |
| 32 | + $this->messageManager = $messageManager; |
| 33 | + $this->escaper = $escaper; |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * Add url collisions notices |
| 38 | + * |
| 39 | + * @param \Magento\Framework\Event\Observer $observer |
| 40 | + * @return void |
| 41 | + */ |
| 42 | + public function execute(\Magento\Framework\Event\Observer $observer) |
| 43 | + { |
| 44 | + /** @var \Magento\Catalog\Model\Product $product */ |
| 45 | + $product = $observer->getEvent()->getProduct(); |
| 46 | + if ($product->getData('unsaved_urls')) { |
| 47 | + $urls = ''; |
| 48 | + foreach ($product->getData('unsaved_urls') as $url) { |
| 49 | + /** @var \Magento\UrlRewrite\Service\V1\Data\UrlRewrite $url */ |
| 50 | + $urls .= $url->getRequestPath() . ', '; |
| 51 | + } |
| 52 | + $urls = rtrim($urls, ', '); |
| 53 | + $this->messageManager->addNoticeMessage( |
| 54 | + __( |
| 55 | + 'The following urls have not been saved for product %1: %2', |
| 56 | + $this->escaper->escapeHtml($product->getName()), |
| 57 | + $this->escaper->escapeHtml($urls) |
| 58 | + ) |
| 59 | + ); |
| 60 | + } |
| 61 | + } |
| 62 | +} |
0 commit comments