Skip to content

Commit 20ffc77

Browse files
committed
ACP2E-56 : [On Prem] Magento invoice order date filter not working
1 parent 1ef4504 commit 20ffc77

File tree

6 files changed

+309
-53
lines changed

6 files changed

+309
-53
lines changed

app/code/Magento/Cms/Model/ResourceModel/Block/Grid/Collection.php

Lines changed: 64 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,48 +8,65 @@
88
use Magento\Framework\Api\Search\SearchResultInterface;
99
use Magento\Framework\Api\Search\AggregationInterface;
1010
use Magento\Cms\Model\ResourceModel\Block\Collection as BlockCollection;
11+
use Magento\Framework\App\ObjectManager;
12+
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface;
13+
use Magento\Framework\Data\Collection\EntityFactoryInterface;
14+
use Magento\Framework\DB\Adapter\AdapterInterface;
15+
use Magento\Framework\EntityManager\MetadataPool;
16+
use Magento\Framework\Event\ManagerInterface;
17+
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
18+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
19+
use Magento\Store\Model\StoreManagerInterface;
20+
use Psr\Log\LoggerInterface;
1121

1222
/**
1323
* Collection for displaying grid of cms blocks
1424
*/
1525
class Collection extends BlockCollection implements SearchResultInterface
1626
{
27+
/**
28+
* @var TimezoneInterface
29+
*/
30+
private $timeZone;
31+
1732
/**
1833
* @var AggregationInterface
1934
*/
2035
protected $aggregations;
2136

2237
/**
23-
* @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory
24-
* @param \Psr\Log\LoggerInterface $logger
25-
* @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
26-
* @param \Magento\Framework\Event\ManagerInterface $eventManager
27-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
28-
* @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
38+
* @param EntityFactoryInterface $entityFactory
39+
* @param LoggerInterface $logger
40+
* @param FetchStrategyInterface $fetchStrategy
41+
* @param ManagerInterface $eventManager
42+
* @param StoreManagerInterface $storeManager
43+
* @param MetadataPool $metadataPool
2944
* @param string $mainTable
3045
* @param string $eventPrefix
3146
* @param string $eventObject
3247
* @param string $resourceModel
3348
* @param string $model
34-
* @param \Magento\Framework\DB\Adapter\AdapterInterface|string|null $connection
35-
* @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource
49+
* @param AdapterInterface|string|null $connection
50+
* @param AbstractDb $resource
51+
* @param TimezoneInterface|null $timeZone
3652
*
3753
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
3854
*/
3955
public function __construct(
40-
\Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory,
41-
\Psr\Log\LoggerInterface $logger,
42-
\Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
43-
\Magento\Framework\Event\ManagerInterface $eventManager,
44-
\Magento\Store\Model\StoreManagerInterface $storeManager,
45-
\Magento\Framework\EntityManager\MetadataPool $metadataPool,
56+
EntityFactoryInterface $entityFactory,
57+
LoggerInterface $logger,
58+
FetchStrategyInterface $fetchStrategy,
59+
ManagerInterface $eventManager,
60+
StoreManagerInterface $storeManager,
61+
MetadataPool $metadataPool,
4662
$mainTable,
4763
$eventPrefix,
4864
$eventObject,
4965
$resourceModel,
5066
$model = \Magento\Framework\View\Element\UiComponent\DataProvider\Document::class,
5167
$connection = null,
52-
\Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null
68+
AbstractDb $resource = null,
69+
TimezoneInterface $timeZone = null
5370
) {
5471
parent::__construct(
5572
$entityFactory,
@@ -65,6 +82,38 @@ public function __construct(
6582
$this->_eventObject = $eventObject;
6683
$this->_init($model, $resourceModel);
6784
$this->setMainTable($mainTable);
85+
$this->timeZone = $timeZone ?: ObjectManager::getInstance()->get(TimezoneInterface::class);
86+
}
87+
88+
/**
89+
* @inheritdoc
90+
*/
91+
protected function _initSelect()
92+
{
93+
parent::_initSelect();
94+
95+
$tableDescription = $this->getConnection()->describeTable($this->getMainTable());
96+
foreach ($tableDescription as $columnInfo) {
97+
$this->addFilterToMap($columnInfo['COLUMN_NAME'], 'main_table.'.$columnInfo['COLUMN_NAME']);
98+
}
99+
100+
return $this;
101+
}
102+
103+
/**
104+
* @inheritDoc
105+
*/
106+
public function addFieldToFilter($field, $condition = null)
107+
{
108+
if ($field === 'creation_time' || $field === 'update_time') {
109+
if (is_array($condition)) {
110+
foreach ($condition as $key => $value) {
111+
$condition[$key] = $this->timeZone->convertConfigTimeToUtc($value);
112+
}
113+
}
114+
}
115+
116+
return parent::addFieldToFilter($field, $condition);
68117
}
69118

70119
/**

app/code/Magento/Cms/Model/ResourceModel/Page/Grid/Collection.php

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,65 @@
88
use Magento\Framework\Api\Search\SearchResultInterface;
99
use Magento\Framework\Api\Search\AggregationInterface;
1010
use Magento\Cms\Model\ResourceModel\Page\Collection as PageCollection;
11+
use Magento\Framework\App\ObjectManager;
12+
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface;
13+
use Magento\Framework\Data\Collection\EntityFactoryInterface;
14+
use Magento\Framework\EntityManager\MetadataPool;
15+
use Magento\Framework\Event\ManagerInterface;
16+
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
17+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
18+
use Magento\Store\Model\StoreManagerInterface;
19+
use Psr\Log\LoggerInterface;
1120

1221
/**
1322
* Class Collection
1423
* Collection for displaying grid of sales documents
1524
*/
1625
class Collection extends PageCollection implements SearchResultInterface
1726
{
27+
/**
28+
* @var TimezoneInterface
29+
*/
30+
private $timeZone;
31+
1832
/**
1933
* @var AggregationInterface
2034
*/
2135
protected $aggregations;
2236

2337
/**
24-
* @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory
25-
* @param \Psr\Log\LoggerInterface $logger
26-
* @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
27-
* @param \Magento\Framework\Event\ManagerInterface $eventManager
28-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
29-
* @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
38+
* @param EntityFactoryInterface $entityFactory
39+
* @param LoggerInterface $logger
40+
* @param FetchStrategyInterface $fetchStrategy
41+
* @param ManagerInterface $eventManager
42+
* @param StoreManagerInterface $storeManager
43+
* @param MetadataPool $metadataPool
3044
* @param mixed|null $mainTable
3145
* @param string $eventPrefix
3246
* @param mixed $eventObject
3347
* @param mixed $resourceModel
3448
* @param string $model
3549
* @param null $connection
36-
* @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb|null $resource
50+
* @param AbstractDb|null $resource,
51+
* @param TimezoneInterface|null $timeZone
3752
*
3853
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
3954
*/
4055
public function __construct(
41-
\Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory,
42-
\Psr\Log\LoggerInterface $logger,
43-
\Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
44-
\Magento\Framework\Event\ManagerInterface $eventManager,
45-
\Magento\Store\Model\StoreManagerInterface $storeManager,
46-
\Magento\Framework\EntityManager\MetadataPool $metadataPool,
56+
EntityFactoryInterface $entityFactory,
57+
LoggerInterface $logger,
58+
FetchStrategyInterface $fetchStrategy,
59+
ManagerInterface $eventManager,
60+
StoreManagerInterface $storeManager,
61+
MetadataPool $metadataPool,
4762
$mainTable,
4863
$eventPrefix,
4964
$eventObject,
5065
$resourceModel,
5166
$model = \Magento\Framework\View\Element\UiComponent\DataProvider\Document::class,
5267
$connection = null,
53-
\Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null
68+
AbstractDb $resource = null,
69+
TimezoneInterface $timeZone = null
5470
) {
5571
parent::__construct(
5672
$entityFactory,
@@ -66,6 +82,38 @@ public function __construct(
6682
$this->_eventObject = $eventObject;
6783
$this->_init($model, $resourceModel);
6884
$this->setMainTable($mainTable);
85+
$this->timeZone = $timeZone ?: ObjectManager::getInstance()->get(TimezoneInterface::class);
86+
}
87+
88+
/**
89+
* @inheritdoc
90+
*/
91+
protected function _initSelect()
92+
{
93+
parent::_initSelect();
94+
95+
$tableDescription = $this->getConnection()->describeTable($this->getMainTable());
96+
foreach ($tableDescription as $columnInfo) {
97+
$this->addFilterToMap($columnInfo['COLUMN_NAME'], 'main_table.'.$columnInfo['COLUMN_NAME']);
98+
}
99+
100+
return $this;
101+
}
102+
103+
/**
104+
* @inheritDoc
105+
*/
106+
public function addFieldToFilter($field, $condition = null)
107+
{
108+
if ($field === 'creation_time' || $field === 'update_time') {
109+
if (is_array($condition)) {
110+
foreach ($condition as $key => $value) {
111+
$condition[$key] = $this->timeZone->convertConfigTimeToUtc($value);
112+
}
113+
}
114+
}
115+
116+
return parent::addFieldToFilter($field, $condition);
69117
}
70118

71119
/**

app/code/Magento/Sales/Model/ResourceModel/Order/Creditmemo/Grid/Collection.php

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,74 @@
66

77
namespace Magento\Sales\Model\ResourceModel\Order\Creditmemo\Grid;
88

9+
use Magento\Framework\App\ObjectManager;
910
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface as FetchStrategy;
1011
use Magento\Framework\Data\Collection\EntityFactoryInterface as EntityFactory;
1112
use Magento\Framework\Event\ManagerInterface as EventManager;
13+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
14+
use Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult;
15+
use Magento\Sales\Model\ResourceModel\Order\Creditmemo;
1216
use Psr\Log\LoggerInterface as Logger;
1317

14-
class Collection extends \Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult
18+
class Collection extends SearchResult
1519
{
20+
/**
21+
* @var TimezoneInterface
22+
*/
23+
private $timeZone;
24+
1625
/**
1726
* Initialize dependencies.
1827
*
19-
* @param EntityFactory $entityFactory
20-
* @param Logger $logger
21-
* @param FetchStrategy $fetchStrategy
22-
* @param EventManager $eventManager
23-
* @param string $mainTable
24-
* @param string $resourceModel
28+
* @param EntityFactory $entityFactory
29+
* @param Logger $logger
30+
* @param FetchStrategy $fetchStrategy
31+
* @param EventManager $eventManager
32+
* @param string $mainTable
33+
* @param string $resourceModel
34+
* @param TimezoneInterface|null $timeZone
2535
*/
2636
public function __construct(
2737
EntityFactory $entityFactory,
2838
Logger $logger,
2939
FetchStrategy $fetchStrategy,
3040
EventManager $eventManager,
31-
$mainTable = 'sales_creditmemo_grid',
32-
$resourceModel = \Magento\Sales\Model\ResourceModel\Order\Creditmemo::class
41+
$mainTable='sales_creditmemo_grid',
42+
$resourceModel= Creditmemo::class,
43+
TimezoneInterface $timeZone = null
3344
) {
3445
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $mainTable, $resourceModel);
46+
$this->timeZone = $timeZone ?: ObjectManager::getInstance()->get(TimezoneInterface::class);
47+
}
48+
49+
/**
50+
* @inheritdoc
51+
*/
52+
protected function _initSelect()
53+
{
54+
parent::_initSelect();
55+
56+
$tableDescription = $this->getConnection()->describeTable($this->getMainTable());
57+
foreach ($tableDescription as $columnInfo) {
58+
$this->addFilterToMap($columnInfo['COLUMN_NAME'], 'main_table.'.$columnInfo['COLUMN_NAME']);
59+
}
60+
61+
return $this;
62+
}
63+
64+
/**
65+
* @inheritDoc
66+
*/
67+
public function addFieldToFilter($field, $condition = null)
68+
{
69+
if ($field === 'created_at' || $field === 'order_created_at') {
70+
if (is_array($condition)) {
71+
foreach ($condition as $key => $value) {
72+
$condition[$key] = $this->timeZone->convertConfigTimeToUtc($value);
73+
}
74+
}
75+
}
76+
77+
return parent::addFieldToFilter($field, $condition);
3578
}
3679
}

0 commit comments

Comments
 (0)