/**
  * Generate list of urls for global scope
  *
  * @return \Magento\UrlRewrite\Service\V1\Data\UrlRewrite[]
  */
 protected function generateForGlobalScope()
 {
     $urls = [];
     $categoryId = $this->category->getId();
     foreach ($this->category->getStoreIds() as $id) {
         if (!$this->isGlobalScope($id) && !$this->storeViewService->doesEntityHaveOverriddenUrlKeyForStore($id, $categoryId, Category::ENTITY)) {
             $urls = array_merge($urls, $this->generateForSpecificStoreView($id));
         }
     }
     return $urls;
 }
 /**
  * @param Category $category
  * @return void
  */
 protected function updateUrlPathForChildren(Category $category)
 {
     $children = $this->childrenCategoriesProvider->getChildren($category, true);
     if ($this->isGlobalScope($category->getStoreId())) {
         foreach ($children as $child) {
             foreach ($category->getStoreIds() as $storeId) {
                 if ($this->storeViewService->doesEntityHaveOverriddenUrlPathForStore($storeId, $child->getId(), Category::ENTITY)) {
                     $child->setStoreId($storeId);
                     $this->updateUrlPathForCategory($child);
                 }
             }
         }
     } else {
         foreach ($children as $child) {
             $child->setStoreId($category->getStoreId());
             $this->updateUrlPathForCategory($child);
         }
     }
 }
Example #3
0
 public function testSkipGenerationForGlobalScope()
 {
     $this->category->expects($this->any())->method('getStoreIds')->will($this->returnValue([1, 2]));
     $this->storeViewService->expects($this->exactly(2))->method('doesEntityHaveOverriddenUrlKeyForStore')->will($this->returnValue(true));
     $this->assertEquals([], $this->categoryUrlRewriteGenerator->generate($this->category));
 }
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage Cannot retrieve attribute for entity type "invalid_type"
  */
 public function testInvalidAttributeRetrieve()
 {
     $invalidEntityType = 'invalid_type';
     $this->config->expects($this->once())->method('getAttribute')->will($this->returnValue(false));
     $this->storeViewService->doesEntityHaveOverriddenUrlKeyForStore(1, 1, $invalidEntityType);
 }
 /**
  * @param int $storeId
  * @param int $categoryId
  * @return bool
  */
 protected function isOverrideUrlsForStore($storeId, $categoryId)
 {
     return $this->overrideStoreUrls || !$this->storeViewService->doesEntityHaveOverriddenUrlKeyForStore($storeId, $categoryId, Category::ENTITY);
 }