Ejemplo n.º 1
0
 /**
  * Process correct loading of virtual rule when loading a category via the Flat Resource
  * Built around load() method because the afterLoad() Resource method is only triggered
  * when using the EntityManager, and is not triggered when calling load() method on model explicitely.
  *
  * @param FlatResource $categoryResource Flat Category Resource
  * @param \Closure     $proceed          Flat Category legacy load() method
  * @param DataObject   $category         The category being loaded
  * @param string       $value            The value
  * @param null         $field            Field to process loading on
  */
 public function aroundLoad(FlatResource $categoryResource, \Closure $proceed, $category, $value, $field = null)
 {
     $proceed($category, $value, $field);
     if ($category->getVirtualRule() == null || is_string($category->getVirtualRule())) {
         $attribute = $categoryResource->getAttribute('virtual_rule');
         $attribute->getBackend()->afterLoad($category);
     }
 }
Ejemplo n.º 2
0
 public function testGetCategories()
 {
     $this->categoryCollectionFactoryMock = $this->getMockBuilder(CollectionFactory::class)->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->categoryCollectionMock = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->setMethods(['addNameToResult', 'addUrlRewriteToResult', 'addParentPathFilter', 'addStoreFilter', 'addIsActiveFilter', 'addAttributeToFilter', 'addSortedField', 'load'])->getMock();
     $this->categoryCollectionMock->expects($this->once())->method('addNameToResult')->willReturn($this->categoryCollectionMock);
     $this->categoryCollectionMock->expects($this->once())->method('addUrlRewriteToResult')->willReturn($this->categoryCollectionMock);
     $this->categoryCollectionMock->expects($this->once())->method('addParentPathFilter')->with(self::PARENT_PATH)->willReturn($this->categoryCollectionMock);
     $this->categoryCollectionMock->expects($this->once())->method('addStoreFilter')->willReturn($this->categoryCollectionMock);
     $this->categoryCollectionMock->expects($this->once())->method('addIsActiveFilter')->willReturn($this->categoryCollectionMock);
     $this->categoryCollectionMock->expects($this->once())->method('addSortedField')->with(self::SORTED)->willReturn($this->categoryCollectionMock);
     $this->categoryCollectionMock->expects($this->once())->method('addAttributeToFilter')->with('include_in_menu', 1)->willReturn($this->categoryCollectionMock);
     $this->categoryCollectionMock->expects($this->once())->method('load')->willReturn($this->categoryCollectionMock);
     $this->categoryCollectionFactoryMock->expects($this->once())->method('create')->willReturn($this->categoryCollectionMock);
     $this->model = $this->objectManager->getObject(Flat::class, ['context' => $this->contextMock, 'storeManager' => $this->storeManagerMock]);
     $reflection = new \ReflectionClass(get_class($this->model));
     $reflectionProperty = $reflection->getProperty('categoryFlatCollectionFactory');
     $reflectionProperty->setAccessible(true);
     $reflectionProperty->setValue($this->model, $this->categoryCollectionFactoryMock);
     $this->assertEquals($this->model->getCategories(self::PARENT, self::RECURSION_LEVEL, self::SORTED, true), $this->categoryCollectionMock);
 }