/** * @return void */ protected function _initCollection() { $isFilter = $this->getParam('store') || $this->getParam('website') || $this->getParam('group'); $this->_collection = $this->_orderCollection->prepareSummary($this->getParam('period'), 0, 0, $isFilter); if ($this->getParam('store')) { $this->_collection->addFieldToFilter('store_id', $this->getParam('store')); } elseif ($this->getParam('website')) { $storeIds = $this->_storeManager->getWebsite($this->getParam('website'))->getStoreIds(); $this->_collection->addFieldToFilter('store_id', ['in' => implode(',', $storeIds)]); } elseif ($this->getParam('group')) { $storeIds = $this->_storeManager->getGroup($this->getParam('group'))->getStoreIds(); $this->_collection->addFieldToFilter('store_id', ['in' => implode(',', $storeIds)]); } elseif (!$this->_collection->isLive()) { $this->_collection->addFieldToFilter('store_id', ['eq' => $this->_storeManager->getStore(\Magento\Store\Model\Store::ADMIN_CODE)->getId()]); } $this->_collection->load(); }
/** * @param int $useAggregatedData * @param string $mainTable * @param int $isFilter * @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $getIfNullSqlResult * @dataProvider useAggregatedDataDataProvider * @return void */ public function testPrepareSummary($useAggregatedData, $mainTable, $isFilter, $getIfNullSqlResult) { $range = ''; $customStart = 1; $customEnd = 10; $this->scopeConfigMock->expects($this->once())->method('getValue')->with('sales/dashboard/use_aggregated_data', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)->willReturn($useAggregatedData); $orderMock = $this->getMockBuilder('Magento\\Sales\\Model\\Resource\\Report\\Order')->disableOriginalConstructor()->getMock(); $this->orderFactoryMock->expects($this->any())->method('create')->willReturn($orderMock); $this->resourceMock->expects($this->at(0))->method('getTable')->with($mainTable); $this->dbMock->expects($getIfNullSqlResult)->method('getIfNullSql'); $this->collection->prepareSummary($range, $customStart, $customEnd, $isFilter); }