public function testResolve()
 {
     $documentIds = [1, 2, 3];
     $attributeSetIds = [4, 5];
     $requestName = 'request_name';
     $this->attributeSetFinder->expects($this->once())->method('findAttributeSetIdsByProductIds')->with($documentIds)->willReturn($attributeSetIds);
     $searchCriteria = $this->getMock(SearchCriteriaInterface::class);
     $this->searchCriteriaBuilder->expects($this->once())->method('addFilter')->with('attribute_set_id', $attributeSetIds, 'in')->willReturnSelf();
     $this->searchCriteriaBuilder->expects($this->once())->method('create')->willReturn($searchCriteria);
     $attributeFirst = $this->getMock(ProductAttributeInterface::class);
     $attributeFirst->expects($this->once())->method('getAttributeCode')->willReturn('code_1');
     $attributeSecond = $this->getMock(ProductAttributeInterface::class);
     $attributeSecond->expects($this->once())->method('getAttributeCode')->willReturn('code_2');
     $searchResult = $this->getMock(ProductAttributeSearchResultsInterface::class);
     $searchResult->expects($this->once())->method('getItems')->willReturn([$attributeFirst, $attributeSecond]);
     $this->productAttributeRepository->expects($this->once())->method('getList')->with($searchCriteria)->willReturn($searchResult);
     $bucketFirst = $this->getMock(BucketInterface::class);
     $bucketFirst->expects($this->once())->method('getField')->willReturn('code_1');
     $bucketSecond = $this->getMock(BucketInterface::class);
     $bucketSecond->expects($this->once())->method('getField')->willReturn('some_another_code');
     $bucketThird = $this->getMock(BucketInterface::class);
     $bucketThird->expects($this->once())->method('getName')->willReturn('custom_not_attribute_field');
     $this->request->expects($this->once())->method('getAggregation')->willReturn([$bucketFirst, $bucketSecond, $bucketThird]);
     $this->request->expects($this->once())->method('getName')->willReturn($requestName);
     $this->config->expects($this->once())->method('get')->with($requestName)->willReturn(['aggregations' => ['custom_not_attribute_field' => []]]);
     $this->assertEquals([$bucketFirst, $bucketThird], $this->aggregationResolver->resolve($this->request, $documentIds));
 }
Пример #2
0
 /**
  * Get applicable attributes
  *
  * @param array $documentIds
  * @return array
  */
 private function getApplicableAttributeCodes(array $documentIds)
 {
     $attributeSetIds = $this->attributeSetFinder->findAttributeSetIdsByProductIds($documentIds);
     $searchCriteria = $this->searchCriteriaBuilder->addFilter('attribute_set_id', $attributeSetIds, 'in')->create();
     $result = $this->productAttributeRepository->getList($searchCriteria);
     $attributeCodes = [];
     foreach ($result->getItems() as $attribute) {
         $attributeCodes[] = $attribute->getAttributeCode();
     }
     return $attributeCodes;
 }