Skip to content

Commit 2bca2aa

Browse files
🔃 [EngCom] Public Pull Requests - 2.3-develop
Accepted Public Pull Requests: - #21834: Add argument to show filter text in URL rewrite grid after click on back button (by @vbmagento) - #21135: Fix eav form foreach error #21134 (by @wojtekn) - #18067: Fixes variables in configuration fields not being replaced with actual value� (by @hostep) - #21749: Sitemap Generation - Product URL check null fix (by @asim-vax) - #21511: SHQ18-1568 Updating UPS endpoint to use https. Http is no longer reli� (by @wsajosh) - #21484: Populate label elements for street address fields in checkout (by @scottsb) - #21465: Module data fixtures for @magentoDataFixtureBeforeTransaction annotations (by @Vinai) - #21065: Refactored Retrieval Of Entity ID To Make AbstractDataProvider Usable (by @sprankhub) - #21053: Allow redis compression options to be specified during `setup:install` process (by @cmacdonald-au) - #20526: [EAV] Improving the EAV attribute code validation, by not allowing to use n� (by @eduard13) - #20898: Fixed #13319 , Incorrect method return value in \Magento\Shipping\Model\Carrier\AbstractCarrier::getTotalNumOfBoxes() (by @cedmudit) - #19265: add missing fields to quote_address (by @ErikPel) Fixed GitHub Issues: - #21805: Filter in url rewrites table in backend isn't being remembered (reported by @hostep) has been fixed in #21834 by @vbmagento in 2.3-develop branch Related commits: 1. ae6c8bc 2. d85fd44 3. f75b3e9 4. d5a61c0 - #21134: Invalid argument supplied for foreach thrown in EAV code (reported by @wojtekn) has been fixed in #21135 by @wojtekn in 2.3-develop branch Related commits: 1. ac40d43 2. 059f399 3. 9f0dfcf - #15972: Since Magento 2.2.1, certain variables in the configuration get resolved to their actual value (reported by @hostep) has been fixed in #18067 by @hostep in 2.3-develop branch Related commits: 1. a8f1729 - #10893: Street fields in checkout don't have a label that's readable by a screenreader (reported by @TomFranssen) has been fixed in #21484 by @scottsb in 2.3-develop branch Related commits: 1. e1fa289 - #20766: AttributeCode column name length validation throws wrong error message (reported by @brosenberger) has been fixed in #20526 by @eduard13 in 2.3-develop branch Related commits: 1. 6f83604 2. adb1a8f 3. 3c8acbb 4. 82f5511 5. 4488371 6. e028d6f 7. 8129886 8. 079bb15 9. 5666a85 10. 50b78da 11. 6878668 12. 40683de 13. 392cd1b - #20943: No complete validation while creation of attributes. (reported by @irajneeshgupta) has been fixed in #20526 by @eduard13 in 2.3-develop branch Related commits: 1. 6f83604 2. adb1a8f 3. 3c8acbb 4. 82f5511 5. 4488371 6. e028d6f 7. 8129886 8. 079bb15 9. 5666a85 10. 50b78da 11. 6878668 12. 40683de 13. 392cd1b - #13319: Incorrect method return value in \Magento\Shipping\Model\Carrier\AbstractCarrier::getTotalNumOfBoxes() (reported by @korostii) has been fixed in #20898 by @cedmudit in 2.3-develop branch Related commits: 1. 56504e1 - #17658: validate function in vatvalidation calls checkVatNumber a lot (reported by @sanderjongsma) has been fixed in #19265 by @ErikPel in 2.3-develop branch Related commits: 1. e27f09f 2. 7f15bd8
2 parents 450880c + 46033f1 commit 2bca2aa

File tree

32 files changed

+607
-137
lines changed

32 files changed

+607
-137
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -195,25 +195,6 @@ public function execute()
195195
? $model->getAttributeCode()
196196
: $this->getRequest()->getParam('attribute_code');
197197
$attributeCode = $attributeCode ?: $this->generateCode($this->getRequest()->getParam('frontend_label')[0]);
198-
if (strlen($attributeCode) > 0) {
199-
$validatorAttrCode = new \Zend_Validate_Regex(
200-
['pattern' => '/^[a-zA-Z\x{600}-\x{6FF}][a-zA-Z\x{600}-\x{6FF}_0-9]{0,30}$/u']
201-
);
202-
if (!$validatorAttrCode->isValid($attributeCode)) {
203-
$this->messageManager->addErrorMessage(
204-
__(
205-
'Attribute code "%1" is invalid. Please use only letters (a-z or A-Z), ' .
206-
'numbers (0-9) or underscore(_) in this field, first character should be a letter.',
207-
$attributeCode
208-
)
209-
);
210-
return $this->returnResult(
211-
'catalog/*/edit',
212-
['attribute_id' => $attributeId, '_current' => true],
213-
['error' => true]
214-
);
215-
}
216-
}
217198
$data['attribute_code'] = $attributeCode;
218199

219200
//validate frontend_input

app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77

88
namespace Magento\Catalog\Controller\Adminhtml\Product\Attribute;
99

10-
use Magento\Framework\Serialize\Serializer\FormData;
10+
use Magento\Catalog\Controller\Adminhtml\Product\Attribute as AttributeAction;
11+
use Magento\Eav\Model\Validator\Attribute\Code as AttributeCodeValidator;
1112
use Magento\Framework\App\Action\HttpGetActionInterface;
1213
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
1314
use Magento\Framework\App\ObjectManager;
1415
use Magento\Framework\DataObject;
15-
use Magento\Catalog\Controller\Adminhtml\Product\Attribute as AttributeAction;
16+
use Magento\Framework\Serialize\Serializer\FormData;
1617

1718
/**
1819
* Product attribute validate controller.
@@ -43,6 +44,11 @@ class Validate extends AttributeAction implements HttpGetActionInterface, HttpPo
4344
*/
4445
private $formDataSerializer;
4546

47+
/**
48+
* @var AttributeCodeValidator
49+
*/
50+
private $attributeCodeValidator;
51+
4652
/**
4753
* Constructor
4854
*
@@ -54,6 +60,7 @@ class Validate extends AttributeAction implements HttpGetActionInterface, HttpPo
5460
* @param \Magento\Framework\View\LayoutFactory $layoutFactory
5561
* @param array $multipleAttributeList
5662
* @param FormData|null $formDataSerializer
63+
* @param AttributeCodeValidator|null $attributeCodeValidator
5764
*/
5865
public function __construct(
5966
\Magento\Backend\App\Action\Context $context,
@@ -63,14 +70,18 @@ public function __construct(
6370
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
6471
\Magento\Framework\View\LayoutFactory $layoutFactory,
6572
array $multipleAttributeList = [],
66-
FormData $formDataSerializer = null
73+
FormData $formDataSerializer = null,
74+
AttributeCodeValidator $attributeCodeValidator = null
6775
) {
6876
parent::__construct($context, $attributeLabelCache, $coreRegistry, $resultPageFactory);
6977
$this->resultJsonFactory = $resultJsonFactory;
7078
$this->layoutFactory = $layoutFactory;
7179
$this->multipleAttributeList = $multipleAttributeList;
7280
$this->formDataSerializer = $formDataSerializer ?: ObjectManager::getInstance()
7381
->get(FormData::class);
82+
$this->attributeCodeValidator = $attributeCodeValidator ?: ObjectManager::getInstance()->get(
83+
AttributeCodeValidator::class
84+
);
7485
}
7586

7687
/**
@@ -115,6 +126,12 @@ public function execute()
115126
$response->setError(true);
116127
$response->setProductAttribute($attribute->toArray());
117128
}
129+
130+
if (!$this->attributeCodeValidator->isValid($attributeCode)) {
131+
$this->setMessageToResponse($response, $this->attributeCodeValidator->getMessages());
132+
$response->setError(true);
133+
}
134+
118135
if ($this->getRequest()->has('new_attribute_set_name')) {
119136
$setName = $this->getRequest()->getParam('new_attribute_set_name');
120137
/** @var $attributeSet \Magento\Eav\Model\Entity\Attribute\Set */

app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Attribute/SaveTest.php

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

88
use Magento\Catalog\Api\Data\ProductAttributeInterface;
99
use Magento\Catalog\Controller\Adminhtml\Product\Attribute\Save;
10+
use Magento\Eav\Model\Validator\Attribute\Code as AttributeCodeValidator;
1011
use Magento\Framework\Serialize\Serializer\FormData;
1112
use Magento\Catalog\Test\Unit\Controller\Adminhtml\Product\AttributeTest;
1213
use Magento\Catalog\Model\Product\AttributeSet\BuildFactory;
@@ -94,6 +95,11 @@ class SaveTest extends AttributeTest
9495
*/
9596
private $productAttributeMock;
9697

98+
/**
99+
* @var AttributeCodeValidator|\PHPUnit_Framework_MockObject_MockObject
100+
*/
101+
private $attributeCodeValidatorMock;
102+
97103
protected function setUp()
98104
{
99105
parent::setUp();
@@ -138,6 +144,9 @@ protected function setUp()
138144
$this->formDataSerializerMock = $this->getMockBuilder(FormData::class)
139145
->disableOriginalConstructor()
140146
->getMock();
147+
$this->attributeCodeValidatorMock = $this->getMockBuilder(AttributeCodeValidator::class)
148+
->disableOriginalConstructor()
149+
->getMock();
141150
$this->productAttributeMock = $this->getMockBuilder(ProductAttributeInterface::class)
142151
->setMethods(['getId', 'get'])
143152
->getMockForAbstractClass();
@@ -171,6 +180,7 @@ protected function getModel()
171180
'groupCollectionFactory' => $this->groupCollectionFactoryMock,
172181
'layoutFactory' => $this->layoutFactoryMock,
173182
'formDataSerializer' => $this->formDataSerializerMock,
183+
'attributeCodeValidator' => $this->attributeCodeValidatorMock
174184
]);
175185
}
176186

@@ -224,6 +234,10 @@ public function testExecute()
224234
$this->productAttributeMock
225235
->method('getAttributeCode')
226236
->willReturn('test_code');
237+
$this->attributeCodeValidatorMock
238+
->method('isValid')
239+
->with('test_code')
240+
->willReturn(true);
227241
$this->requestMock->expects($this->once())
228242
->method('getPostValue')
229243
->willReturn($data);

app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Attribute/ValidateTest.php

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Catalog\Test\Unit\Controller\Adminhtml\Product\Attribute;
77

88
use Magento\Catalog\Controller\Adminhtml\Product\Attribute\Validate;
9+
use Magento\Eav\Model\Validator\Attribute\Code as AttributeCodeValidator;
910
use Magento\Framework\Serialize\Serializer\FormData;
1011
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
1112
use Magento\Catalog\Test\Unit\Controller\Adminhtml\Product\AttributeTest;
@@ -67,6 +68,11 @@ class ValidateTest extends AttributeTest
6768
*/
6869
private $formDataSerializerMock;
6970

71+
/**
72+
* @var AttributeCodeValidator|\PHPUnit_Framework_MockObject_MockObject
73+
*/
74+
private $attributeCodeValidatorMock;
75+
7076
protected function setUp()
7177
{
7278
parent::setUp();
@@ -95,6 +101,9 @@ protected function setUp()
95101
$this->formDataSerializerMock = $this->getMockBuilder(FormData::class)
96102
->disableOriginalConstructor()
97103
->getMock();
104+
$this->attributeCodeValidatorMock = $this->getMockBuilder(AttributeCodeValidator::class)
105+
->disableOriginalConstructor()
106+
->getMock();
98107

99108
$this->contextMock->expects($this->any())
100109
->method('getObjectManager')
@@ -117,6 +126,7 @@ protected function getModel()
117126
'layoutFactory' => $this->layoutFactoryMock,
118127
'multipleAttributeList' => ['select' => 'option'],
119128
'formDataSerializer' => $this->formDataSerializerMock,
129+
'attributeCodeValidator' => $this->attributeCodeValidatorMock,
120130
]
121131
);
122132
}
@@ -141,6 +151,12 @@ public function testExecute()
141151
$this->attributeMock->expects($this->once())
142152
->method('loadByCode')
143153
->willReturnSelf();
154+
155+
$this->attributeCodeValidatorMock->expects($this->once())
156+
->method('isValid')
157+
->with('test_attribute_code')
158+
->willReturn(true);
159+
144160
$this->requestMock->expects($this->once())
145161
->method('has')
146162
->with('new_attribute_set_name')
@@ -190,6 +206,11 @@ public function testUniqueValidation(array $options, $isError)
190206
->with($serializedOptions)
191207
->willReturn($options);
192208

209+
$this->attributeCodeValidatorMock->expects($this->once())
210+
->method('isValid')
211+
->with('test_attribute_code')
212+
->willReturn(true);
213+
193214
$this->objectManagerMock->expects($this->once())
194215
->method('create')
195216
->willReturn($this->attributeMock);
@@ -333,6 +354,11 @@ public function testEmptyOption(array $options, $result)
333354
->method('loadByCode')
334355
->willReturnSelf();
335356

357+
$this->attributeCodeValidatorMock->expects($this->once())
358+
->method('isValid')
359+
->with('test_attribute_code')
360+
->willReturn(true);
361+
336362
$this->resultJsonFactoryMock->expects($this->once())
337363
->method('create')
338364
->willReturn($this->resultJson);
@@ -444,6 +470,10 @@ public function testExecuteWithOptionsDataError()
444470
[\Magento\Eav\Model\Entity\Attribute\Set::class, [], $this->attributeSetMock]
445471
]);
446472

473+
$this->attributeCodeValidatorMock
474+
->method('isValid')
475+
->willReturn(true);
476+
447477
$this->attributeMock
448478
->method('loadByCode')
449479
->willReturnSelf();
@@ -463,4 +493,81 @@ public function testExecuteWithOptionsDataError()
463493

464494
$this->getModel()->execute();
465495
}
496+
497+
/**
498+
* Test execute with an invalid attribute code
499+
*
500+
* @dataProvider provideInvalidAttributeCodes
501+
* @param string $attributeCode
502+
* @param $result
503+
* @throws \Magento\Framework\Exception\NotFoundException
504+
*/
505+
public function testExecuteWithInvalidAttributeCode($attributeCode, $result)
506+
{
507+
$serializedOptions = '{"key":"value"}';
508+
$this->requestMock->expects($this->any())
509+
->method('getParam')
510+
->willReturnMap([
511+
['frontend_label', null, null],
512+
['frontend_input', 'select', 'multipleselect'],
513+
['attribute_code', null, $attributeCode],
514+
['new_attribute_set_name', null, 'test_attribute_set_name'],
515+
['message_key', Validate::DEFAULT_MESSAGE_KEY, 'message'],
516+
['serialized_options', '[]', $serializedOptions],
517+
]);
518+
519+
$this->formDataSerializerMock
520+
->expects($this->once())
521+
->method('unserialize')
522+
->with($serializedOptions)
523+
->willReturn(["key" => "value"]);
524+
525+
$this->objectManagerMock->expects($this->once())
526+
->method('create')
527+
->willReturn($this->attributeMock);
528+
529+
$this->attributeMock->expects($this->once())
530+
->method('loadByCode')
531+
->willReturnSelf();
532+
533+
$this->attributeCodeValidatorMock->expects($this->once())
534+
->method('isValid')
535+
->with($attributeCode)
536+
->willReturn(false);
537+
538+
$this->attributeCodeValidatorMock->expects($this->once())
539+
->method('getMessages')
540+
->willReturn(['Invalid Attribute Code.']);
541+
542+
$this->resultJsonFactoryMock->expects($this->once())
543+
->method('create')
544+
->willReturn($this->resultJson);
545+
546+
$this->resultJson->expects($this->once())
547+
->method('setJsonData')
548+
->willReturnArgument(0);
549+
550+
$response = $this->getModel()->execute();
551+
$responseObject = json_decode($response);
552+
553+
$this->assertEquals($responseObject, $result);
554+
}
555+
556+
/**
557+
* Providing invalid attribute codes
558+
*
559+
* @return array
560+
*/
561+
public function provideInvalidAttributeCodes()
562+
{
563+
return [
564+
'invalid attribute code' => [
565+
'.attribute_code',
566+
(object) [
567+
'error' => true,
568+
'message' => 'Invalid Attribute Code.',
569+
]
570+
]
571+
];
572+
}
466573
}

app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ protected function getMultilineFieldConfig($attributeCode, array $attributeConfi
278278
for ($lineIndex = 0; $lineIndex < (int)$attributeConfig['size']; $lineIndex++) {
279279
$isFirstLine = $lineIndex === 0;
280280
$line = [
281+
'label' => __("%1: Line %2", $attributeConfig['label'], $lineIndex + 1),
281282
'component' => 'Magento_Ui/js/form/element/abstract',
282283
'config' => [
283284
// customScope is used to group elements within a single form e.g. they can be validated separately

app/code/Magento/Config/Block/System/Config/Form.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,10 @@ private function getFieldData(\Magento\Config\Model\Config\Structure\Element\Fie
424424
$backendModel = $field->getBackendModel();
425425
// Backend models which implement ProcessorInterface are processed by ScopeConfigInterface
426426
if (!$backendModel instanceof ProcessorInterface) {
427+
if (array_key_exists($path, $this->_configData)) {
428+
$data = $this->_configData[$path];
429+
}
430+
427431
$backendModel->setPath($path)
428432
->setValue($data)
429433
->setWebsite($this->getWebsiteCode())

0 commit comments

Comments
 (0)