/**
  * @param string $from
  * @param string $to
  * @param string $period
  * @param array $results
  * @dataProvider intervalsDataProvider
  * @return void
  */
 public function testPrepareIntervalsCollection($from, $to, $period, $results)
 {
     $collection = $this->getMockBuilder('Magento\\Framework\\Data\\Collection')->disableOriginalConstructor()->setMethods(['addItem'])->getMock();
     $item = $this->getMockBuilder('Magento\\Reports\\Model\\Item')->disableOriginalConstructor()->setMethods(['setPeriod', 'setIsEmpty'])->getMock();
     $this->itemFactoryMock->expects($this->exactly(count($results)))->method('create')->willReturn($item);
     $item->expects($this->exactly(count($results)))->method('setIsEmpty');
     $collection->expects($this->exactly(count($results)))->method('addItem');
     foreach ($results as $key => $result) {
         $item->expects($this->at($key + $key))->method('setPeriod')->with($result);
     }
     $this->data->prepareIntervalsCollection($collection, $from, $to, $period);
 }
Beispiel #2
0
 /**
  * @return $this|\Magento\Backend\Block\Widget\Grid
  */
 protected function _prepareCollection()
 {
     $filterData = $this->getFilterData();
     if ($filterData->getData('from') == null || $filterData->getData('to') == null) {
         $this->setCountTotals(false);
         $this->setCountSubTotals(false);
         return parent::_prepareCollection();
     }
     $storeIds = $this->_getStoreIds();
     $orderStatuses = $filterData->getData('order_statuses');
     if (is_array($orderStatuses)) {
         if (count($orderStatuses) == 1 && strpos($orderStatuses[0], ',') !== false) {
             $filterData->setData('order_statuses', explode(',', $orderStatuses[0]));
         }
     }
     $resourceCollection = $this->_resourceFactory->create($this->getResourceCollectionName())->setPeriod($filterData->getData('period_type'))->setDateRange($filterData->getData('from', null), $filterData->getData('to', null))->addStoreFilter($storeIds)->setAggregatedColumns($this->_getAggregatedColumns());
     $this->_addOrderStatusFilter($resourceCollection, $filterData);
     $this->_addCustomFilter($resourceCollection, $filterData);
     if ($this->_isExport) {
         $this->setCollection($resourceCollection);
         return $this;
     }
     if ($filterData->getData('show_empty_rows', false)) {
         $this->_reportsData->prepareIntervalsCollection($this->getCollection(), $filterData->getData('from', null), $filterData->getData('to', null), $filterData->getData('period_type'));
     }
     if ($this->getCountSubTotals()) {
         $this->getSubTotals();
     }
     if ($this->getCountTotals()) {
         $totalsCollection = $this->_resourceFactory->create($this->getResourceCollectionName())->setPeriod($filterData->getData('period_type'))->setDateRange($filterData->getData('from', null), $filterData->getData('to', null))->addStoreFilter($storeIds)->setAggregatedColumns($this->_getAggregatedColumns())->isTotals(true);
         $this->_addOrderStatusFilter($totalsCollection, $filterData);
         $this->_addCustomFilter($totalsCollection, $filterData);
         foreach ($totalsCollection as $item) {
             $this->setTotals($item);
             break;
         }
     }
     $this->getCollection()->setColumnGroupBy($this->_columnGroupBy);
     $this->getCollection()->setResourceCollection($resourceCollection);
     return parent::_prepareCollection();
 }