Skip to content

Commit e642dde

Browse files
committed
ACP2E-3660: REST endpoint Product Import Json not validate the mandatory fields
1 parent 22830e3 commit e642dde

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2708,7 +2708,9 @@ public function validateRow(array $rowData, $rowNum)
27082708
// if product doesn't exist, need to throw critical error else all errors should be not critical.
27092709
$errorLevel = $this->getValidationErrorLevel($sku);
27102710

2711-
if (!$this->validator->isValid($rowData)) {
2711+
$hasValidatedImportParent = $sku && $this->skuProcessor->getNewSku($sku);
2712+
$contextRowData = array_merge(['has_import_parent' => $hasValidatedImportParent], $rowData);
2713+
if (!$this->validator->isValid($contextRowData)) {
27122714
foreach ($this->validator->getMessages() as $message) {
27132715
$this->skipRow($rowNum, $message, $errorLevel, $this->validator->getInvalidAttribute());
27142716
}
@@ -2756,6 +2758,7 @@ public function validateRow(array $rowData, $rowNum)
27562758
'attr_set_code' => $rowData[self::COL_ATTR_SET],
27572759
]
27582760
);
2761+
//$this->skuStorage->set(array_merge(['sku' => $sku], $this->skuProcessor->getNewSku($sku)));
27592762
}
27602763
}
27612764

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ public function isValid($value)
3737
$skuExists = $this->skuStorage->has($value[Product::COL_SKU]);
3838
$hasCustomOptions = $this->hasCustomOptions($value);
3939
$hasNameValue = $this->hasNameValue($value);
40+
$hasParentInImport = $this->hasValidatedImportParent($value);
4041

41-
if (!$skuExists && !$hasCustomOptions && !$hasNameValue) {
42+
if (!$skuExists && !$hasCustomOptions && !$hasNameValue && !$hasParentInImport) {
4243
return $this->invalidate();
4344
}
4445

@@ -64,6 +65,17 @@ private function invalidate(): bool
6465
return false;
6566
}
6667

68+
/**
69+
* Check if current row data has a soon-to-be added parent product
70+
*
71+
* @param array $rowData
72+
* @return bool
73+
*/
74+
private function hasValidatedImportParent(array $rowData): bool
75+
{
76+
return array_key_exists('has_import_parent', $rowData) && $rowData['has_import_parent'];
77+
}
78+
6779
/**
6880
* Check if row data contains name value
6981
*

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/Product/Validator/NameTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static function getRowData(): array
6363
['name' => 'anything goes here', 'store_view_code' => 'en', 'sku' => 'sku']
6464
],
6565
[
66-
true,
66+
false,
6767
['name' => null, 'store_view_code' => 'en', 'sku' => 'sku']
6868
],
6969
];

0 commit comments

Comments
 (0)