Skip to content

Commit 53856ce

Browse files
committed
ACP2E-56 : [On Prem] Magento invoice order date filter not working
1 parent d1ad997 commit 53856ce

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Sales\Model\ResourceModel\Order\Invoice\Grid;
7+
8+
use Magento\Framework\App\ObjectManager;
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\Stdlib\DateTime\TimezoneInterface;
13+
use Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult;
14+
use Magento\Sales\Model\ResourceModel\Order\Invoice;
15+
use Psr\Log\LoggerInterface as Logger;
16+
17+
/**
18+
* Order invoice grid collection
19+
*/
20+
class CollectionFilter extends SearchResult
21+
{
22+
/**
23+
* @var TimezoneInterface
24+
*/
25+
private $timeZone;
26+
27+
/**
28+
* Initialize dependencies.
29+
*
30+
* @param EntityFactory $entityFactory
31+
* @param Logger $logger
32+
* @param FetchStrategy $fetchStrategy
33+
* @param EventManager $eventManager
34+
* @param string $mainTable
35+
* @param string $resourceModel
36+
* @param TimezoneInterface|null $timeZone
37+
*/
38+
public function __construct(
39+
EntityFactory $entityFactory,
40+
Logger $logger,
41+
FetchStrategy $fetchStrategy,
42+
EventManager $eventManager,
43+
$mainTable = 'sales_invoice_grid',
44+
$resourceModel = Invoice::class,
45+
TimezoneInterface $timeZone = null
46+
) {
47+
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $mainTable, $resourceModel);
48+
$this->timeZone = $timeZone ?: ObjectManager::getInstance()->get(TimezoneInterface::class);
49+
}
50+
51+
/**
52+
* @inheritdoc
53+
*/
54+
protected function _initSelect()
55+
{
56+
parent::_initSelect();
57+
58+
$tableDescription = $this->getConnection()->describeTable($this->getMainTable());
59+
foreach ($tableDescription as $columnInfo) {
60+
$this->addFilterToMap($columnInfo['COLUMN_NAME'], 'main_table.'.$columnInfo['COLUMN_NAME']);
61+
}
62+
63+
return $this;
64+
}
65+
66+
/**
67+
* @inheritDoc
68+
*/
69+
public function addFieldToFilter($field, $condition = null)
70+
{
71+
if ($field === 'created_at' || $field === 'order_created_at') {
72+
if (is_array($condition)) {
73+
foreach ($condition as $key => $value) {
74+
$condition[$key] = $this->timeZone->convertConfigTimeToUtc($value);
75+
}
76+
}
77+
}
78+
79+
return parent::addFieldToFilter($field, $condition);
80+
}
81+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
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"/>
122123
<type name="Magento\Sales\Model\ResourceModel\Provider\NotSyncedDataProvider">
123124
<arguments>
124125
<argument name="providers" xsi:type="array">
@@ -839,7 +840,7 @@
839840
</argument>
840841
</arguments>
841842
</type>
842-
<virtualType name="Magento\Sales\Model\ResourceModel\Order\Invoice\Grid\Collection" type="Magento\Sales\Model\ResourceModel\Order\CollectionFilter">
843+
<virtualType name="Magento\Sales\Model\ResourceModel\Order\Invoice\Grid\Collection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
843844
<arguments>
844845
<argument name="mainTable" xsi:type="string">sales_invoice_grid</argument>
845846
<argument name="resourceModel" xsi:type="string">Magento\Sales\Model\ResourceModel\Order\Invoice</argument>

0 commit comments

Comments
 (0)