Skip to content

Commit c90c183

Browse files
author
Lysenko Olexandr
authored
Merge pull request #2866 from magento-chaika/vikapr
[Chaika] Bugfixes
2 parents 21f33bc + f894554 commit c90c183

File tree

7 files changed

+130
-10
lines changed

7 files changed

+130
-10
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ public function initializeFromData(\Magento\Catalog\Model\Product $product, arra
159159
}
160160

161161
$productData = $this->normalize($productData);
162+
$productData = $this->convertSpecialFromDateStringToObject($productData);
162163

163164
if (!empty($productData['is_downloadable'])) {
164165
$productData['product_has_weight'] = 0;
@@ -452,4 +453,19 @@ private function fillProductOptions(Product $product, array $productOptions)
452453

453454
return $product->setOptions($customOptions);
454455
}
456+
457+
/**
458+
* Convert string date presentation into object
459+
*
460+
* @param array $productData
461+
* @return array
462+
*/
463+
private function convertSpecialFromDateStringToObject($productData)
464+
{
465+
if (isset($productData['special_from_date']) && $productData['special_from_date'] != '') {
466+
$productData['special_from_date'] = new \DateTime($productData['special_from_date']);
467+
}
468+
469+
return $productData;
470+
}
455471
}

app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/HelperTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,12 @@ public function testInitialize(
198198
'option2' => ['is_delete' => false, 'name' => 'name1', 'price' => 'price1', 'option_id' => '13'],
199199
'option3' => ['is_delete' => false, 'name' => 'name1', 'price' => 'price1', 'option_id' => '14']
200200
];
201+
$specialFromDate = '2018-03-03 19:30:00';
201202
$productData = [
202203
'stock_data' => ['stock_data'],
203204
'options' => $optionsData,
204-
'website_ids' => $websiteIds
205+
'website_ids' => $websiteIds,
206+
'special_from_date' => $specialFromDate,
205207
];
206208
if (!empty($tierPrice)) {
207209
$productData = array_merge($productData, ['tier_price' => $tierPrice]);
@@ -306,6 +308,7 @@ public function testInitialize(
306308
}
307309

308310
$this->assertEquals($expectedLinks, $resultLinks);
311+
$this->assertEquals($specialFromDate, $productData['special_from_date']);
309312
}
310313

311314
/**

app/code/Magento/Customer/view/frontend/web/js/customer-data.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ define([
2727

2828
//TODO: remove global change, in this case made for initNamespaceStorage
2929
$.cookieStorage.setConf({
30-
path: '/'
30+
path: '/',
31+
expires: 1
3132
});
3233

3334
storage = $.initNamespaceStorage('mage-cache-storage').localStorage;

app/code/Magento/Eav/Model/Entity/Attribute.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Framework\Api\AttributeValueFactory;
99
use Magento\Framework\Exception\LocalizedException;
10+
use Magento\Framework\Stdlib\DateTime;
1011
use Magento\Framework\Stdlib\DateTime\DateTimeFormatterInterface;
1112

1213
/**
@@ -276,12 +277,10 @@ public function beforeSave()
276277

277278
// save default date value as timestamp
278279
if ($hasDefaultValue) {
279-
$format = $this->_localeDate->getDateFormat(
280-
\IntlDateFormatter::SHORT
281-
);
282280
try {
283-
$defaultValue = $this->dateTimeFormatter->formatObject(new \DateTime($defaultValue), $format);
284-
$this->setDefaultValue($defaultValue);
281+
$locale = $this->_localeResolver->getLocale();
282+
$defaultValue = $this->_localeDate->date($defaultValue, $locale, false, false);
283+
$this->setDefaultValue($defaultValue->format(DateTime::DATETIME_PHP_FORMAT));
285284
} catch (\Exception $e) {
286285
throw new LocalizedException(__('Invalid default date'));
287286
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Eav\Model\Entity;
7+
8+
use Magento\TestFramework\Helper\Bootstrap;
9+
use Magento\Framework\Locale\ResolverInterface;
10+
11+
class AttributeTest extends \PHPUnit\Framework\TestCase
12+
{
13+
/**
14+
* @var Attribute
15+
*/
16+
private $attribute;
17+
18+
/**
19+
* @var \Magento\Framework\ObjectManagerInterface
20+
*/
21+
private $objectManager;
22+
23+
/**
24+
* @var ResolverInterface
25+
*/
26+
private $_localeResolver;
27+
28+
protected function setUp()
29+
{
30+
$this->objectManager = Bootstrap::getObjectManager();
31+
$this->attribute = $this->objectManager->get(Attribute::class);
32+
$this->_localeResolver = $this->objectManager->get(ResolverInterface::class);
33+
}
34+
35+
protected function tearDown()
36+
{
37+
$this->attribute = null;
38+
$this->objectManager = null;
39+
$this->_localeResolver = null;
40+
}
41+
42+
/**
43+
* @param string $defaultValue
44+
* @param string $backendType
45+
* @param string $locale
46+
* @param string $expected
47+
* @dataProvider beforeSaveDataProvider
48+
* @throws
49+
*/
50+
public function testBeforeSave($defaultValue, $backendType, $locale, $expected)
51+
{
52+
$this->attribute->setDefaultValue($defaultValue);
53+
$this->attribute->setBackendType($backendType);
54+
$this->_localeResolver->setLocale($locale);
55+
$this->attribute->beforeSave();
56+
57+
$this->assertEquals($expected, $this->attribute->getDefaultValue());
58+
}
59+
60+
public function beforeSaveDataProvider()
61+
{
62+
return [
63+
['21/07/18', 'datetime', 'en_AU', '2018-07-21 00:00:00'],
64+
['07/21/18', 'datetime', 'en_US', '2018-07-21 00:00:00'],
65+
['21/07/18', 'datetime', 'fr_FR', '2018-07-21 00:00:00'],
66+
['21/07/18', 'datetime', 'de_DE', '2018-07-21 00:00:00'],
67+
['21/07/18', 'datetime', 'uk_UA', '2018-07-21 00:00:00'],
68+
['100.50', 'decimal', 'en_US', '100.50'],
69+
['100,50', 'decimal', 'uk_UA', '100.5'],
70+
];
71+
}
72+
73+
/**
74+
* @param string $defaultValue
75+
* @param string $backendType
76+
* @param string $locale
77+
* @param string $expected
78+
* @dataProvider beforeSaveErrorDataDataProvider
79+
* @expectedException \Magento\Framework\Exception\LocalizedException
80+
*/
81+
public function testBeforeSaveErrorData($defaultValue, $backendType, $locale, $expected)
82+
{
83+
$this->attribute->setDefaultValue($defaultValue);
84+
$this->attribute->setBackendType($backendType);
85+
$this->_localeResolver->setLocale($locale);
86+
$this->attribute->beforeSave();
87+
88+
$this->expectExceptionMessage($expected);
89+
}
90+
91+
public function beforeSaveErrorDataDataProvider()
92+
{
93+
return [
94+
'wrong date for Australia' => ['32/38', 'datetime', 'en_AU', 'Invalid default date'],
95+
'wrong date for States' => ['32/38', 'datetime', 'en_US', 'Invalid default date'],
96+
'wrong decimal separator for US' => ['100,50', 'decimal', 'en_US', 'Invalid default decimal value'],
97+
'wrong decimal separator for UA' => ['100.50', 'decimal', 'uk_UA', 'Invalid default decimal value'],
98+
];
99+
}
100+
}

nginx.conf.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ location /static/ {
103103
rewrite ^/static/(version[^/]+/)?(.*)$ /static/$2 last;
104104
}
105105

106-
location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
106+
location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2|json)$ {
107107
add_header Cache-Control "public";
108108
add_header X-Frame-Options "SAMEORIGIN";
109109
expires +1y;

pub/static/.htaccess

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ AddType application/xml xml
6767

6868
<IfModule mod_headers.c>
6969

70-
<FilesMatch .*\.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$>
70+
<FilesMatch .*\.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2|json)$>
7171
Header append Cache-Control public
7272
</FilesMatch>
7373

@@ -97,12 +97,13 @@ AddType application/xml xml
9797
ExpiresByType application/x-bzip2 "access plus 0 seconds"
9898

9999
# CSS, JavaScript, html
100-
<FilesMatch \.(css|js|html)$>
100+
<FilesMatch \.(css|js|html|json)$>
101101
ExpiresDefault "access plus 1 year"
102102
</FilesMatch>
103103
ExpiresByType text/css "access plus 1 year"
104104
ExpiresByType text/html "access plus 1 year"
105105
ExpiresByType application/javascript "access plus 1 year"
106+
ExpiresByType application/json "access plus 1 year"
106107

107108
# Favicon, images, flash
108109
<FilesMatch \.(ico|gif|png|jpg|jpeg|swf|svg)$>

0 commit comments

Comments
 (0)