Skip to content

Commit ed2eea6

Browse files
author
Olexandr Lysenko
committed
Merge branch 'MAGETWO-58896' into bugfixes
2 parents 8d0dc6f + a6de353 commit ed2eea6

File tree

5 files changed

+221
-125
lines changed

5 files changed

+221
-125
lines changed

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/General.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -315,17 +315,6 @@ protected function customizeNameListeners(array $meta)
315315
$importsConfig = [
316316
'mask' => $this->locator->getStore()->getConfig('catalog/fields_masks/' . $listener),
317317
'component' => 'Magento_Catalog/js/components/import-handler',
318-
'imports' => [
319-
'handleNameChanges' => '${$.provider}:data.product.name',
320-
'handleDescriptionChanges' => '${$.provider}:data.product.description',
321-
'handleSkuChanges' => '${$.provider}:data.product.sku',
322-
'handleColorChanges' => '${$.provider}:data.product.color',
323-
'handleCountryChanges' => '${$.provider}:data.product.country_of_manufacture',
324-
'handleGenderChanges' => '${$.provider}:data.product.gender',
325-
'handleMaterialChanges' => '${$.provider}:data.product.material',
326-
'handleShortDescriptionChanges' => '${$.provider}:data.product.short_description',
327-
'handleSizeChanges' => '${$.provider}:data.product.size'
328-
],
329318
'allowImport' => !$this->locator->getProduct()->getId(),
330319
];
331320

app/code/Magento/Catalog/view/adminhtml/web/js/components/import-handler.js

Lines changed: 51 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -4,148 +4,78 @@
44
*/
55

66
define([
7+
'Magento_Ui/js/form/element/abstract',
78
'underscore',
8-
'Magento_Ui/js/form/element/textarea'
9-
], function (_, Textarea) {
9+
'uiRegistry'
10+
], function (Abstract, _, registry) {
1011
'use strict';
1112

12-
return Textarea.extend({
13+
return Abstract.extend({
1314
defaults: {
1415
allowImport: true,
1516
autoImportIfEmpty: false,
16-
values: {
17-
'name': '',
18-
'description': '',
19-
'sku': '',
20-
'color': '',
21-
'country_of_manufacture': '',
22-
'gender': '',
23-
'material': '',
24-
'short_description': '',
25-
'size': ''
26-
},
27-
valueUpdate: 'input',
28-
mask: ''
17+
values: {},
18+
mask: '',
19+
queryTemplate: 'ns = ${ $.ns }, index = '
2920
},
3021

31-
/**
32-
* Handle name value changes, if it's allowed
33-
*
34-
* @param {String} newValue
35-
*/
36-
handleNameChanges: function (newValue) {
37-
this.values.name = newValue;
38-
this.updateValue();
39-
},
40-
41-
/**
42-
* Handle description value changes, if it's allowed
43-
*
44-
* @param {String} newValue
45-
*/
46-
handleDescriptionChanges: function (newValue) {
47-
this.values.description = newValue;
48-
this.updateValue();
49-
},
22+
/** @inheritdoc */
23+
initialize: function () {
24+
this._super();
5025

51-
/**
52-
* Handle sku value changes, if it's allowed
53-
*
54-
* @param {String} newValue
55-
*/
56-
handleSkuChanges: function (newValue) {
57-
if (this.code !== 'sku') {
58-
this.values.sku = newValue;
59-
this.updateValue();
26+
if (this.allowImport) {
27+
this.setHandlers();
6028
}
6129
},
6230

6331
/**
64-
* Handle color value changes, if it's allowed
65-
*
66-
* @param {String} newValue
67-
*/
68-
handleColorChanges: function (newValue) {
69-
this.values.color = newValue;
70-
this.updateValue();
71-
},
72-
73-
/**
74-
* Handle country value changes, if it's allowed
75-
*
76-
* @param {String} newValue
32+
* Split mask placeholder and attach events to placeholder fields.
7733
*/
78-
handleCountryChanges: function (newValue) {
79-
this.values.country = newValue;
80-
this.updateValue();
81-
},
34+
setHandlers: function () {
35+
var str = this.mask || '',
36+
placeholders;
8237

83-
/**
84-
* Handle gender value changes, if it's allowed
85-
*
86-
* @param {String} newValue
87-
*/
88-
handleGenderChanges: function (newValue) {
89-
this.values.gender = newValue;
90-
this.updateValue();
91-
},
38+
placeholders = str.match(/{{(.*?)}}/g); // Get placeholders
9239

93-
/**
94-
* Handle material value changes, if it's allowed
95-
*
96-
* @param {String} newValue
97-
*/
98-
handleMaterialChanges: function (newValue) {
99-
this.values.material = newValue;
100-
this.updateValue();
101-
},
40+
_.each(placeholders, function (placeholder) {
41+
placeholder = placeholder.replace(/[{{}}]/g, ''); // Remove curly braces
10242

103-
/**
104-
* Handle short description value changes, if it's allowed
105-
*
106-
* @param {String} newValue
107-
*/
108-
handleShortDescriptionChanges: function (newValue) {
109-
this.values['short_description'] = newValue;
110-
this.updateValue();
43+
registry.get(this.queryTemplate + placeholder, function (component) {
44+
this.values[placeholder] = component.getPreview();
45+
component.on('value', this.updateValue.bind(this, placeholder, component));
46+
component.valueUpdate = 'keyup';
47+
}.bind(this));
48+
}, this);
11149
},
11250

11351
/**
114-
* Handle size value changes, if it's allowed
52+
* Update field with mask value, if it's allowed.
11553
*
116-
* @param {String} newValue
54+
* @param {Object} placeholder
55+
* @param {Object} component
11756
*/
118-
handleSizeChanges: function (newValue) {
119-
this.values.size = newValue;
120-
this.updateValue();
121-
},
57+
updateValue: function (placeholder, component) {
58+
var string = this.mask || '',
59+
nonEmptyValueFlag = false;
12260

123-
/**
124-
* Update field value, if it's allowed
125-
*/
126-
updateValue: function () {
127-
var str = this.mask || '',
128-
nonEmptyValueFlag = false,
129-
tmpElement;
61+
if (placeholder) {
62+
this.values[placeholder] = component.getPreview() || '';
63+
}
13064

13165
if (!this.allowImport) {
13266
return;
13367
}
13468

135-
if (str) {
136-
_.each(this.values, function (propertyValue, propertyName) {
137-
str = str.replace('{{' + propertyName + '}}', propertyValue);
138-
nonEmptyValueFlag = nonEmptyValueFlag || !!propertyValue;
139-
});
140-
}
141-
142-
// strip tags
143-
tmpElement = document.createElement('div');
144-
tmpElement.innerHTML = str;
145-
str = tmpElement.textContent || tmpElement.innerText || '';
69+
_.each(this.values, function (propertyValue, propertyName) {
70+
string = string.replace('{{' + propertyName + '}}', propertyValue);
71+
nonEmptyValueFlag = nonEmptyValueFlag || !!propertyValue;
72+
});
14673

14774
if (nonEmptyValueFlag) {
148-
this.value(str);
75+
string = string.replace(/(<([^>]+)>)/ig, ''); // Remove html tags
76+
this.value(string);
77+
} else {
78+
this.value('');
14979
}
15080
},
15181

@@ -169,13 +99,20 @@ define([
16999
* and disallow/allow import value
170100
*/
171101
userChanges: function () {
102+
103+
/**
104+
* As userChanges is called before updateValue,
105+
* we forced to get value from component by reference
106+
*/
107+
var actualValue = arguments[1].currentTarget.value;
108+
172109
this._super();
173110

174-
if (this.value() === '') {
111+
if (actualValue === '') {
175112
this.allowImport = true;
176113

177114
if (this.autoImportIfEmpty) {
178-
this.updateValue();
115+
this.updateValue(null, null);
179116
}
180117
} else {
181118
this.allowImport = false;

dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/ConfigData.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,16 @@
3434
<item name="inherit" xsi:type="number">1</item>
3535
</field>
3636
</dataset>
37+
<dataset name="attribute_product_mask_sku">
38+
<field name="catalog/fields_masks/sku" xsi:type="array">
39+
<item name="value" xsi:type="string">{{name}} {{country_of_manufacture}}</item>
40+
</field>
41+
</dataset>
42+
<dataset name="attribute_product_mask_sku_rollback">
43+
<field name="catalog/fields_masks/sku" xsi:type="array">
44+
<item name="value" xsi:type="string">{{name}}</item>
45+
<item name="inherit" xsi:type="number">1</item>
46+
</field>
47+
</dataset>
3748
</repository>
3849
</config>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
/**
4+
* Copyright © 2016 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../vendor/magento/mtf/etc/variations.xsd">
9+
<testCase name="Magento\Catalog\Test\TestCase\Product\CreateSimpleProductEntityByAttributeMaskSkuTest" summary="Create Simple Product with attribute sku mask" ticketId="MAGETWO-59861">
10+
<variation name="CreateSimpleProductEntityByAttributeMaskSkuTest1">
11+
<data name="configData" xsi:type="string">attribute_product_mask_sku</data>
12+
<data name="description" xsi:type="string">Create product with country of manufacture attribute sku mask</data>
13+
<data name="product/data/url_key" xsi:type="string">simple-product-%isolation%</data>
14+
<data name="product/data/name" xsi:type="string">Simple Product %isolation%</data>
15+
<data name="product/data/price/value" xsi:type="string">10000</data>
16+
<data name="product/data/weight" xsi:type="string">50</data>
17+
<data name="product/data/quantity_and_stock_status/qty" xsi:type="string">657</data>
18+
<data name="product/data/country_of_manufacture" xsi:type="string">Ukraine</data>
19+
<constraint name="Magento\Catalog\Test\Constraint\AssertProductSaveMessage" />
20+
<constraint name="Magento\Catalog\Test\Constraint\AssertProductInGrid" />
21+
</variation>
22+
</testCase>
23+
</config>

0 commit comments

Comments
 (0)