Skip to content

Commit

Permalink
Merge pull request #164 from magento-mpi/develop
Browse files Browse the repository at this point in the history
[MPI] - bug fix
  • Loading branch information
vpelipenko committed Mar 18, 2015
2 parents 8dd4940 + 78bef61 commit b456cd1
Show file tree
Hide file tree
Showing 35 changed files with 276 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ protected function _convertDate($date)
\IntlDateFormatter::NONE,
$adminTimeZone
);
$simpleRes = new \DateTime('@' . $formatter->parse($date), $adminTimeZone);
$simpleRes = new \DateTime(null, $adminTimeZone);
$simpleRes->setTimestamp($formatter->parse($date));
$simpleRes->setTime(0, 0, 0);
$simpleRes->setTimezone(new \DateTimeZone('UTC'));
return $simpleRes;
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Backup/Model/Backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function load($fileName, $filePath)
'extension' => $this->_helper->getExtensionByType($backupData->getType()),
'display_name' => $this->_helper->nameToDisplayName($backupData->getName()),
'name' => $backupData->getName(),
'date_object' => new \DateTime('@' . $backupData->getTime()),
'date_object' => (new \DateTime())->setTimestamp($backupData->getTime()),
]
);

Expand Down
19 changes: 11 additions & 8 deletions app/code/Magento/Catalog/Model/Product/Option/Type/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function prepareForCart()
$timestamp += 60 * 60 * $value['hour'] + 60 * $value['minute'];
}

$date = new \DateTime('@' . $timestamp);
$date = (new \DateTime())->setTimestamp($timestamp);
$result = $date->format('Y-m-d H:i:s');

// Save date in internal format to avoid locale date bugs
Expand All @@ -188,19 +188,22 @@ public function getFormattedOptionValue($optionValue)
{
if ($this->_formattedOptionValue === null) {
if ($this->getOption()->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_DATE) {
$format = $this->_localeDate->getDateFormat(
\IntlDateFormatter::MEDIUM
$result = $this->_localeDate->formatDateTime(
new \DateTime($optionValue),
\IntlDateFormatter::MEDIUM,
\IntlDateFormatter::NONE
);
$result = \IntlDateFormatter::formatObject(new \DateTime($optionValue), $format);
} elseif ($this->getOption()->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_DATE_TIME) {
$format = $this->_localeDate->getDateTimeFormat(
$result = $this->_localeDate->formatDateTime(
new \DateTime($optionValue),
\IntlDateFormatter::SHORT,
\IntlDateFormatter::SHORT
);
$result = \IntlDateFormatter::formatObject(new \DateTime($optionValue), $format);
} elseif ($this->getOption()->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_TIME) {
$result = \IntlDateFormatter::formatObject(
$result = $this->_localeDate->formatDateTime(
new \DateTime($optionValue),
$this->is24hTimeFormat() ? 'H:i' : 'h:i a'
\IntlDateFormatter::NONE,
\IntlDateFormatter::SHORT
);
} else {
$result = $optionValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ protected function _saveProducts()
$storeIds = [0];

if ('datetime' == $attribute->getBackendType() && strtotime($attrValue)) {
$attrValue = new \DateTime('@' . strtotime($attrValue));
$attrValue = (new \DateTime())->setTimestamp(strtotime($attrValue));
$attrValue = $attrValue->format(DateTime::DATETIME_PHP_FORMAT);
} elseif ($backModel) {
$attribute->getBackend()->beforeSave($product);
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/CatalogRule/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public function prepareCatalogProductCollectionPrices(EventObserver $observer)
if ($observer->getEvent()->hasDate()) {
$date = new \DateTime($observer->getEvent()->getDate());
} else {
$date = new \DateTime('@' . $this->_localeDate->scopeTimeStamp($store));
$date = (new \DateTime())->setTimestamp($this->_localeDate->scopeTimeStamp($store));
}

$productIds = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
require([
'jquery',
'mage/mage'
], function(jQuery){
], function($){

var dataForm = $('#form-validate');
var ignore = <?php echo $_dob->isEnabled() ? '\'input[id$="full"]\'' : 'null'; ?>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ protected function _prepareDataForUpdate(array $rowData)
if ('select' == $attributeParams['type']) {
$value = $attributeParams['options'][strtolower($rowData[$attributeAlias])];
} elseif ('datetime' == $attributeParams['type']) {
$value = new \DateTime('@' . strtotime($rowData[$attributeAlias]));
$value = (new \DateTime())->setTimestamp(strtotime($rowData[$attributeAlias]));
$value = $value->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT);
} else {
$value = $rowData[$attributeAlias];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,11 @@ protected function _prepareDataForUpdate(array $rowData)
$attributesToSave = [];

// entity table data
$now = new \DateTime('@' . time());
$now = new \DateTime();
if (empty($rowData['created_at'])) {
$createdAt = $now;
} else {
$createdAt = new \DateTime('@' . strtotime($rowData['created_at']));
$createdAt = (new \DateTime())->setTimestamp(strtotime($rowData['created_at']));
}
$entityRow = [
'group_id' => empty($rowData['group_id']) ? self::DEFAULT_GROUP_ID : $rowData['group_id'],
Expand Down Expand Up @@ -333,7 +333,7 @@ protected function _prepareDataForUpdate(array $rowData)
if ('select' == $attributeParameters['type']) {
$value = $attributeParameters['options'][strtolower($value)];
} elseif ('datetime' == $attributeParameters['type']) {
$value = new \DateTime('@' . strtotime($value));
$value = (new \DateTime())->setTimestamp(strtotime($value));
$value = $value->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT);
} elseif ($backendModel) {
$attribute->getBackend()->beforeSave($this->_customerModel->setData($attributeCode, $value));
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Dhl/Model/Carrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ protected function _parseResponse($response)

if (strlen(trim($response)) > 0) {
if (strpos(trim($response), '<?xml') === 0) {
$xml = simplexml_load_string($response);
$xml = $this->parseXml($response, 'Magento\Shipping\Model\Simplexml\Element');
if (is_object($xml)) {
if (in_array($xml->getName(), ['ErrorResponse', 'ShipmentValidateErrorResponse'])
|| isset($xml->GetQuoteResponse->Note->Condition)
Expand Down Expand Up @@ -1775,7 +1775,7 @@ protected function _parseXmlTrackingResponse($trackings, $response)
$resultArr = [];

if (strlen(trim($response)) > 0) {
$xml = simplexml_load_string($response);
$xml = $this->parseXml($response, 'Magento\Shipping\Model\Simplexml\Element');
if (!is_object($xml)) {
$errorTitle = __('Response is in the wrong format');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function formatDate($date)
}
// unix timestamp given - simply instantiate date object
if (is_scalar($date) && preg_match('/^[0-9]+$/', $date)) {
$date = new \DateTime('@' . $date);
$date = (new \DateTime())->setTimestamp($date);
// international format
} elseif (!($date instanceof \DateTime)) {
$date = new \DateTime($date);
Expand Down
24 changes: 2 additions & 22 deletions app/code/Magento/Fedex/Model/Carrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,8 @@ protected function _parseXmlResponse($response)
$priceArr = [];

if (strlen(trim($response)) > 0) {
if ($xml = $this->_parseXml($response)) {
$xml = $this->parseXml($response, 'Magento\Shipping\Model\Simplexml\Element');
if (is_object($xml)) {
if (is_object($xml->Error) && is_object($xml->Error->Message)) {
$errorTitle = (string)$xml->Error->Message;
} elseif (is_object($xml->SoftError) && is_object($xml->SoftError->Message)) {
Expand Down Expand Up @@ -760,27 +761,6 @@ protected function _parseXmlResponse($response)
return $result;
}

/**
* Parse XML string and return XML document object or false
*
* @param string $xmlContent
* @return \Magento\Shipping\Model\Simplexml\Element|bool
* @throws \Exception
*/
protected function _parseXml($xmlContent)
{
try {
try {
return simplexml_load_string($xmlContent);
} catch (\Exception $e) {
throw new \Exception(__('Failed to parse xml document: %1', $xmlContent));
}
} catch (\Exception $e) {
$this->_logger->critical($e);
return false;
}
}

/**
* Get configuration data of carrier
*
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Reports/Block/Adminhtml/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected function _prepareCollection()

if (!isset($data['report_from'])) {
// getting all reports from 2001 year
$date = new \DateTime('@' . mktime(0, 0, 0, 1, 1, 2001));
$date = (new \DateTime())->setTimestamp(mktime(0, 0, 0, 1, 1, 2001));
$data['report_from'] = $this->_localeDate->formatDateTime(
$date,
\IntlDateFormatter::SHORT,
Expand Down
32 changes: 18 additions & 14 deletions app/code/Magento/RequireJs/Block/Html/Head/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

namespace Magento\RequireJs\Block\Html\Head;

use Magento\Framework\RequireJs\Config as RequireJsConfig;

/**
* Block responsible for including RequireJs config on the page
*/
class Config extends \Magento\Framework\View\Element\AbstractBlock
{
/**
* @var \Magento\Framework\RequireJs\Config
* @var RequireJsConfig
*/
private $config;

Expand All @@ -28,15 +30,15 @@ class Config extends \Magento\Framework\View\Element\AbstractBlock

/**
* @param \Magento\Framework\View\Element\Context $context
* @param \Magento\Framework\RequireJs\Config $config
* @param RequireJsConfig $config
* @param \Magento\RequireJs\Model\FileManager $fileManager
* @param \Magento\Framework\View\Page\Config $pageConfig
* @param \Magento\Framework\View\Asset\ConfigInterface $bundleConfig
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Context $context,
\Magento\Framework\RequireJs\Config $config,
RequireJsConfig $config,
\Magento\RequireJs\Model\FileManager $fileManager,
\Magento\Framework\View\Page\Config $pageConfig,
\Magento\Framework\View\Asset\ConfigInterface $bundleConfig,
Expand All @@ -59,28 +61,30 @@ protected function _prepareLayout()
$requireJsConfig = $this->fileManager->createRequireJsConfigAsset();
$assetCollection = $this->pageConfig->getAssetCollection();

if ($this->bundleConfig->isBundlingJsFiles()) {
$after = \Magento\Framework\RequireJs\Config::REQUIRE_JS_FILE_NAME;
$assetCollection->insert(
$requireJsConfig->getFilePath(),
$requireJsConfig,
RequireJsConfig::REQUIRE_JS_FILE_NAME
);

if ($this->bundleConfig->isBundlingJsFiles()) {
$bundleAssets = $this->fileManager->createBundleJsPool();
$staticAsset = $this->fileManager->createStaticJsAsset();

/** @var \Magento\Framework\View\Asset\File $bundleAsset */
if (!empty($bundleAssets) && $staticAsset !== false) {
$bundleAssets = array_reverse($bundleAssets);
foreach ($bundleAssets as $bundleAsset) {
$assetCollection->insert($bundleAsset->getFilePath(), $bundleAsset, $after);
$after = $bundleAsset->getFilePath();
$assetCollection->insert(
$bundleAsset->getFilePath(),
$bundleAsset,
RequireJsConfig::REQUIRE_JS_FILE_NAME
);
}
$assetCollection->insert($staticAsset->getFilePath(), $staticAsset, $after);
$assetCollection->insert($staticAsset->getFilePath(), $staticAsset, RequireJsConfig::CONFIG_FILE_NAME);
}
}

$assetCollection->insert(
$requireJsConfig->getFilePath(),
$requireJsConfig,
\Magento\Framework\RequireJs\Config::REQUIRE_JS_FILE_NAME
);

return parent::_prepareLayout();
}

Expand Down
13 changes: 13 additions & 0 deletions app/code/Magento/Shipping/Model/Carrier/AbstractCarrierOnline.php
Original file line number Diff line number Diff line change
Expand Up @@ -607,4 +607,17 @@ public function getMethodPrice($cost, $method = '')
$cost
);
}

/**
* Parse XML string and return XML document object or false
*
* @param string $xmlContent
* @param string $customSimplexml
*
* @return \SimpleXMLElement|bool
*/
public function parseXml($xmlContent, $customSimplexml = 'SimpleXMLElement')
{
return simplexml_load_string($xmlContent, $customSimplexml);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,15 @@ public function testComposePackages()

$this->carrier->proccessAdditionalValidation($request);
}

public function testParseXml()
{
$xmlString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><GetResponse><value>42</value>></GetResponse>";
$simpleXmlElement = $this->carrier->parseXml($xmlString);
$this->assertEquals('GetResponse', $simpleXmlElement->getName());
$this->assertEquals(42, (int)$simpleXmlElement->value);
$this->assertInstanceOf('SimpleXMLElement', $simpleXmlElement);
$customSimpleXmlElement = $this->carrier->parseXml($xmlString, 'Magento\Shipping\Model\Simplexml\Element');
$this->assertInstanceOf('Magento\Shipping\Model\Simplexml\Element', $customSimpleXmlElement);
}
}
6 changes: 3 additions & 3 deletions app/code/Magento/Usps/Model/Carrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ protected function _parseXmlResponse($response)
$response
);
}
$xml = simplexml_load_string($response);
$xml = $this->parseXml($response);

if (is_object($xml)) {
$allowedMethods = explode(',', $this->getConfigData('allowed_methods'));
Expand Down Expand Up @@ -1042,7 +1042,7 @@ protected function _parseXmlTrackingResponse($trackingvalue, $response)
$resultArr = [];
if (strlen(trim($response)) > 0) {
if (strpos(trim($response), '<?xml') === 0) {
$xml = simplexml_load_string($response);
$xml = $this->parseXml($response);
if (is_object($xml)) {
if (isset($xml->Number) && isset($xml->Description) && (string)$xml->Description != '') {
$errorTitle = (string)$xml->Description;
Expand Down Expand Up @@ -1869,7 +1869,7 @@ protected function _doShipmentRequest(\Magento\Framework\Object $request)
$client->setParameterGet('XML', $requestXml);
$response = $client->request()->getBody();

$response = simplexml_load_string($response);
$response = $this->parseXml($response);
if ($response === false || $response->getName() == 'Error') {
$debugData['result'] = [
'error' => $response->Description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
['_parseDescription', 'Magento\Sales\Model\Order\Pdf\Items\AbstractItems'],
['_parsePackageTheme', 'Magento\Widget\Model\Widget\Instance'],
['_parseXmlTrackingResponse', 'Magento\Fedex\Model\Carrier'],
['_parseXml', 'Magento\Fedex\Model\Carrier'],
['_prepareCondition', 'Magento\CatalogSearch\Model\Advanced'],
['_prepareConfigurableProductData', 'Magento\CatalogImportExport\Model\Export\Product'],
['_prepareConfigurableProductPrice', 'Magento\CatalogImportExport\Model\Export\Product'],
Expand Down
Loading

0 comments on commit b456cd1

Please sign in to comment.