示例#1
0
 /**
  * Returns CSV file
  *
  * @return array
  * @throws LocalizedException
  */
 public function getCsvFile()
 {
     $component = $this->filter->getComponent();
     $name = md5(microtime());
     $file = 'export/' . $component->getName() . $name . '.csv';
     $this->filter->prepareComponent($component);
     $this->filter->applySelectionOnTargetProvider();
     $dataProvider = $component->getContext()->getDataProvider();
     $fields = $this->metadataProvider->getFields($component);
     $options = $this->metadataProvider->getOptions();
     $this->directory->create('export');
     $stream = $this->directory->openFile($file, 'w+');
     $stream->lock();
     $stream->writeCsv($this->metadataProvider->getHeaders($component));
     $i = 1;
     $searchCriteria = $dataProvider->getSearchCriteria()->setCurrentPage($i)->setPageSize($this->pageSize);
     $totalCount = (int) $dataProvider->getSearchResult()->getTotalCount();
     while ($totalCount > 0) {
         $items = $dataProvider->getSearchResult()->getItems();
         foreach ($items as $item) {
             $this->metadataProvider->convertDate($item, $component->getName());
             $stream->writeCsv($this->metadataProvider->getRowData($item, $fields, $options));
         }
         $searchCriteria->setCurrentPage(++$i);
         $totalCount = $totalCount - $this->pageSize;
     }
     $stream->unlock();
     $stream->close();
     return ['type' => 'filename', 'value' => $file, 'rm' => true];
 }
 /**
  * @param string $key
  * @param array $fields
  * @param array $options
  * @param array $expected
  * @dataProvider getRowDataProvider
  */
 public function testGetRowData($key, $fields, $options, $expected)
 {
     $document = $this->getMockBuilder('Magento\\Framework\\Api\\Search\\DocumentInterface')->getMockForAbstractClass();
     $attribute = $this->getMockBuilder('Magento\\Framework\\Api\\AttributeInterface')->getMockForAbstractClass();
     $document->expects($this->once())->method('getCustomAttribute')->with($fields[0])->willReturn($attribute);
     $attribute->expects($this->once())->method('getValue')->willReturn($key);
     $result = $this->model->getRowData($document, $fields, $options);
     $this->assertTrue(is_array($result));
     $this->assertCount(1, $result);
     $this->assertEquals($expected, $result);
 }
示例#3
0
 /**
  * Returns CSV file
  *
  * @return array
  * @throws LocalizedException
  */
 public function getCsvFile()
 {
     $component = $this->filter->getComponent();
     $name = md5(microtime());
     $file = 'export/' . $component->getName() . $name . '.csv';
     $this->filter->prepareComponent($component);
     $this->filter->applySelectionOnTargetProvider();
     $searchResult = $component->getContext()->getDataProvider()->getSearchResult();
     $fields = $this->metadataProvider->getFields($component);
     $options = $this->metadataProvider->getOptions();
     $this->directory->create('export');
     $stream = $this->directory->openFile($file, 'w+');
     $stream->lock();
     $stream->writeCsv($this->metadataProvider->getHeaders($component));
     foreach ($searchResult->getItems() as $document) {
         $stream->writeCsv($this->metadataProvider->getRowData($document, $fields, $options));
     }
     $stream->unlock();
     $stream->close();
     return ['type' => 'filename', 'value' => $file, 'rm' => true];
 }
示例#4
0
 /**
  * Returns row data
  *
  * @param DocumentInterface $document
  * @return array
  */
 public function getRowData(DocumentInterface $document)
 {
     return $this->metadataProvider->getRowData($document, $this->getFields(), $this->getOptions());
 }