Skip to content

Commit d587052

Browse files
committed
MC-40240: Product grid date filters does not work for en_GB locale
1 parent c9242e8 commit d587052

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

app/code/Magento/Ui/Component/Filters.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Ui\Component;
77

8+
use Magento\Framework\App\ObjectManager;
9+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
810
use Magento\Framework\View\Element\UiComponent\ContextInterface;
911
use Magento\Framework\View\Element\UiComponent\ObserverInterface;
1012
use Magento\Framework\View\Element\UiComponentFactory;
@@ -47,16 +49,42 @@ class Filters extends AbstractComponent implements ObserverInterface
4749
protected $uiComponentFactory;
4850

4951
/**
50-
* @inheritDoc
52+
* @var TimezoneInterface
53+
*/
54+
private $localeDate;
55+
56+
/**
57+
* Filters constructor.
58+
*
59+
* @param ContextInterface $context
60+
* @param UiComponentFactory $uiComponentFactory
61+
* @param array $components
62+
* @param array $data
63+
* @param TimezoneInterface|null $localeDate
5164
*/
5265
public function __construct(
5366
ContextInterface $context,
5467
UiComponentFactory $uiComponentFactory,
5568
array $components = [],
56-
array $data = []
69+
array $data = [],
70+
?TimezoneInterface $localeDate = null
5771
) {
5872
parent::__construct($context, $components, $data);
5973
$this->uiComponentFactory = $uiComponentFactory;
74+
$this->localeDate = $localeDate ?? ObjectManager::getInstance()->get(TimezoneInterface::class);
75+
}
76+
77+
/**
78+
* @inheritDoc
79+
*/
80+
public function prepare()
81+
{
82+
$config = $this->getData('config');
83+
// Set date format pattern by current locale
84+
$localeDateFormat = $this->localeDate->getDateFormat();
85+
$config['options']['dateFormat'] = $localeDateFormat;
86+
$this->setData('config', $config);
87+
parent::prepare();
6088
}
6189

6290
/**

app/code/Magento/Ui/view/base/web/js/grid/filters/filters.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ define([
124124
*
125125
* @returns {Filters} Chainable.
126126
*/
127-
initialize: function () {
127+
initialize: function (config) {
128+
if (typeof config.options !== 'undefined' && config.options.dateFormat) {
129+
this.constructor.defaults.templates.filters.dateRange.dateFormat = config.options.dateFormat;
130+
}
128131
_.bindAll(this, 'updateActive');
129132

130133
this._super()

app/code/Magento/Ui/view/base/web/js/grid/filters/range.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ define([
5959
*
6060
* @returns {Range} Chainable.
6161
*/
62-
initialize: function () {
62+
initialize: function (config) {
63+
if (config.dateFormat) {
64+
this.constructor.defaults.templates.date.pickerDefaultDateFormat = config.dateFormat;
65+
}
6366
this._super()
6467
.initChildren();
6568

0 commit comments

Comments
 (0)