|
| 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 | +} |
0 commit comments