Skip to content

Commit

Permalink
Merge pull request #154 from magento-goinc/goinc_time_zone
Browse files Browse the repository at this point in the history
[GoInc+Nord] Fixing timezone bugs
  • Loading branch information
Melnikov, Igor(imelnikov) committed Nov 12, 2015
2 parents 2e8d1fa + 6f1f34d commit a724ee7
Show file tree
Hide file tree
Showing 16 changed files with 111 additions and 370 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,10 @@ protected function getTierPrices(array $listSku, $table)
if (isset($exportFilter) && !empty($exportFilter)) {
$date = $exportFilter[\Magento\Catalog\Model\Category::KEY_UPDATED_AT];
if (isset($date[0]) && !empty($date[0])) {
$updatedAtFrom = date('Y-m-d H:i:s', strtotime($date[0]));
$updatedAtFrom = $this->_localeDate->date($date[0], null, false)->format('Y-m-d H:i:s');
}
if (isset($date[1]) && !empty($date[1])) {
$updatedAtTo = date('Y-m-d H:i:s', strtotime($date[1]));
$updatedAtTo = $this->_localeDate->date($date[1], null, false)->format('Y-m-d H:i:s');
}
}
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ class AdvancedPricing extends \Magento\ImportExport\Model\Import\Entity\Abstract
protected $_catalogProductEntity;

/**
* @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface
* @var \Magento\Framework\Stdlib\DateTime\DateTime
*/
protected $_localeDate;
protected $dateTime;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
Expand All @@ -157,7 +157,7 @@ class AdvancedPricing extends \Magento\ImportExport\Model\Import\Entity\Abstract
* @param \Magento\ImportExport\Model\ResourceModel\Helper $resourceHelper
* @param \Magento\Framework\Stdlib\StringUtils $string
* @param ProcessingErrorAggregatorInterface $errorAggregator
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
* @param \Magento\Framework\Stdlib\DateTime\DateTime $dateTime
* @param \Magento\CatalogImportExport\Model\Import\Proxy\Product\ResourceModelFactory $resourceFactory
* @param \Magento\Catalog\Model\Product $productModel
* @param \Magento\Catalog\Helper\Data $catalogData
Expand All @@ -177,7 +177,7 @@ public function __construct(
\Magento\ImportExport\Model\ResourceModel\Helper $resourceHelper,
\Magento\Framework\Stdlib\StringUtils $string,
ProcessingErrorAggregatorInterface $errorAggregator,
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
\Magento\Framework\Stdlib\DateTime\DateTime $dateTime,
\Magento\CatalogImportExport\Model\Import\Proxy\Product\ResourceModelFactory $resourceFactory,
\Magento\Catalog\Model\Product $productModel,
\Magento\Catalog\Helper\Data $catalogData,
Expand All @@ -187,7 +187,7 @@ public function __construct(
AdvancedPricing\Validator\Website $websiteValidator,
AdvancedPricing\Validator\TierPrice $tierPriceValidator
) {
$this->_localeDate = $localeDate;
$this->dateTime = $dateTime;
$this->jsonHelper = $jsonHelper;
$this->_importExportData = $importExportData;
$this->_resourceHelper = $resourceHelper;
Expand Down Expand Up @@ -470,11 +470,11 @@ protected function deleteProductTierPrices(array $listSku, $tableName)
*/
protected function setUpdatedAt(array $listSku)
{
$updatedAt = $this->_localeDate->date(null, null, false)->format('Y-m-d H:i:s');
$updatedAt = $this->dateTime->gmtDate('Y-m-d H:i:s');
$this->_connection->update(
$this->_catalogProductEntity,
[\Magento\Catalog\Model\Category::KEY_UPDATED_AT => $updatedAt],
$this->_connection->quoteInto('sku IN (?)', $listSku)
$this->_connection->quoteInto('sku IN (?)', array_unique($listSku))
);
return $this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class AdvancedPricingTest extends \Magento\ImportExport\Test\Unit\Model\Import\A
/**
* @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $localeDate;
protected $dateTime;

/**
* @var \Magento\Framework\App\ResourceConnection|\PHPUnit_Framework_MockObject_MockObject
Expand Down Expand Up @@ -249,14 +249,14 @@ public function setUp()
false
);
$this->errorAggregator = $this->getErrorAggregatorObject();
$this->localeDate = $this->getMock(
'\Magento\Framework\Stdlib\DateTime\Timezone',
$this->dateTime = $this->getMock(
'\Magento\Framework\Stdlib\DateTime\DateTime',
['date', 'format'],
[],
'',
false
);
$this->localeDate->expects($this->any())->method('date')->willReturnSelf();
$this->dateTime->expects($this->any())->method('date')->willReturnSelf();

$this->advancedPricing = $this->getAdvancedPricingMock([
'retrieveOldSkus',
Expand Down Expand Up @@ -783,7 +783,7 @@ private function getAdvancedPricingMock($methods = [])
$this->resourceHelper,
$this->stringObject,
$this->errorAggregator,
$this->localeDate,
$this->dateTime,
$this->resourceFactory,
$this->productModel,
$this->catalogData,
Expand Down
16 changes: 12 additions & 4 deletions app/code/Magento/Catalog/Model/Product/Option/Type/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ public function validateUserValue($values)
}
} else {
$this->setUserValue(null);
return $this;
}

return $this;
Expand Down Expand Up @@ -191,19 +190,25 @@ public function getFormattedOptionValue($optionValue)
$result = $this->_localeDate->formatDateTime(
new \DateTime($optionValue),
\IntlDateFormatter::MEDIUM,
\IntlDateFormatter::NONE
\IntlDateFormatter::NONE,
null,
'UTC'
);
} elseif ($this->getOption()->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_DATE_TIME) {
$result = $this->_localeDate->formatDateTime(
new \DateTime($optionValue),
\IntlDateFormatter::SHORT,
\IntlDateFormatter::SHORT
\IntlDateFormatter::SHORT,
null,
'UTC'
);
} elseif ($this->getOption()->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_TIME) {
$result = $this->_localeDate->formatDateTime(
new \DateTime($optionValue),
\IntlDateFormatter::NONE,
\IntlDateFormatter::SHORT
\IntlDateFormatter::SHORT,
null,
'UTC'
);
} else {
$result = $optionValue;
Expand Down Expand Up @@ -338,6 +343,9 @@ protected function _setInternalInRequest($internalValue)
if (!isset($requestOptions[$this->getOption()->getId()])) {
$requestOptions[$this->getOption()->getId()] = [];
}
if (!is_array($requestOptions[$this->getOption()->getId()])) {
$requestOptions[$this->getOption()->getId()] = [];
}
$requestOptions[$this->getOption()->getId()]['date_internal'] = $internalValue;
$this->getRequest()->setOptions($requestOptions);
}
Expand Down
Loading

0 comments on commit a724ee7

Please sign in to comment.