5
5
*/
6
6
namespace Magento \Sales \Model \ResourceModel \Order \Grid ;
7
7
8
+ use Magento \Framework \App \ObjectManager ;
8
9
use Magento \Framework \Data \Collection \Db \FetchStrategyInterface as FetchStrategy ;
9
10
use Magento \Framework \Data \Collection \EntityFactoryInterface as EntityFactory ;
10
11
use Magento \Framework \Event \ManagerInterface as EventManager ;
12
+ use Magento \Framework \Stdlib \DateTime \TimezoneInterface ;
13
+ use Magento \Framework \View \Element \UiComponent \DataProvider \SearchResult ;
14
+ use Magento \Sales \Model \ResourceModel \Order ;
11
15
use Psr \Log \LoggerInterface as Logger ;
12
16
13
17
/**
14
18
* Order grid collection
15
19
*/
16
- class Collection extends \ Magento \ Framework \ View \ Element \ UiComponent \ DataProvider \ SearchResult
20
+ class Collection extends SearchResult
17
21
{
22
+ /**
23
+ * @var TimezoneInterface
24
+ */
25
+ private $ timeZone ;
26
+
18
27
/**
19
28
* Initialize dependencies.
20
29
*
@@ -24,16 +33,20 @@ class Collection extends \Magento\Framework\View\Element\UiComponent\DataProvide
24
33
* @param EventManager $eventManager
25
34
* @param string $mainTable
26
35
* @param string $resourceModel
36
+ * @param TimezoneInterface|null $timeZone
27
37
*/
28
38
public function __construct (
29
39
EntityFactory $ entityFactory ,
30
40
Logger $ logger ,
31
41
FetchStrategy $ fetchStrategy ,
32
42
EventManager $ eventManager ,
33
43
$ mainTable = 'sales_order_grid ' ,
34
- $ resourceModel = \Magento \Sales \Model \ResourceModel \Order::class
44
+ $ resourceModel = Order::class,
45
+ TimezoneInterface $ timeZone = null
35
46
) {
36
47
parent ::__construct ($ entityFactory , $ logger , $ fetchStrategy , $ eventManager , $ mainTable , $ resourceModel );
48
+ $ this ->timeZone = $ timeZone ?: ObjectManager::getInstance ()
49
+ ->get (TimezoneInterface::class);
37
50
}
38
51
39
52
/**
@@ -50,4 +63,20 @@ protected function _initSelect()
50
63
51
64
return $ this ;
52
65
}
66
+
67
+ /**
68
+ * @inheritDoc
69
+ */
70
+ public function addFieldToFilter ($ field , $ condition = null )
71
+ {
72
+ if ($ field === 'created_at ' ) {
73
+ if (is_array ($ condition )) {
74
+ foreach ($ condition as $ key => $ value ) {
75
+ $ condition [$ key ] = $ this ->timeZone ->convertConfigTimeToUtc ($ value );
76
+ }
77
+ }
78
+ }
79
+
80
+ return parent ::addFieldToFilter ($ field , $ condition );
81
+ }
53
82
}
0 commit comments