Skip to content

Commit 5c36fff

Browse files
committed
Merge branch 'ACP2E-56' of https://github.com/magento-l3/magento2ce into PR-2021-12-21
2 parents 22a4d00 + 39121b0 commit 5c36fff

File tree

9 files changed

+470
-40
lines changed

9 files changed

+470
-40
lines changed

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

Lines changed: 53 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,9 +82,28 @@ 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);
6886
}
6987

7088
/**
89+
* @inheritDoc
90+
*/
91+
public function addFieldToFilter($field, $condition = null)
92+
{
93+
if ($field === 'creation_time' || $field === 'update_time') {
94+
if (is_array($condition)) {
95+
foreach ($condition as $key => $value) {
96+
$condition[$key] = $this->timeZone->convertConfigTimeToUtc($value);
97+
}
98+
}
99+
}
100+
101+
return parent::addFieldToFilter($field, $condition);
102+
}
103+
104+
/**
105+
* Get aggregation interface instance
106+
*
71107
* @return AggregationInterface
72108
*/
73109
public function getAggregations()
@@ -76,6 +112,8 @@ public function getAggregations()
76112
}
77113

78114
/**
115+
* Set aggregation interface instance
116+
*
79117
* @param AggregationInterface $aggregations
80118
* @return $this
81119
*/

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

Lines changed: 52 additions & 15 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
35-
* @param null $connection
36-
* @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb|null $resource
49+
* @param mixed|null $connection
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,9 +82,28 @@ 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);
6986
}
7087

7188
/**
89+
* @inheritDoc
90+
*/
91+
public function addFieldToFilter($field, $condition = null)
92+
{
93+
if ($field === 'creation_time' || $field === 'update_time') {
94+
if (is_array($condition)) {
95+
foreach ($condition as $key => $value) {
96+
$condition[$key] = $this->timeZone->convertConfigTimeToUtc($value);
97+
}
98+
}
99+
}
100+
101+
return parent::addFieldToFilter($field, $condition);
102+
}
103+
104+
/**
105+
* Get aggregation interface instance
106+
*
72107
* @return AggregationInterface
73108
*/
74109
public function getAggregations()
@@ -77,6 +112,8 @@ public function getAggregations()
77112
}
78113

79114
/**
115+
* Set aggregation interface instance
116+
*
80117
* @param AggregationInterface $aggregations
81118
* @return $this
82119
*/

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface as FetchStrategy;
1010
use Magento\Framework\Data\Collection\EntityFactoryInterface as EntityFactory;
1111
use Magento\Framework\Event\ManagerInterface as EventManager;
12+
use Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult;
13+
use Magento\Sales\Model\ResourceModel\Order\Creditmemo;
1214
use Psr\Log\LoggerInterface as Logger;
1315

14-
class Collection extends \Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult
16+
class Collection extends SearchResult
1517
{
1618
/**
1719
* Initialize dependencies.
@@ -22,14 +24,16 @@ class Collection extends \Magento\Framework\View\Element\UiComponent\DataProvide
2224
* @param EventManager $eventManager
2325
* @param string $mainTable
2426
* @param string $resourceModel
27+
* @throws \Magento\Framework\Exception\LocalizedException
28+
* phpcs:disable Generic.CodeAnalysis.UselessOverridingMethod.Found
2529
*/
2630
public function __construct(
2731
EntityFactory $entityFactory,
2832
Logger $logger,
2933
FetchStrategy $fetchStrategy,
3034
EventManager $eventManager,
3135
$mainTable = 'sales_creditmemo_grid',
32-
$resourceModel = \Magento\Sales\Model\ResourceModel\Order\Creditmemo::class
36+
$resourceModel = Creditmemo::class
3337
) {
3438
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $mainTable, $resourceModel);
3539
}

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,31 @@
99
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface as FetchStrategy;
1010
use Magento\Framework\Data\Collection\EntityFactoryInterface as EntityFactory;
1111
use Magento\Framework\Event\ManagerInterface as EventManager;
12+
use Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult;
13+
use Magento\Sales\Model\ResourceModel\Order\Shipment;
1214
use Psr\Log\LoggerInterface as Logger;
1315

14-
class Collection extends \Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult
16+
class Collection extends SearchResult
1517
{
1618
/**
1719
* Initialize dependencies.
1820
*
19-
* @param EntityFactory $entityFactory
20-
* @param Logger $logger
21-
* @param FetchStrategy $fetchStrategy
22-
* @param EventManager $eventManager
23-
* @param string $mainTable
24-
* @param string $resourceModel
21+
* @param EntityFactory $entityFactory
22+
* @param Logger $logger
23+
* @param FetchStrategy $fetchStrategy
24+
* @param EventManager $eventManager
25+
* @param string $mainTable
26+
* @param string $resourceModel
27+
* @throws \Magento\Framework\Exception\LocalizedException
28+
* phpcs:disable Generic.CodeAnalysis.UselessOverridingMethod.Found
2529
*/
2630
public function __construct(
2731
EntityFactory $entityFactory,
2832
Logger $logger,
2933
FetchStrategy $fetchStrategy,
3034
EventManager $eventManager,
3135
$mainTable = 'sales_shipment_grid',
32-
$resourceModel = \Magento\Sales\Model\ResourceModel\Order\Shipment::class
36+
$resourceModel = Shipment::class
3337
) {
3438
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $mainTable, $resourceModel);
3539
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Sales\Plugin\Model\ResourceModel\Order;
8+
9+
use Magento\Framework\DB\Select;
10+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
11+
use Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult;
12+
13+
class OrderGridCollectionFilter
14+
{
15+
/**
16+
* @var TimezoneInterface
17+
*/
18+
private TimezoneInterface $timeZone;
19+
20+
/**
21+
* Timezone converter interface
22+
*
23+
* @param TimezoneInterface $timeZone
24+
*/
25+
public function __construct(
26+
TimezoneInterface $timeZone
27+
) {
28+
$this->timeZone = $timeZone;
29+
}
30+
31+
/**
32+
* Conditional column filters with timezone convertor interface
33+
*
34+
* @param SearchResult $subject
35+
* @param \Closure $proceed
36+
* @param string $field
37+
* @param string|null $condition
38+
* @return SearchResult|mixed
39+
* @throws \Magento\Framework\Exception\LocalizedException
40+
*/
41+
public function aroundAddFieldToFilter(
42+
SearchResult $subject,
43+
\Closure $proceed,
44+
$field,
45+
$condition = null
46+
) {
47+
48+
if ($field === 'created_at' || $field === 'order_created_at') {
49+
if (is_array($condition)) {
50+
foreach ($condition as $key => $value) {
51+
$condition[$key] = $this->timeZone->convertConfigTimeToUtc($value);
52+
}
53+
}
54+
55+
$fieldName = $subject->getConnection()->quoteIdentifier($field);
56+
$condition = $subject->getConnection()->prepareSqlCondition($fieldName, $condition);
57+
$subject->getSelect()->where($condition, null, Select::TYPE_CONDITION);
58+
59+
return $subject;
60+
}
61+
62+
return $proceed($field, $condition);
63+
}
64+
}

app/code/Magento/Sales/etc/adminhtml/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,7 @@
4848
</argument>
4949
</arguments>
5050
</type>
51+
<type name="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
52+
<plugin name="orderGridCollectionFilterPlugin" type="Magento\Sales\Plugin\Model\ResourceModel\Order\OrderGridCollectionFilter"/>
53+
</type>
5154
</config>

0 commit comments

Comments
 (0)