Skip to content

Commit a724ee7

Browse files
author
Melnikov, Igor(imelnikov)
committed
Merge pull request #154 from magento-goinc/goinc_time_zone
[GoInc+Nord] Fixing timezone bugs
2 parents 2e8d1fa + 6f1f34d commit a724ee7

File tree

16 files changed

+111
-370
lines changed

16 files changed

+111
-370
lines changed

app/code/Magento/AdvancedPricingImportExport/Model/Export/AdvancedPricing.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,10 @@ protected function getTierPrices(array $listSku, $table)
345345
if (isset($exportFilter) && !empty($exportFilter)) {
346346
$date = $exportFilter[\Magento\Catalog\Model\Category::KEY_UPDATED_AT];
347347
if (isset($date[0]) && !empty($date[0])) {
348-
$updatedAtFrom = date('Y-m-d H:i:s', strtotime($date[0]));
348+
$updatedAtFrom = $this->_localeDate->date($date[0], null, false)->format('Y-m-d H:i:s');
349349
}
350350
if (isset($date[1]) && !empty($date[1])) {
351-
$updatedAtTo = date('Y-m-d H:i:s', strtotime($date[1]));
351+
$updatedAtTo = $this->_localeDate->date($date[1], null, false)->format('Y-m-d H:i:s');
352352
}
353353
}
354354
try {

app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ class AdvancedPricing extends \Magento\ImportExport\Model\Import\Entity\Abstract
143143
protected $_catalogProductEntity;
144144

145145
/**
146-
* @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface
146+
* @var \Magento\Framework\Stdlib\DateTime\DateTime
147147
*/
148-
protected $_localeDate;
148+
protected $dateTime;
149149

150150
/**
151151
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -157,7 +157,7 @@ class AdvancedPricing extends \Magento\ImportExport\Model\Import\Entity\Abstract
157157
* @param \Magento\ImportExport\Model\ResourceModel\Helper $resourceHelper
158158
* @param \Magento\Framework\Stdlib\StringUtils $string
159159
* @param ProcessingErrorAggregatorInterface $errorAggregator
160-
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
160+
* @param \Magento\Framework\Stdlib\DateTime\DateTime $dateTime
161161
* @param \Magento\CatalogImportExport\Model\Import\Proxy\Product\ResourceModelFactory $resourceFactory
162162
* @param \Magento\Catalog\Model\Product $productModel
163163
* @param \Magento\Catalog\Helper\Data $catalogData
@@ -177,7 +177,7 @@ public function __construct(
177177
\Magento\ImportExport\Model\ResourceModel\Helper $resourceHelper,
178178
\Magento\Framework\Stdlib\StringUtils $string,
179179
ProcessingErrorAggregatorInterface $errorAggregator,
180-
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
180+
\Magento\Framework\Stdlib\DateTime\DateTime $dateTime,
181181
\Magento\CatalogImportExport\Model\Import\Proxy\Product\ResourceModelFactory $resourceFactory,
182182
\Magento\Catalog\Model\Product $productModel,
183183
\Magento\Catalog\Helper\Data $catalogData,
@@ -187,7 +187,7 @@ public function __construct(
187187
AdvancedPricing\Validator\Website $websiteValidator,
188188
AdvancedPricing\Validator\TierPrice $tierPriceValidator
189189
) {
190-
$this->_localeDate = $localeDate;
190+
$this->dateTime = $dateTime;
191191
$this->jsonHelper = $jsonHelper;
192192
$this->_importExportData = $importExportData;
193193
$this->_resourceHelper = $resourceHelper;
@@ -470,11 +470,11 @@ protected function deleteProductTierPrices(array $listSku, $tableName)
470470
*/
471471
protected function setUpdatedAt(array $listSku)
472472
{
473-
$updatedAt = $this->_localeDate->date(null, null, false)->format('Y-m-d H:i:s');
473+
$updatedAt = $this->dateTime->gmtDate('Y-m-d H:i:s');
474474
$this->_connection->update(
475475
$this->_catalogProductEntity,
476476
[\Magento\Catalog\Model\Category::KEY_UPDATED_AT => $updatedAt],
477-
$this->_connection->quoteInto('sku IN (?)', $listSku)
477+
$this->_connection->quoteInto('sku IN (?)', array_unique($listSku))
478478
);
479479
return $this;
480480
}

app/code/Magento/AdvancedPricingImportExport/Test/Unit/Model/Import/AdvancedPricingTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class AdvancedPricingTest extends \Magento\ImportExport\Test\Unit\Model\Import\A
7979
/**
8080
* @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject
8181
*/
82-
protected $localeDate;
82+
protected $dateTime;
8383

8484
/**
8585
* @var \Magento\Framework\App\ResourceConnection|\PHPUnit_Framework_MockObject_MockObject
@@ -249,14 +249,14 @@ public function setUp()
249249
false
250250
);
251251
$this->errorAggregator = $this->getErrorAggregatorObject();
252-
$this->localeDate = $this->getMock(
253-
'\Magento\Framework\Stdlib\DateTime\Timezone',
252+
$this->dateTime = $this->getMock(
253+
'\Magento\Framework\Stdlib\DateTime\DateTime',
254254
['date', 'format'],
255255
[],
256256
'',
257257
false
258258
);
259-
$this->localeDate->expects($this->any())->method('date')->willReturnSelf();
259+
$this->dateTime->expects($this->any())->method('date')->willReturnSelf();
260260

261261
$this->advancedPricing = $this->getAdvancedPricingMock([
262262
'retrieveOldSkus',
@@ -783,7 +783,7 @@ private function getAdvancedPricingMock($methods = [])
783783
$this->resourceHelper,
784784
$this->stringObject,
785785
$this->errorAggregator,
786-
$this->localeDate,
786+
$this->dateTime,
787787
$this->resourceFactory,
788788
$this->productModel,
789789
$this->catalogData,

app/code/Magento/Catalog/Model/Product/Option/Type/Date.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ public function validateUserValue($values)
114114
}
115115
} else {
116116
$this->setUserValue(null);
117-
return $this;
118117
}
119118

120119
return $this;
@@ -191,19 +190,25 @@ public function getFormattedOptionValue($optionValue)
191190
$result = $this->_localeDate->formatDateTime(
192191
new \DateTime($optionValue),
193192
\IntlDateFormatter::MEDIUM,
194-
\IntlDateFormatter::NONE
193+
\IntlDateFormatter::NONE,
194+
null,
195+
'UTC'
195196
);
196197
} elseif ($this->getOption()->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_DATE_TIME) {
197198
$result = $this->_localeDate->formatDateTime(
198199
new \DateTime($optionValue),
199200
\IntlDateFormatter::SHORT,
200-
\IntlDateFormatter::SHORT
201+
\IntlDateFormatter::SHORT,
202+
null,
203+
'UTC'
201204
);
202205
} elseif ($this->getOption()->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_TIME) {
203206
$result = $this->_localeDate->formatDateTime(
204207
new \DateTime($optionValue),
205208
\IntlDateFormatter::NONE,
206-
\IntlDateFormatter::SHORT
209+
\IntlDateFormatter::SHORT,
210+
null,
211+
'UTC'
207212
);
208213
} else {
209214
$result = $optionValue;
@@ -338,6 +343,9 @@ protected function _setInternalInRequest($internalValue)
338343
if (!isset($requestOptions[$this->getOption()->getId()])) {
339344
$requestOptions[$this->getOption()->getId()] = [];
340345
}
346+
if (!is_array($requestOptions[$this->getOption()->getId()])) {
347+
$requestOptions[$this->getOption()->getId()] = [];
348+
}
341349
$requestOptions[$this->getOption()->getId()]['date_internal'] = $internalValue;
342350
$this->getRequest()->setOptions($requestOptions);
343351
}

0 commit comments

Comments
 (0)