Skip to content

Commit 032f409

Browse files
committed
ACP2E-56 : [On Prem] Magento invoice order date filter not working
1 parent e352aea commit 032f409

File tree

9 files changed

+170
-396
lines changed

9 files changed

+170
-396
lines changed

app/code/Magento/Sales/Model/ResourceModel/Order/CollectionFilter.php

Lines changed: 0 additions & 80 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Sales\Model\ResourceModel\Order\Creditmemo\Grid;
8+
9+
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface as FetchStrategy;
10+
use Magento\Framework\Data\Collection\EntityFactoryInterface as EntityFactory;
11+
use Magento\Framework\Event\ManagerInterface as EventManager;
12+
use Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult;
13+
use Magento\Sales\Model\ResourceModel\Order\Creditmemo;
14+
use Psr\Log\LoggerInterface as Logger;
15+
16+
class Collection extends SearchResult
17+
{
18+
/**
19+
* Initialize dependencies.
20+
*
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+
*/
29+
public function __construct(
30+
EntityFactory $entityFactory,
31+
Logger $logger,
32+
FetchStrategy $fetchStrategy,
33+
EventManager $eventManager,
34+
$mainTable = 'sales_creditmemo_grid',
35+
$resourceModel = Creditmemo::class
36+
) {
37+
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $mainTable, $resourceModel);
38+
}
39+
}

app/code/Magento/Sales/Model/ResourceModel/Order/Invoice/Grid/CollectionFilter.php

Lines changed: 0 additions & 84 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Sales\Model\ResourceModel\Order\Shipment\Grid;
8+
9+
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface as FetchStrategy;
10+
use Magento\Framework\Data\Collection\EntityFactoryInterface as EntityFactory;
11+
use Magento\Framework\Event\ManagerInterface as EventManager;
12+
use Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult;
13+
use Magento\Sales\Model\ResourceModel\Order\Shipment;
14+
use Psr\Log\LoggerInterface as Logger;
15+
16+
class Collection extends SearchResult
17+
{
18+
/**
19+
* Initialize dependencies.
20+
*
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+
*/
29+
public function __construct(
30+
EntityFactory $entityFactory,
31+
Logger $logger,
32+
FetchStrategy $fetchStrategy,
33+
EventManager $eventManager,
34+
$mainTable = 'sales_shipment_grid',
35+
$resourceModel = Shipment::class
36+
) {
37+
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $mainTable, $resourceModel);
38+
}
39+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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+
* @param TimezoneInterface $timeZone
22+
*/
23+
public function __construct(
24+
TimezoneInterface $timeZone
25+
) {
26+
$this->timeZone = $timeZone;
27+
}
28+
29+
private function _initSelect(SearchResult $subject)
30+
{
31+
$tableDescription = $subject->getConnection()->describeTable($subject->getMainTable());
32+
if ($tableDescription) {
33+
foreach ($tableDescription as $columnInfo) {
34+
$subject->addFilterToMap($columnInfo['COLUMN_NAME'], 'main_table.' . $columnInfo['COLUMN_NAME']);
35+
}
36+
}
37+
38+
return $subject;
39+
}
40+
41+
/**
42+
* @param SearchResult $subject
43+
* @param \Closure $proceed
44+
* @param string $field
45+
* @param string|null $condition
46+
* @return SearchResult|mixed
47+
* @throws \Magento\Framework\Exception\LocalizedException
48+
*/
49+
public function aroundAddFieldToFilter(
50+
SearchResult $subject,
51+
\Closure $proceed,
52+
$field,
53+
$condition = null
54+
) {
55+
$this->_initSelect($subject);
56+
$fieldMap = $this->getFilterFieldsMap();
57+
$fieldName = $fieldMap['fields'][$field] ?? null;
58+
if (!$fieldName) {
59+
return $proceed($field, $condition);
60+
}
61+
62+
if ($field === 'created_at' || $field === 'order_created_at') {
63+
if (is_array($condition)) {
64+
foreach ($condition as $key => $value) {
65+
$condition[$key] = $this->timeZone->convertConfigTimeToUtc($value);
66+
}
67+
}
68+
}
69+
70+
$fieldName = $subject->getConnection()->quoteIdentifier($fieldName);
71+
$condition = $subject->getConnection()->prepareSqlCondition($fieldName, $condition);
72+
$subject->getSelect()->where($condition, null, Select::TYPE_CONDITION);
73+
74+
return $subject;
75+
}
76+
77+
/**
78+
* @return \string[][]
79+
*/
80+
private function getFilterFieldsMap(): array
81+
{
82+
return [
83+
'fields' => [
84+
'created_at' => 'main_table.created_at',
85+
'order_created_at' => 'main_table.order_created_at',
86+
],
87+
];
88+
}
89+
}

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>

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@
119119
<preference for="Magento\Sales\Model\ConfigInterface" type="Magento\Sales\Model\Config" />
120120
<preference for="Magento\Sales\Model\Order\Shipment\ShipmentItemsValidatorInterface" type="Magento\Sales\Model\Order\Shipment\ShipmentItemsValidator" />
121121
<preference for="Magento\Sales\Model\OrderMutexInterface" type="Magento\Sales\Model\OrderMutex"/>
122-
<preference for="Magento\Sales\Model\ResourceModel\Order\Invoice\Grid\Collection" type="Magento\Sales\Model\ResourceModel\Order\Invoice\Grid\CollectionFilter"/>
123122
<type name="Magento\Sales\Model\ResourceModel\Provider\NotSyncedDataProvider">
124123
<arguments>
125124
<argument name="providers" xsi:type="array">
@@ -846,18 +845,6 @@
846845
<argument name="resourceModel" xsi:type="string">Magento\Sales\Model\ResourceModel\Order\Invoice</argument>
847846
</arguments>
848847
</virtualType>
849-
<virtualType name="Magento\Sales\Model\ResourceModel\Order\Shipment\Grid\Collection" type="Magento\Sales\Model\ResourceModel\Order\CollectionFilter">
850-
<arguments>
851-
<argument name="mainTable" xsi:type="string">sales_shipment_grid</argument>
852-
<argument name="resourceModel" xsi:type="string">Magento\Sales\Model\ResourceModel\Order\Shipment</argument>
853-
</arguments>
854-
</virtualType>
855-
<virtualType name="Magento\Sales\Model\ResourceModel\Order\Creditmemo\Grid\Collection" type="Magento\Sales\Model\ResourceModel\Order\CollectionFilter">
856-
<arguments>
857-
<argument name="mainTable" xsi:type="string">sales_creditmemo_grid</argument>
858-
<argument name="resourceModel" xsi:type="string">Magento\Sales\Model\ResourceModel\Order\Creditmemo</argument>
859-
</arguments>
860-
</virtualType>
861848
<type name="Magento\Sales\Model\Order\Config">
862849
<arguments>
863850
<argument name="state" xsi:type="object">Magento\Framework\App\State\Proxy</argument>

0 commit comments

Comments
 (0)