Skip to content

Commit e26dea6

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-90029' into 2.2-develop-pr36
2 parents 756c469 + 574d7b6 commit e26dea6

File tree

35 files changed

+282
-46
lines changed

35 files changed

+282
-46
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/Checkout/Test/Mftf/Section/CheckoutShippingSection.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
<element name="city" type="input" selector="input[name=city]"/>
1818
<element name="region" type="select" selector="select[name=region_id]"/>
1919
<element name="postcode" type="input" selector="input[name=postcode]"/>
20+
<element name="country" type="select" selector="select[name=country_id]"/>
2021
<element name="telephone" type="input" selector="input[name=telephone]"/>
2122
<element name="next" type="button" selector="button.button.action.continue.primary"/>
2223
<element name="firstShippingMethod" type="radio" selector="#checkout-shipping-method-load input[type='radio']"/>
2324
<element name="selectedShippingAddress" type="text" selector=".shipping-address-item.selected-item"/>
2425
<element name="newAddressButton" type="button" selector="#checkout-step-shipping button"/>
2526
<element name="next" type="button" selector="[data-role='opc-continue']"/>
27+
<element name="stateInput" type="input" selector="input[name=region]"/>
2628
<element name="newAdress" type="button" selector="button.action.action-show-popup"/>
2729
<element name="addStreet" type="input" selector="#shipping-new-address-form input[name='street[0]']"/>
2830
<element name="addCity" type="input" selector="#shipping-new-address-form input[name='city']"/>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd">
11+
<test name="AddressStateFieldShouldNotAcceptJustIntegerValuesTest">
12+
<annotations>
13+
<features value="Checkout"/>
14+
<title value="Guest Checkout"/>
15+
<description value="Address State field should not allow just integer values"/>
16+
<severity value="MAJOR"/>
17+
<testCaseId value="MAGETWO-93291"/>
18+
<group value="checkout"/>
19+
</annotations>
20+
<before>
21+
<createData entity="_defaultCategory" stepKey="createCategory"/>
22+
<createData entity="ApiSimpleProduct" stepKey="createProduct">
23+
<requiredEntity createDataKey="createCategory"/>
24+
</createData>
25+
</before>
26+
<after>
27+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
28+
<deleteData createDataKey="createProduct" stepKey="deleteProduct"/>
29+
</after>
30+
31+
<amOnPage url="{{StorefrontCategoryPage.url($$createCategory.name$$)}}" stepKey="onCategoryPage"/>
32+
<waitForPageLoad stepKey="waitForPageLoad1"/>
33+
<moveMouseOver selector="{{StorefrontCategoryMainSection.ProductItemInfo}}" stepKey="hoverProduct"/>
34+
<click selector="{{StorefrontCategoryMainSection.AddToCartBtn}}" stepKey="addToCart"/>
35+
<waitForElementVisible selector="{{StorefrontCategoryMainSection.SuccessMsg}}" time="30" stepKey="waitForProductAdded"/>
36+
<see selector="{{StorefrontCategoryMainSection.SuccessMsg}}" userInput="You added $$createProduct.name$$ to your shopping cart." stepKey="seeAddedToCartMessage"/>
37+
<see selector="{{StorefrontMinicartSection.quantity}}" userInput="1" stepKey="seeCartQuantity"/>
38+
<actionGroup ref="GoToCheckoutFromMinicartActionGroup" stepKey="guestGoToCheckoutFromMinicart" />
39+
<selectOption selector="{{CheckoutShippingSection.country}}" userInput="{{UK_Address.country_id}}" stepKey="selectCounty"/>
40+
<waitForPageLoad stepKey="waitFormToReload"/>
41+
<fillField selector="{{CheckoutShippingSection.stateInput}}" userInput="1" stepKey="enterStateAsIntegerValue"/>
42+
<waitForPageLoad stepKey="waitforFormValidation"/>
43+
<see userInput="First character must be letter." stepKey="seeTheErrorMessageDisplayed"/>
44+
<fillField selector="{{CheckoutShippingSection.stateInput}}" userInput=" 1" stepKey="enterStateAsIntegerValue1"/>
45+
<waitForPageLoad stepKey="waitforFormValidation1"/>
46+
<see userInput="First character must be letter." stepKey="seeTheErrorMessageDisplayed1"/>
47+
<fillField selector="{{CheckoutShippingSection.stateInput}}" userInput="ABC1" stepKey="enterStateAsIntegerValue2"/>
48+
<waitForPageLoad stepKey="waitforFormValidation2"/>
49+
<dontSee userInput="First character must be letter." stepKey="seeTheErrorMessageIsNotDisplayed"/>
50+
</test>
51+
</tests>

app/code/Magento/Customer/Model/Address/AbstractAddress.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ public function validate()
648648
//If country actually has regions and requires you to
649649
//select one then it must be selected.
650650
$errors[] = __('%fieldName is a required field.', ['fieldName' => 'regionId']);
651-
} elseif ($regionId && !in_array($regionId, $allowedRegions, true)) {
651+
} elseif ($allowedRegions && $regionId && !in_array($regionId, $allowedRegions, true)) {
652652
//If a region is selected then checking if it exists.
653653
$errors[] = __(
654654
'Invalid value of "%value" provided for the %fieldName field.',

app/code/Magento/Customer/Test/Mftf/Data/AddressData.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949
<data key="default_shipping">Yes</data>
5050
<requiredEntity type="region">RegionTX</requiredEntity>
5151
</entity>
52+
<!--If required other field can be added to UK_Address entity, don't modify any existing data-->
53+
<entity name="UK_Address" type="address">
54+
<data key="country_id">GB</data>
55+
</entity>
5256
<entity name="US_Address_CA" type="address">
5357
<data key="firstname">John</data>
5458
<data key="lastname">Doe</data>

app/code/Magento/Customer/Test/Unit/Model/Address/AbstractAddressTest.php

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,8 @@ public function testValidate(array $data, $expected)
311311
->will($this->returnValue([]));
312312

313313
$this->directoryDataMock->expects($this->any())
314-
->method('isRegionRequired');
314+
->method('isRegionRequired')
315+
->willReturn($data['region_required']);
315316

316317
$countryCollectionMock = $this->getMockBuilder(\Magento\Directory\Model\ResourceModel\Country\Collection::class)
317318
->disableOriginalConstructor()
@@ -326,14 +327,18 @@ public function testValidate(array $data, $expected)
326327

327328
$regionModelMock = $this->getMockBuilder(\Magento\Directory\Model\Region::class)
328329
->disableOriginalConstructor()
329-
->setMethods(['getCountryId', 'getName', 'load'])
330+
->setMethods(['getCountryId', 'getName', 'load', 'loadByCode'])
330331
->getMock();
331332

332333
$this->regionFactoryMock->expects($this->any())->method('create')->willReturn($regionModelMock);
333334

334335
$regionModelMock->expects($this->any())->method('load')->with($data['region_id'])->willReturnSelf();
335336
$regionModelMock->expects($this->any())->method('getCountryId')->willReturn($countryId);
336-
$regionModelMock->expects($this->any())->method('getName')->willReturn('RegionName');
337+
$regionModelMock->expects($this->any())->method('getName')->willReturn($data['region']);
338+
$regionModelMock->expects($this->any())
339+
->method('loadByCode')
340+
->with($data['region'], $countryId)
341+
->willReturnSelf();
337342

338343
$countryModelMock = $this->getMockBuilder(\Magento\Directory\Model\Country::class)
339344
->disableOriginalConstructor()
@@ -352,7 +357,7 @@ public function testValidate(array $data, $expected)
352357
->setMethods(['getAllIds'])
353358
->getMock();
354359
$countryModelMock->expects($this->any())->method('getRegionCollection')->willReturn($regionCollectionMock);
355-
$regionCollectionMock->expects($this->any())->method('getAllIds')->willReturn(['1']);
360+
$regionCollectionMock->expects($this->any())->method('getAllIds')->willReturn($data['allowed_regions']);
356361

357362
foreach ($data as $key => $value) {
358363
$this->model->setData($key, $value);
@@ -377,8 +382,11 @@ public function validateDataProvider()
377382
'country_id' => $countryId,
378383
'postcode' => 07201,
379384
'region_id' => 1,
385+
'region' => 'RegionName',
386+
'region_required' => false,
380387
'company' => 'Magento',
381-
'fax' => '222-22-22'
388+
'fax' => '222-22-22',
389+
'allowed_regions' => ['1'],
382390
];
383391
return [
384392
'firstname' => [
@@ -405,8 +413,28 @@ public function validateDataProvider()
405413
array_merge(array_diff_key($data, ['postcode' => '']), ['country_id' => $countryId++]),
406414
['postcode is a required field.'],
407415
],
408-
'region_id' => [
409-
array_merge($data, ['country_id' => $countryId++, 'region_id' => 2]),
416+
'region' => [
417+
array_merge(
418+
$data,
419+
[
420+
'region_required' => true,
421+
'country_id' => $countryId++,
422+
'allowed_regions' => [],
423+
'region' => '',
424+
]
425+
),
426+
['region is a required field.'],
427+
],
428+
'region_id1' => [
429+
array_merge($data, ['country_id' => $countryId, 'region_required' => true, 'region_id' => '']),
430+
['regionId is a required field.'],
431+
],
432+
'region_id2' => [
433+
array_merge($data, ['country_id' => $countryId, 'region_id' => 2, 'allowed_regions' => []]),
434+
true,
435+
],
436+
'region_id3' => [
437+
array_merge($data, ['country_id' => $countryId, 'region_id' => 2, 'allowed_regions' => [1, 3]]),
410438
['Invalid value of "2" provided for the regionId field.'],
411439
],
412440
'country_id' => [

app/code/Magento/Customer/view/frontend/templates/address/edit.phtml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
/** @var \Magento\Customer\Block\Address\Edit $block */
1010
?>
11-
<?php $_company = $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Company') ?>
12-
<?php $_telephone = $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Telephone') ?>
13-
<?php $_fax = $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Fax') ?>
11+
<?php $_company = $block->getLayout()->createBlock(\Magento\Customer\Block\Widget\Company::class) ?>
12+
<?php $_telephone = $block->getLayout()->createBlock(\Magento\Customer\Block\Widget\Telephone::class) ?>
13+
<?php $_fax = $block->getLayout()->createBlock(\Magento\Customer\Block\Widget\Fax::class) ?>
1414
<form class="form-address-edit"
1515
action="<?= $block->escapeUrl($block->getSaveUrl()) ?>"
1616
method="post"
@@ -39,7 +39,7 @@
3939
</fieldset>
4040
<fieldset class="fieldset">
4141
<legend class="legend"><span><?= $block->escapeHtml(__('Address')) ?></span></legend><br>
42-
<?php $_streetValidationClass = $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('street'); ?>
42+
<?php $_streetValidationClass = $this->helper(\Magento\Customer\Helper\Address::class)->getAttributeValidationClass('street'); ?>
4343
<div class="field street required">
4444
<label for="street_1" class="label">
4545
<span><?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('street') ?></span>
@@ -53,7 +53,7 @@
5353
class="input-text <?= $block->escapeHtmlAttr($_streetValidationClass) ?>"/>
5454
<div class="nested">
5555
<?php $_streetValidationClass = trim(str_replace('required-entry', '', $_streetValidationClass)); ?>
56-
<?php for ($_i = 1, $_n = $this->helper('Magento\Customer\Helper\Address')->getStreetLines(); $_i < $_n; $_i++): ?>
56+
<?php for ($_i = 1, $_n = $this->helper(\Magento\Customer\Helper\Address::class)->getStreetLines(); $_i < $_n; $_i++): ?>
5757
<div class="field additional">
5858
<label class="label" for="street_<?= /* @noEscape */ $_i + 1 ?>">
5959
<span><?= $block->escapeHtml(__('Street Address %1', $_i + 1)) ?></span>
@@ -71,7 +71,7 @@
7171
</div>
7272
</div>
7373

74-
<?php if ($this->helper('Magento\Customer\Helper\Address')->isVatAttributeVisible()) : ?>
74+
<?php if ($this->helper(\Magento\Customer\Helper\Address::class)->isVatAttributeVisible()) : ?>
7575
<div class="field taxvat">
7676
<label class="label" for="vat_id">
7777
<span><?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('vat_id') ?></span>
@@ -81,7 +81,7 @@
8181
name="vat_id"
8282
value="<?= $block->escapeHtmlAttr($block->getAddress()->getVatId()) ?>"
8383
title="<?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('vat_id') ?>"
84-
class="input-text <?= $block->escapeHtmlAttr($this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('vat_id')) ?>"
84+
class="input-text <?= $block->escapeHtmlAttr($this->helper(\Magento\Customer\Helper\Address::class)->getAttributeValidationClass('vat_id')) ?>"
8585
id="vat_id">
8686
</div>
8787
</div>
@@ -93,7 +93,7 @@
9393
name="city"
9494
value="<?= $block->escapeHtmlAttr($block->getAddress()->getCity()) ?>"
9595
title="<?= $block->escapeHtmlAttr(__('City')) ?>"
96-
class="input-text <?= $block->escapeHtmlAttr($this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('city')) ?>"
96+
class="input-text <?= $block->escapeHtmlAttr($this->helper(\Magento\Customer\Helper\Address::class)->getAttributeValidationClass('city')) ?>"
9797
id="city">
9898
</div>
9999
</div>
@@ -112,7 +112,7 @@
112112
name="region"
113113
value="<?= $block->escapeHtmlAttr($block->getRegion()) ?>"
114114
title="<?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('region') ?>"
115-
class="input-text <?= $block->escapeHtmlAttr($this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('region')) ?>"<?= !$block->getConfig('general/region/display_all') ? ' disabled="disabled"' : '' ?>/>
115+
class="input-text validate-not-number-first <?= $block->escapeHtmlAttr($this->helper(\Magento\Customer\Helper\Address::class)->getAttributeValidationClass('region')) ?>"<?= !$block->getConfig('general/region/display_all') ? ' disabled="disabled"' : '' ?>/>
116116
</div>
117117
</div>
118118
<div class="field zip required">
@@ -125,7 +125,7 @@
125125
value="<?= $block->escapeHtmlAttr($block->getAddress()->getPostcode()) ?>"
126126
title="<?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('postcode') ?>"
127127
id="zip"
128-
class="input-text validate-zip-international <?= $block->escapeHtmlAttr($this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('postcode')) ?>">
128+
class="input-text validate-zip-international <?= $block->escapeHtmlAttr($this->helper(\Magento\Customer\Helper\Address::class)->getAttributeValidationClass('postcode')) ?>">
129129
</div>
130130
</div>
131131
<div class="field country required">

app/code/Magento/Customer/view/frontend/templates/form/confirmation.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<div class="field email required">
1515
<label for="email_address" class="label"><span><?= $block->escapeHtml(__('Email')) ?></span></label>
1616
<div class="control">
17-
<input type="email" name="email" id="email_address" class="input-text" value="<?= $block->escapeHtmlAttr($block->getEmail()) ?>" data-validate="{required:true, 'validate-email':true}">
17+
<input type="email" name="email" id="email_address" class="input-text" value="<?= $block->escapeHtmlAttr($block->getEmail()) ?>" data-validate="{required:true, 'validate-email':true}" data-mage-init='{"mage/trim-input":{}}'>
1818
</div>
1919
</div>
2020
</fieldset>

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;

0 commit comments

Comments
 (0)