Skip to content

Commit c953b4d

Browse files
committed
ACPT-1429: Stabilize Import Product
1 parent 08e0f3c commit c953b4d

File tree

5 files changed

+48
-23
lines changed

5 files changed

+48
-23
lines changed

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

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,6 @@ public function isAttributeValid($attrCode, array $attrParams, array $rowData)
254254
*/
255255
private function validateByAttributeType(string $attrCode, array $attrParams, array $rowData): bool
256256
{
257-
$valid = false;
258-
259257
switch ($attrParams['type']) {
260258
case 'varchar':
261259
case 'text':
@@ -270,19 +268,7 @@ private function validateByAttributeType(string $attrCode, array $attrParams, ar
270268
$valid = $this->validateOption($attrCode, $attrParams['options'], $rowData[$attrCode]);
271269
break;
272270
case 'multiselect':
273-
$values = $this->context->parseMultiselectValues($rowData[$attrCode]);
274-
foreach ($values as $value) {
275-
$valid = $this->validateOption($attrCode, $attrParams['options'], $value);
276-
if (!$valid) {
277-
break;
278-
}
279-
}
280-
281-
$uniqueValues = array_unique($values);
282-
if (count($uniqueValues) != count($values)) {
283-
$valid = false;
284-
$this->_addMessages([RowValidatorInterface::ERROR_DUPLICATE_MULTISELECT_VALUES]);
285-
}
271+
$valid = $this->validateMultiselect($attrCode, $attrParams['options'], $rowData[$attrCode]);
286272
break;
287273
case 'datetime':
288274
$val = trim($rowData[$attrCode]);
@@ -299,6 +285,35 @@ private function validateByAttributeType(string $attrCode, array $attrParams, ar
299285
return $valid;
300286
}
301287

288+
/**
289+
* Validate multiselect attribute.
290+
*
291+
* @param string $attrCode
292+
* @param array $options
293+
* @param array|string $rowData
294+
* @return bool
295+
*/
296+
private function validateMultiselect(string $attrCode, array $options, array|string $rowData): bool
297+
{
298+
$valid = true;
299+
300+
$values = $this->context->parseMultiselectValues($rowData);
301+
foreach ($values as $value) {
302+
$valid = $this->validateOption($attrCode, $options, $value);
303+
if (!$valid) {
304+
break;
305+
}
306+
}
307+
308+
$uniqueValues = array_unique($values);
309+
if (count($uniqueValues) != count($values)) {
310+
$valid = false;
311+
$this->_addMessages([RowValidatorInterface::ERROR_DUPLICATE_MULTISELECT_VALUES]);
312+
}
313+
314+
return $valid;
315+
}
316+
302317
/**
303318
* Set invalid attribute
304319
*

app/code/Magento/CustomerImportExport/Model/Import/Customer.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,7 @@ protected function _prepareDataForUpdate(array $rowData)
461461
$attribute->getBackend()->beforeSave($this->_customerModel->setData($attributeCode, $value));
462462
$value = $this->_customerModel->getData($attributeCode);
463463
}
464-
$attributesToSave[$attribute->getBackend()
465-
->getTable()][$entityId][$attributeParameters['id']] = $value;
464+
$attributesToSave[$attribute->getBackend()->getTable()][$entityId][$attributeParameters['id']] = $value;
466465

467466
// restore 'backend_model' to avoid default setting
468467
$attribute->setBackendModel($backendModel);
@@ -617,7 +616,7 @@ protected function _validateRowForUpdate(array $rowData, $rowNumber)
617616
$isFieldRequired = $attributeParams['is_required'];
618617
$isFieldNotSetAndCustomerDoesNotExist =
619618
!isset($rowData[$attributeCode]) && !$this->_getCustomerId($email, $website);
620-
$isFieldSetAndTrimmedValueIsEmpty = true;
619+
$isFieldSetAndTrimmedValueIsEmpty = false;
621620
$isFieldValueNotEmpty = false;
622621

623622
if (isset($rowData[$attributeCode])) {
@@ -626,7 +625,7 @@ protected function _validateRowForUpdate(array $rowData, $rowNumber)
626625
$isFieldValueNotEmpty = count(array_filter($rowData[$attributeCode], 'strlen')) > 0;
627626
} else {
628627
$isFieldSetAndTrimmedValueIsEmpty = '' === trim((string)$rowData[$attributeCode]);
629-
$isFieldValueNotEmpty = strlen($rowData[$attributeCode]) > 0;
628+
$isFieldValueNotEmpty = strlen((string)$rowData[$attributeCode]) > 0;
630629
}
631630
}
632631

app/code/Magento/DownloadableImportExport/Model/Import/Product/Type/Downloadable.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ protected function prepareSampleData($rowCol, $entityId = null)
831831
* Prepare samples data in structured format.
832832
*
833833
* @param array $samples
834-
* @param $entityId
834+
* @param string|int|null $entityId
835835
* @return array
836836
*/
837837
private function prepareStructuredSampleData(array $samples, $entityId = null): array
@@ -885,7 +885,7 @@ protected function prepareLinkData($rowCol, $entityId = null)
885885
* Prepare links data in structured format.
886886
*
887887
* @param array $links
888-
* @param $entityId
888+
* @param string|int|null $entityId
889889
* @return array
890890
*/
891891
private function prepareStructuredLinkData(array $links, $entityId = null): array

app/code/Magento/ImportExport/Model/Import/AbstractEntity.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
* @api
2929
* @SuppressWarnings(PHPMD.TooManyFields)
3030
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
31+
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
3132
* @since 100.0.2
3233
*/
3334
abstract class AbstractEntity implements EntityInterface
@@ -522,7 +523,7 @@ private function validateEncoding(array|string|null $element, string $attrName):
522523
);
523524
return false;
524525
}
525-
} elseif (is_null($element)) {
526+
} elseif ($element === null) {
526527
return true;
527528
}
528529

lib/internal/Magento/Framework/Reflection/TypeProcessor.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class TypeProcessor
3131
public const INT_TYPE = 'integer';
3232
public const BOOLEAN_TYPE = 'bool';
3333
public const ANY_TYPE = 'mixed';
34+
public const UNSTRUCTURED_ARRAY = 'UnstructuredArray';
3435
/**#@-*/
3536

3637
/**#@+
@@ -144,7 +145,8 @@ public function register($type)
144145
}
145146
if (!$this->isTypeSimple($typeName) && !$this->isTypeAny($typeName)) {
146147
$typeSimple = $this->getArrayItemType($type);
147-
if (!(class_exists($typeSimple) || interface_exists($typeSimple))) {
148+
if (!(class_exists($typeSimple) || interface_exists($typeSimple))
149+
&& ($typeSimple !== self::UNSTRUCTURED_ARRAY)) {
148150
throw new \LogicException(
149151
sprintf(
150152
'The "%s" class doesn\'t exist and the namespace must be specified. Verify and try again.',
@@ -174,6 +176,11 @@ protected function _processComplexType($class)
174176
{
175177
$typeName = $this->translateTypeName($class);
176178
$this->_types[$typeName] = [];
179+
if ($typeName === self::UNSTRUCTURED_ARRAY) {
180+
$this->_types[$typeName]['documentation'] = '';
181+
$this->_types[$typeName]['parameters'] = [];
182+
return $this->_types[$typeName];
183+
}
177184
if ($this->isArrayType($class)) {
178185
$this->register($this->getArrayItemType($class));
179186
} else {
@@ -448,6 +455,9 @@ public function translateTypeName($class)
448455

449456
return ucfirst($moduleNamespace . $moduleName . implode('', $typeNameParts));
450457
}
458+
if ($class === self::UNSTRUCTURED_ARRAY) {
459+
return $class;
460+
}
451461
throw new \InvalidArgumentException(
452462
sprintf('The "%s" parameter type is invalid. Verify the parameter and try again.', $class)
453463
);

0 commit comments

Comments
 (0)