Beispiel #1
0
 /**
  * Generate urls for UrlRewrite and save it in storage
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function processUrlRewriteSaving(EventObserver $observer)
 {
     /** @var \Magento\Catalog\Model\Category $category */
     $category = $observer->getEvent()->getCategory();
     if (!$this->catalogUrlRewriteHelper->isRootCategory($category) && (!$category->getData('url_key') || $category->getOrigData('url_key') != $category->getData('url_key'))) {
         $this->urlSave->save($this->categoryUrlGenerator->generate($category));
         $products = $category->getProductCollection()->addAttributeToSelect('url_key')->addAttributeToSelect('url_path');
         foreach ($products as $product) {
             $product->setData('save_rewrites_history', $category->getData('save_rewrites_history'));
             $this->urlSave->save($this->productUrlGenerator->generateWithChangedCategories($product, [$category->getId() => $category]));
         }
     }
 }
Beispiel #2
0
 /**
  * Generate list of urls per store
  *
  * @param int $storeId
  * @return \Magento\UrlRedirect\Service\V1\Data\UrlRewrite[]
  */
 protected function generateForStore($storeId)
 {
     $urls[] = $this->createUrlRewrite($storeId, $this->catalogUrlRewriteHelper->getProductUrlKeyPath($this->product, $storeId), $this->catalogUrlRewriteHelper->getProductCanonicalUrlPath($this->product));
     foreach ($this->getCategories() as $category) {
         if (isset($this->changedCategories[$category->getId()])) {
             $category = $this->changedCategories[$category->getId()];
         }
         if ($this->catalogUrlRewriteHelper->isRootCategory($category)) {
             continue;
         }
         $urls[] = $this->createUrlRewrite($storeId, $this->catalogUrlRewriteHelper->getProductUrlKeyPathWithCategory($this->product, $category, $storeId), $this->catalogUrlRewriteHelper->getProductCanonicalUrlPathWithCategory($this->product, $category));
     }
     return array_merge($urls, $this->generateRewritesBasedOnCurrentRewrites($storeId));
 }