Skip to content

Commit 203709d

Browse files
author
Joan He
committed
Merge remote-tracking branch 'origin/MC-5498-config-product' into BugFixPR
2 parents b1d3061 + 064d755 commit 203709d

File tree

7 files changed

+225
-8
lines changed

7 files changed

+225
-8
lines changed

app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminProductGridActionGroup.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,17 @@
192192
<click selector="{{AdminProductGridConfirmActionSection.ok}}" stepKey="confirmProductDelete"/>
193193
</actionGroup>
194194

195+
<actionGroup name="deleteProductByName" extends="deleteProductBySku">
196+
<arguments>
197+
<argument name="sku" type="string" defaultValue=""/>
198+
<argument name="name" type="string"/>
199+
</arguments>
200+
<remove keyForRemoval="fillProductSkuFilter"/>
201+
<fillField selector="{{AdminProductGridFilterSection.nameFilter}}" userInput="{{name}}" stepKey="fillProductSkuFilter" after="openProductFilters"/>
202+
<remove keyForRemoval="seeProductSkuInGrid"/>
203+
<see selector="{{AdminProductGridSection.productGridCell('1', 'Name')}}" userInput="{{name}}" stepKey="seeProductNameInGrid" after="clickApplyFilters"/>
204+
</actionGroup>
205+
195206
<!--Open product for edit by clicking row X and column Y in product grid-->
196207
<actionGroup name="openProducForEditByClickingRowXColumnYInProductGrid">
197208
<arguments>

app/code/Magento/Catalog/Test/Mftf/Data/ProductData.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,4 +477,8 @@
477477
<requiredEntity type="product_extension_attribute">EavStock1</requiredEntity>
478478
<requiredEntity type="custom_attribute">CustomAttributeProductAttribute</requiredEntity>
479479
</entity>
480+
<entity name="ProductWithLongNameSku" extends="ApiSimpleProduct">
481+
<data key="name" unique="suffix">Product With Long Name And Sku - But not too long</data>
482+
<data key="sku" unique="suffix">Product With Long Name And Sku - But not too long</data>
483+
</entity>
480484
</entities>

app/code/Magento/ConfigurableProduct/Test/Mftf/ActionGroup/AdminConfigurableProductActionGroup.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
<seeInTitle userInput="{{product.name}}" stepKey="seeProductNameInTitle"/>
106106
</actionGroup>
107107

108-
<actionGroup name="createConfigurationsForAttribute">
108+
<actionGroup name="generateConfigurationsByAttributeCode">
109109
<arguments>
110110
<argument name="attributeCode" type="string" defaultValue="SomeString"/>
111111
</arguments>
@@ -121,6 +121,12 @@
121121
<fillField selector="{{AdminCreateProductConfigurationsPanel.quantity}}" userInput="99" stepKey="enterAttributeQuantity"/>
122122
<click selector="{{AdminCreateProductConfigurationsPanel.next}}" stepKey="clickOnNextButton3"/>
123123
<click selector="{{AdminCreateProductConfigurationsPanel.next}}" stepKey="clickOnNextButton4"/>
124+
</actionGroup>
125+
126+
<actionGroup name="createConfigurationsForAttribute" extends="generateConfigurationsByAttributeCode">
127+
<arguments>
128+
<argument name="attributeCode" type="string" defaultValue="SomeString"/>
129+
</arguments>
124130
<click selector="{{AdminProductFormActionSection.saveButton}}" stepKey="clickOnSaveButton2"/>
125131
<click selector="{{AdminChooseAffectedAttributeSetPopup.confirm}}" stepKey="clickOnConfirmInPopup"/>
126132
</actionGroup>

app/code/Magento/ConfigurableProduct/Test/Mftf/Section/AdminProductFormConfigurationsSection.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
<element name="removeProductBtn" type="button" selector="//a[text()='Remove Product']"/>
2323
<element name="disableProductBtn" type="button" selector="//a[text()='Disable Product']"/>
2424
<element name="enableProductBtn" type="button" selector="//a[text()='Enable Product']"/>
25+
<element name="variationsSkuInputByRow" selector="[data-index='configurable-matrix'] table > tbody > tr:nth-of-type({{row}}) input[name*='sku']" type="input" parameterized="true"/>
26+
<element name="variationsSkuInputErrorByRow" selector="[data-index='configurable-matrix'] table > tbody > tr:nth-of-type({{row}}) .admin__field-error" type="text" parameterized="true"/>
2527
</section>
2628
<section name="AdminConfigurableProductFormSection">
2729
<element name="productWeight" type="input" selector=".admin__control-text[name='product[weight]']"/>
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AdminConfigurableProductLongSkuTest">
12+
<annotations>
13+
<features value="ConfigurableProduct"/>
14+
<stories value="Create configurable product"/>
15+
<title value="Admin is able to create an product with a long sku below that is below the character limit"/>
16+
<description value="Try to create a product with sku slightly less than char limit. Get client side SKU length error for child products. Correct SKUs and save product succeeds."/>
17+
<severity value="MAJOR"/>
18+
<testCaseId value="MC-5685"/>
19+
<group value="ConfigurableProduct"/>
20+
</annotations>
21+
22+
<before>
23+
<!--Create product attribute with options-->
24+
<createData entity="productAttributeWithTwoOptions" stepKey="createConfigProductAttribute"/>
25+
<createData entity="productAttributeOption1" stepKey="createConfigProductAttributeOption1">
26+
<requiredEntity createDataKey="createConfigProductAttribute"/>
27+
</createData>
28+
<createData entity="productAttributeOption2" stepKey="createConfigProductAttributeOption2">
29+
<requiredEntity createDataKey="createConfigProductAttribute"/>
30+
</createData>
31+
<createData entity="AddToDefaultSet" stepKey="createConfigAddToAttributeSet">
32+
<requiredEntity createDataKey="createConfigProductAttribute"/>
33+
</createData>
34+
<getData entity="ProductAttributeOptionGetter" index="1" stepKey="getConfigAttributeOption1">
35+
<requiredEntity createDataKey="createConfigProductAttribute"/>
36+
</getData>
37+
<getData entity="ProductAttributeOptionGetter" index="2" stepKey="getConfigAttributeOption2">
38+
<requiredEntity createDataKey="createConfigProductAttribute"/>
39+
</getData>
40+
<!--Create Category-->
41+
<createData entity="ApiCategory" stepKey="createCategory"/>
42+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin1"/>
43+
</before>
44+
45+
<after>
46+
<!--Clean up products-->
47+
<actionGroup ref="deleteProductByName" stepKey="cleanUpProducts">
48+
<argument name="sku" value="{{ProductWithLongNameSku.sku}}"/>
49+
<argument name="name" value="{{ProductWithLongNameSku.name}}"/>
50+
</actionGroup>
51+
<!--Clean up attribute-->
52+
<deleteData createDataKey="createConfigProductAttribute" stepKey="deleteConfigProductAttribute"/>
53+
<!--Clean up category-->
54+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
55+
<amOnPage url="admin/admin/auth/logout/" stepKey="amOnLogoutPage"/>
56+
</after>
57+
58+
<!--Create a configurable product with long name and sku-->
59+
<amOnPage url="{{AdminProductCreatePage.url(AddToDefaultSet.attributeSetId, 'configurable')}}" stepKey="goToProductCreatePage"/>
60+
<waitForPageLoad stepKey="waitForProductCreatePage"/>
61+
<fillField selector="{{AdminProductFormSection.productName}}" userInput="{{ProductWithLongNameSku.name}}" stepKey="fillProductName"/>
62+
<fillField selector="{{AdminProductFormSection.productSku}}" userInput="{{ProductWithLongNameSku.sku}}" stepKey="fillProductSku"/>
63+
<fillField selector="{{AdminProductFormSection.productPrice}}" userInput="{{ProductWithLongNameSku.price}}" stepKey="fillProductPrice"/>
64+
<searchAndMultiSelectOption selector="{{AdminProductFormSection.categoriesDropdown}}" parameterArray="[$$createCategory.name$$]" stepKey="selectCategory"/>
65+
<!--Setup configurations-->
66+
<actionGroup ref="generateConfigurationsByAttributeCode" stepKey="setupConfigurations">
67+
<argument name="attributeCode" value="$$createConfigProductAttribute.attribute_code$$"/>
68+
</actionGroup>
69+
70+
<!--See SKU length errors in Current Variations grid-->
71+
<click selector="{{AdminProductFormActionSection.saveButton}}" stepKey="saveProductFail"/>
72+
<seeInCurrentUrl url="{{AdminProductCreatePage.url(AddToDefaultSet.attributeSetId, 'configurable')}}" stepKey="seeRemainOnCreateProductPage"/>
73+
<see selector="{{AdminProductFormConfigurationsSection.variationsSkuInputErrorByRow('1')}}" userInput="Please enter less or equal than 64 symbols." stepKey="seeSkuTooLongError1"/>
74+
<see selector="{{AdminProductFormConfigurationsSection.variationsSkuInputErrorByRow('2')}}" userInput="Please enter less or equal than 64 symbols." stepKey="seeSkuTooLongError2"/>
75+
<!--Fix SKU lengths-->
76+
<fillField selector="{{AdminProductFormConfigurationsSection.variationsSkuInputByRow('1')}}" userInput="LongSku-$$getConfigAttributeOption1.label$$" stepKey="fixConfigurationSku1"/>
77+
<fillField selector="{{AdminProductFormConfigurationsSection.variationsSkuInputByRow('2')}}" userInput="LongSku-$$getConfigAttributeOption2.label$$" stepKey="fixConfigurationSku2"/>
78+
<!--Save product successfully-->
79+
<click selector="{{AdminProductFormActionSection.saveButton}}" stepKey="saveProductSuccess"/>
80+
<seeElement selector="{{AdminProductMessagesSection.successMessage}}" stepKey="seeSaveProductMessage"/>
81+
82+
<!--Assert configurations on the product edit pag-->
83+
<seeNumberOfElements selector="{{AdminProductFormConfigurationsSection.currentVariationsRows}}" userInput="2" stepKey="seeNumberOfRows"/>
84+
<see selector="{{AdminProductFormConfigurationsSection.currentVariationsNameCells}}" userInput="{{ProductWithLongNameSku.name}}-$$getConfigAttributeOption1.label$$" stepKey="seeChildProductName1"/>
85+
<see selector="{{AdminProductFormConfigurationsSection.currentVariationsNameCells}}" userInput="{{ProductWithLongNameSku.name}}-$$getConfigAttributeOption2.label$$" stepKey="seeChildProductName2"/>
86+
<see selector="{{AdminProductFormConfigurationsSection.currentVariationsSkuCells}}" userInput="LongSku-$$getConfigAttributeOption1.label$$" stepKey="seeChildProductSku1"/>
87+
<see selector="{{AdminProductFormConfigurationsSection.currentVariationsSkuCells}}" userInput="LongSku-$$getConfigAttributeOption2.label$$" stepKey="seeChildProductSku2"/>
88+
<see selector="{{AdminProductFormConfigurationsSection.currentVariationsPriceCells}}" userInput="{{ProductWithLongNameSku.price}}" stepKey="seeConfigurationsPrice"/>
89+
90+
<!--Assert storefront category list page-->
91+
<amOnPage url="/" stepKey="amOnStorefront"/>
92+
<waitForPageLoad stepKey="waitForStorefrontLoad"/>
93+
<click userInput="$$createCategory.name$$" stepKey="clickOnCategoryName"/>
94+
<waitForPageLoad stepKey="waitForCategoryPageLoad"/>
95+
<see userInput="{{ProductWithLongNameSku.name}}" stepKey="assertProductPresent"/>
96+
<see userInput="{{ProductWithLongNameSku.price}}" stepKey="assertProductPricePresent"/>
97+
98+
<!--Assert storefront product details page-->
99+
<click selector="{{StorefrontCategoryProductSection.ProductTitleByName(ProductWithLongNameSku.name)}}" stepKey="clickOnProductName"/>
100+
<waitForPageLoad stepKey="waitForProductPageLoad"/>
101+
<seeInTitle userInput="{{ProductWithLongNameSku.name}}" stepKey="assertProductNameTitle"/>
102+
<see userInput="{{ProductWithLongNameSku.name}}" selector="{{StorefrontProductInfoMainSection.productName}}" stepKey="assertProductName"/>
103+
<see userInput="{{ProductWithLongNameSku.sku}}" selector="{{StorefrontProductInfoMainSection.productSku}}" stepKey="assertProductSku"/>
104+
<see selector="{{StorefrontProductInfoMainSection.productAttributeTitle1}}" userInput="$$createConfigProductAttribute.default_frontend_label$$" stepKey="seeColorAttributeName1"/>
105+
<see selector="{{StorefrontProductInfoMainSection.productAttributeOptions1}}" userInput="$$getConfigAttributeOption1.label$$" stepKey="seeInDropDown1"/>
106+
<see selector="{{StorefrontProductInfoMainSection.productAttributeOptions1}}" userInput="$$getConfigAttributeOption2.label$$" stepKey="seeInDropDown2"/>
107+
</test>
108+
</tests>

app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/variations/variations.js

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -390,19 +390,23 @@ define([
390390
this.attributeSetHandlerModal().openModal();
391391
} else {
392392
this.formElement().save(arguments[0], arguments[1]);
393+
394+
if (this.formElement().source.get('params.invalid')) {
395+
this.unserializeData();
396+
}
393397
}
394398
},
395399

396400
/**
397401
* Serialize data for specific form fields
398402
*
399-
* Get data from outdated fields, serialize it and produce new form fields.
403+
* Serializes some complex data fields
400404
*
401-
* Outdated fields:
405+
* Original fields:
402406
* - configurable-matrix;
403407
* - associated_product_ids.
404408
*
405-
* New fields:
409+
* Serialized fields in request:
406410
* - configurable-matrix-serialized;
407411
* - associated_product_ids_serialized.
408412
*/
@@ -420,6 +424,25 @@ define([
420424
}
421425
},
422426

427+
/**
428+
* Unserialize data for specific form fields
429+
*
430+
* Unserializes some fields that were serialized this.serializeData
431+
*/
432+
unserializeData: function () {
433+
if (this.source.data['configurable-matrix-serialized']) {
434+
this.source.data['configurable-matrix'] =
435+
JSON.parse(this.source.data['configurable-matrix-serialized']);
436+
delete this.source.data['configurable-matrix-serialized'];
437+
}
438+
439+
if (this.source.data['associated_product_ids_serialized']) {
440+
this.source.data['associated_product_ids'] =
441+
JSON.parse(this.source.data['associated_product_ids_serialized']);
442+
delete this.source.data['associated_product_ids_serialized'];
443+
}
444+
},
445+
423446
/**
424447
* Check for newly added attributes
425448
* @returns {Boolean}
@@ -443,20 +466,20 @@ define([
443466
* @returns {Boolean}
444467
*/
445468
addNewAttributeSetHandler: function () {
446-
var choosenAttributeSetOption;
469+
var chosenAttributeSetOption;
447470

448471
this.formElement().validate();
449472

450473
if (this.formElement().source.get('params.invalid') === false) {
451-
choosenAttributeSetOption = this.attributeSetSelection;
474+
chosenAttributeSetOption = this.attributeSetSelection;
452475

453-
if (choosenAttributeSetOption === 'new') {
476+
if (chosenAttributeSetOption === 'new') {
454477
this.createNewAttributeSet();
455478

456479
return false;
457480
}
458481

459-
if (choosenAttributeSetOption === 'existing') {
482+
if (chosenAttributeSetOption === 'existing') {
460483
this.set(
461484
'skeletonAttributeSet',
462485
this.attributeSetId
@@ -467,6 +490,10 @@ define([
467490

468491
return true;
469492
}
493+
494+
this.unserializeData();
495+
496+
return false;
470497
},
471498

472499
/**

dev/tests/js/jasmine/tests/app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/variations/variations.test.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,64 @@ define([
117117
expect(variation.source.data['configurable-matrix-serialized']).toEqual(resultMatrix);
118118
expect(variation.source.data['associated_product_ids_serialized']).toEqual(resultIds);
119119
});
120+
121+
it('checks that "unserializeData" unserializes data', function () {
122+
var matrixString = '[{"name":"Small Product","attributes":"Size: small","price":5.5},' +
123+
'{"name":"Medium Product","attributes":"Size: medium","price":10.99},' +
124+
'{"name":"Large Product","attributes":"Size: large","price":25}]',
125+
idString = '[100, 101, 102]',
126+
resultMatrix = JSON.parse(matrixString),
127+
resultIds = JSON.parse(idString);
128+
129+
variation.source.data['configurable-matrix-serialized'] = matrixString;
130+
variation.source.data['associated_product_ids_serialized'] = idString;
131+
132+
variation.unserializeData();
133+
134+
expect(variation.source.data['configurable-matrix-serialized']).toBeUndefined();
135+
expect(variation.source.data['associated_product_ids_serialized']).toBeUndefined();
136+
expect(variation.source.data['configurable-matrix']).toEqual(resultMatrix);
137+
expect(variation.source.data['associated_product_ids']).toEqual(resultIds);
138+
});
139+
140+
it('checks that "serializeData" and "unserializeData" give proper result', function () {
141+
var matrix = [
142+
{
143+
name: 'Small Product',
144+
attributes: 'Size: small',
145+
price: 5.50
146+
},
147+
{
148+
name: 'Medium Product',
149+
attributes: 'Size: medium',
150+
price: 10.99
151+
},
152+
{
153+
name: 'Large Product',
154+
attributes: 'Size: large',
155+
price: 25
156+
}
157+
],
158+
ids = [1, 2, 3],
159+
resultMatrix = JSON.stringify(matrix),
160+
resultIds = JSON.stringify(ids);
161+
162+
variation.source.data['configurable-matrix'] = matrix;
163+
variation.source.data['associated_product_ids'] = ids;
164+
165+
variation.serializeData();
166+
167+
expect(variation.source.data['configurable-matrix']).toBeUndefined();
168+
expect(variation.source.data['associated_product_ids']).toBeUndefined();
169+
expect(variation.source.data['configurable-matrix-serialized']).toEqual(resultMatrix);
170+
expect(variation.source.data['associated_product_ids_serialized']).toEqual(resultIds);
171+
172+
variation.unserializeData();
173+
174+
expect(variation.source.data['configurable-matrix']).toEqual(matrix);
175+
expect(variation.source.data['associated_product_ids']).toEqual(ids);
176+
expect(variation.source.data['configurable-matrix-serialized']).toBeUndefined();
177+
expect(variation.source.data['associated_product_ids_serialized']).toBeUndefined();
178+
});
120179
});
121180
});

0 commit comments

Comments
 (0)