Skip to content

Commit 9c81cf5

Browse files
committed
ACP2E-3660: REST endpoint Product Import Json not validate the mandatory fields
1 parent 8169bca commit 9c81cf5

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product/Validator.php

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,11 @@ public function getInvalidAttribute()
379379
}
380380

381381
/**
382-
* Is valid attributes
382+
* Validate attributes against configured properties
383383
*
384384
* @return array
385385
*/
386-
protected function isValidAttributes()
386+
private function validateAttributes(): array
387387
{
388388
$this->_clearMessages();
389389
$this->setInvalidAttribute(null);
@@ -412,21 +412,52 @@ protected function isValidAttributes()
412412
return $attributeValidationResult;
413413
}
414414

415+
/**
416+
* Is valid attributes
417+
*
418+
* @return bool
419+
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
420+
*/
421+
protected function isValidAttributes()
422+
{
423+
$this->_clearMessages();
424+
$this->setInvalidAttribute(null);
425+
if (!isset($this->_rowData['product_type'])) {
426+
return false;
427+
}
428+
$entityTypeModel = $this->context->retrieveProductTypeByName($this->_rowData['product_type']);
429+
if ($entityTypeModel) {
430+
foreach ($this->_rowData as $attrCode => $attrValue) {
431+
$attrParams = $entityTypeModel->retrieveAttributeFromCache($attrCode);
432+
if ($attrCode === Product::COL_CATEGORY && $attrValue) {
433+
$this->isCategoriesValid($attrValue);
434+
} elseif ($attrParams) {
435+
$this->isAttributeValid($attrCode, $attrParams, $this->_rowData);
436+
}
437+
}
438+
if ($this->getMessages()) {
439+
return false;
440+
}
441+
}
442+
return true;
443+
}
444+
415445
/**
416446
* @inheritdoc
417447
*/
418448
public function isValid($value)
419449
{
420450
$this->_rowData = $value;
421451
$this->_clearMessages();
422-
$validatedAttributes = $this->isValidAttributes();
452+
$validatedAttributes = $this->validateAttributes();
423453
/** @var Product\Validator\AbstractImportValidator $validator */
424454
foreach ($this->validators as $validator) {
425455
if (!$validator->isValid($value)) {
426456
$this->_addMessages($validator->getMessages());
427457
} else {
428458
//prioritize specialized validation
429459
if ($validator->getFieldName() &&
460+
isset($validatedAttributes['attributes']) &&
430461
$validatedAttributes['attributes'][$validator->getFieldName()] === false
431462
) {
432463
$validatedAttributes['attributes'][$validator->getFieldName()] = true;

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/Product/Type/AbstractTypeTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php declare(strict_types=1);
22

33
/**
4-
* Copyright © Magento, Inc. All rights reserved.
5-
* See COPYING.txt for license details.
4+
* Copyright 2015 Adobe
5+
* All Rights Reserved.
66
*/
77
namespace Magento\CatalogImportExport\Test\Unit\Model\Import\Product\Type;
88

0 commit comments

Comments
 (0)