/**
  * Retrieve slides matching the specified criteria.
  *
  * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
  * @return \Magento\Framework\Api\SearchResultsInterface
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
 {
     $this->searchResultsFactory->setSearchCriteria($searchCriteria);
     $collection = $this->slideCollectionFactory->create();
     foreach ($searchCriteria->getFilterGroups() as $filterGroup) {
         foreach ($filterGroup->getFilters() as $filter) {
             $condition = $filter->getConditionType() ?: 'eq';
             $collection->addFieldToFilter($filter->getField(), [$condition => $filter->getValue()]);
         }
     }
     $this->searchResultsFactory->setTotalCount($collection->getSize());
     $sortOrders = $searchCriteria->getSortOrders();
     if ($sortOrders) {
         foreach ($sortOrders as $sortOrder) {
             $collection->addOrder($sortOrder->getField(), strtoupper($sortOrder->getDirection()) === 'ASC' ? 'ASC' : 'DESC');
         }
     }
     $collection->setCurPage($searchCriteria->getCurrentPage());
     $collection->setPageSize($searchCriteria->getPageSize());
     $slides = [];
     /** @var \Foggyline\Slider\Model\Slide $slideModel */
     foreach ($collection as $slideModel) {
         $slideData = $this->dataSlideFactory->create();
         $this->dataObjectHelper->populateWithArray($slideData, $slideModel->getData(), '\\Foggyline\\Slider\\Api\\Data\\SlideInterface');
         $slides[] = $this->dataObjectProcessor->buildOutputDataArray($slideData, '\\Foggyline\\Slider\\Api\\Data\\SlideInterface');
     }
     $this->searchResultsFactory->setItems($slides);
     return $this->searchResultsFactory;
 }
Esempio n. 2
0
 public function testModifyData()
 {
     $sourceData = ['1' => ['product' => [ProductAttributeInterface::CODE_PRICE => '19.99']]];
     $this->locatorMock->expects($this->any())->method('getProduct')->willReturn($this->productMock);
     $this->productMock->expects($this->any())->method('getId')->willReturn(1);
     $this->productMock->expects($this->once())->method('getAttributeSetId')->willReturn(4);
     $this->productMock->expects($this->once())->method('getData')->with(ProductAttributeInterface::CODE_PRICE)->willReturn('19.9900');
     $this->searchCriteriaBuilderMock->expects($this->any())->method('addFilter')->willReturnSelf();
     $this->searchCriteriaBuilderMock->expects($this->any())->method('create')->willReturn($this->searchCriteriaMock);
     $this->attributeGroupRepositoryMock->expects($this->any())->method('getList')->willReturn($this->searchCriteriaMock);
     $this->searchCriteriaMock->expects($this->once())->method('getItems')->willReturn([$this->attributeGroupMock]);
     $this->sortOrderBuilderMock->expects($this->once())->method('setField')->willReturnSelf();
     $this->sortOrderBuilderMock->expects($this->once())->method('setAscendingDirection')->willReturnSelf();
     $dataObjectMock = $this->getMock('\\Magento\\Framework\\Api\\AbstractSimpleObject', [], [], '', false);
     $this->sortOrderBuilderMock->expects($this->once())->method('create')->willReturn($dataObjectMock);
     $this->searchCriteriaBuilderMock->expects($this->any())->method('addFilter')->willReturnSelf();
     $this->searchCriteriaBuilderMock->expects($this->once())->method('addSortOrder')->willReturnSelf();
     $this->searchCriteriaBuilderMock->expects($this->any())->method('create')->willReturn($this->searchCriteriaMock);
     $this->attributeRepositoryMock->expects($this->once())->method('getList')->with($this->searchCriteriaMock)->willReturn($this->searchResultsMock);
     $this->eavAttributeMock->expects($this->any())->method('getAttributeGroupCode')->willReturn('product-details');
     $this->eavAttributeMock->expects($this->once())->method('getApplyTo')->willReturn([]);
     $this->eavAttributeMock->expects($this->once())->method('getFrontendInput')->willReturn('price');
     $this->eavAttributeMock->expects($this->any())->method('getAttributeCode')->willReturn(ProductAttributeInterface::CODE_PRICE);
     $this->searchResultsMock->expects($this->once())->method('getItems')->willReturn([$this->eavAttributeMock]);
     $this->storeMock->expects($this->once())->method('getBaseCurrencyCode')->willReturn('en_US');
     $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($this->storeMock);
     $this->currencyMock->expects($this->once())->method('toCurrency')->willReturn('19.99');
     $this->currencyLocaleMock->expects($this->once())->method('getCurrency')->willReturn($this->currencyMock);
     $this->assertEquals($sourceData, $this->eav->modifyData([]));
 }