12 class AbstractGrid extends \Magento\Backend\Block\Widget\Grid\Extended
65 \
Magento\Backend\Helper\Data $backendHelper,
67 \
Magento\Reports\Model\Grouped\CollectionFactory $collectionFactory,
68 \
Magento\Reports\Helper\Data $reportsData,
71 $this->_resourceFactory = $resourceFactory;
72 $this->_collectionFactory = $collectionFactory;
73 $this->_reportsData = $reportsData;
74 parent::__construct($context, $backendHelper,
$data);
87 $this->setUseAjax(
false);
88 if (isset($this->_columnGroupBy)) {
125 if ($this->_aggregatedColumns ===
null) {
127 if (!is_array($this->_aggregatedColumns)) {
128 $this->_aggregatedColumns = [];
130 if ($column->hasTotal()) {
131 $this->_aggregatedColumns[$column->getId()] =
"{$column->getTotal()}({$column->getIndex()})";
150 if (is_array($column) && array_key_exists(
'visibility_filter', $column)) {
151 $filterData = $this->getFilterData();
152 $visibilityFilter = $column[
'visibility_filter'];
153 if (!is_array($visibilityFilter)) {
154 $visibilityFilter = [$visibilityFilter];
156 foreach ($visibilityFilter as $k => $v) {
159 $filterFieldValue =
true;
162 $filterFieldValue = $v;
164 if (!$filterData->hasData($filterFieldId) || $filterData->getData($filterFieldId) != $filterFieldValue
170 return parent::addColumn($columnId, $column);
180 $storeIds = $this->getFilteredStores();
182 $allowedStoreIds = array_keys($this->_storeManager->getStores());
184 $storeIds = array_intersect($allowedStoreIds, $storeIds);
186 if (empty($storeIds)) {
187 $storeIds = $allowedStoreIds;
190 $storeIds = array_values($storeIds);
204 $filterData = $this->getFilterData();
206 if ($filterData->getData(
'from') ==
null || $filterData->getData(
'to') ==
null) {
209 return parent::_prepareCollection();
214 $orderStatuses = $filterData->getData(
'order_statuses');
215 if (is_array($orderStatuses)) {
216 if (count($orderStatuses) == 1 && strpos($orderStatuses[0],
',') !==
false) {
217 $filterData->setData(
'order_statuses', explode(
',', $orderStatuses[0]));
221 $resourceCollection = $this->_resourceFactory->create(
224 $filterData->getData(
'period_type')
226 $filterData->getData(
'from',
null),
227 $filterData->getData(
'to',
null)
230 )->setAggregatedColumns(
237 if ($this->_isExport) {
242 if ($filterData->getData(
'show_empty_rows',
false)) {
243 $this->_reportsData->prepareIntervalsCollection(
245 $filterData->getData(
'from',
null),
246 $filterData->getData(
'to',
null),
247 $filterData->getData(
'period_type')
256 $totalsCollection = $this->_resourceFactory->create(
259 $filterData->getData(
'period_type')
261 $filterData->getData(
'from',
null),
262 $filterData->getData(
'to',
null)
265 )->setAggregatedColumns(
274 foreach ($totalsCollection as
$item) {
280 $this->
getCollection()->setColumnGroupBy($this->_columnGroupBy);
281 $this->
getCollection()->setResourceCollection($resourceCollection);
283 return parent::_prepareCollection();
294 $filterData = $this->getFilterData();
295 $totalsCollection = $this->_resourceFactory->create(
298 $filterData->getData(
'period_type')
300 $filterData->getData(
'from',
null),
301 $filterData->getData(
'to',
null)
304 )->setAggregatedColumns(
313 if ($totalsCollection->load()->getSize() < 1 || !$filterData->getData(
'from')) {
317 foreach ($totalsCollection->getItems() as
$item) {
324 return parent::getCountTotals();
334 $filterData = $this->getFilterData();
335 $subTotalsCollection = $this->_resourceFactory->create(
338 $filterData->getData(
'period_type')
340 $filterData->getData(
'from',
null),
341 $filterData->getData(
'to',
null)
344 )->setAggregatedColumns(
354 return parent::getSubTotals();
366 $this->_storeIds = $storeIds;
377 if ($this->_currentCurrencyCode ===
null) {
378 $this->_currentCurrencyCode = count($this->_storeIds) > 0
379 ? $this->_storeManager->getStore(array_shift($this->_storeIds))->getCurrentCurrencyCode()
380 : $this->_storeManager->getStore()->getBaseCurrencyCode();
394 return $this->_storeManager->getStore()->getBaseCurrency()->getRate($toCurrency);
406 $collection->addOrderStatusFilter($filterData->getData(
'order_statuses'));
432 private function getFilteredStores(): array
436 $filterData = $this->getFilterData();
438 if ($filterData->getWebsite()) {
439 $storeIds = array_keys(
440 $this->_storeManager->getWebsite($filterData->getWebsite())->getStores()
444 if ($filterData->getGroup()) {
445 $storeIds = array_keys(
446 $this->_storeManager->getGroup($filterData->getGroup())->getStores()
450 if ($filterData->getData(
'store_ids')) {
451 $storeIds = explode(
',', $filterData->getData(
'store_ids'));
454 return is_array($storeIds) ? $storeIds : [];
_addCustomFilter($collection, $filterData)
addColumn($columnId, $column)
_addOrderStatusFilter($collection, $filterData)
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Backend\Helper\Data $backendHelper, \Magento\Reports\Model\ResourceModel\Report\Collection\Factory $resourceFactory, \Magento\Reports\Model\Grouped\CollectionFactory $collectionFactory, \Magento\Reports\Helper\Data $reportsData, array $data=[])
getResourceCollectionName()