/**
  * @param Category $category
  * @return void
  */
 protected function updateUrlPathForChildren(Category $category)
 {
     foreach ($this->childrenCategoriesProvider->getChildren($category, true) as $childCategory) {
         $childCategory->unsUrlPath();
         $childCategory->setUrlPath($this->categoryUrlPathGenerator->getUrlPath($childCategory));
         $childCategory->getResource()->saveAttribute($childCategory, 'url_path');
     }
 }
Example #2
0
 /**
  * Remove product urls from storage
  *
  * @param \Magento\Catalog\Model\ResourceModel\Category $subject
  * @param callable $proceed
  * @param CategoryInterface $category
  * @return mixed
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundDelete(\Magento\Catalog\Model\ResourceModel\Category $subject, \Closure $proceed, CategoryInterface $category)
 {
     $categoryIds = $this->childrenCategoriesProvider->getChildrenIds($category, true);
     $categoryIds[] = $category->getId();
     $result = $proceed($category);
     foreach ($categoryIds as $categoryId) {
         $this->deleteRewritesForCategory($categoryId);
     }
     return $result;
 }
 /**
  * Generate list of children urls
  *
  * @param int $storeId
  * @param \Magento\Catalog\Model\Category $category
  * @return \Magento\UrlRewrite\Service\V1\Data\UrlRewrite[]
  */
 public function generate($storeId, Category $category)
 {
     $urls = [];
     foreach ($this->childrenCategoriesProvider->getChildren($category) as $childCategory) {
         $childCategory->setStoreId($storeId);
         $childCategory->setData('save_rewrites_history', $category->getData('save_rewrites_history'));
         $urls = array_merge($urls, $this->categoryUrlRewriteGeneratorFactory->create()->generate($childCategory));
     }
     return $urls;
 }
 public function testGetChildren()
 {
     $categoryLevel = 3;
     $this->select->expects($this->at(1))->method('where')->with('path LIKE :c_path')->willReturnSelf();
     $this->select->expects($this->at(2))->method('where')->with('level <= :c_level')->willReturnSelf();
     $this->category->expects($this->once())->method('isObjectNew')->willReturn(false);
     $this->category->expects($this->once())->method('getLevel')->willReturn($categoryLevel);
     $bind = ['c_path' => 'category-path/%', 'c_level' => $categoryLevel + 1];
     $this->connection->expects($this->any())->method('fetchCol')->with($this->select, $bind)->willReturn(['id']);
     $this->childrenCategoriesProvider->getChildren($this->category, false);
 }
 /**
  * @param Category $category
  * @return void
  */
 public function deleteCategoryRewritesForChildren(Category $category)
 {
     $categoryIds = $this->childrenCategoriesProvider->getChildrenIds($category, true);
     $categoryIds[] = $category->getId();
     foreach ($categoryIds as $categoryId) {
         $this->urlPersist->deleteByData([UrlRewrite::ENTITY_ID => $categoryId, UrlRewrite::ENTITY_TYPE => CategoryUrlRewriteGenerator::ENTITY_TYPE]);
         $this->urlPersist->deleteByData([UrlRewrite::METADATA => serialize(['category_id' => $categoryId]), UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE]);
     }
 }
 /**
  * @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);
         }
     }
 }