Skip to content

Commit 08e0f3c

Browse files
committed
ACPT-1424: Import Customer Addresses
1 parent 167bc3f commit 08e0f3c

File tree

2 files changed

+57
-14
lines changed

2 files changed

+57
-14
lines changed

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,8 @@ protected function _prepareDataForUpdate(array $rowData): array
634634

635635
$value = $rowData[$attributeAlias];
636636

637-
if ($rowData[$attributeAlias] === null || !strlen($rowData[$attributeAlias])) {
637+
if ($rowData[$attributeAlias] === null
638+
|| (is_string($rowData[$attributeAlias]) && !strlen($rowData[$attributeAlias]))) {
638639
if ($attributeParams['is_required']) {
639640
continue;
640641
}
@@ -689,12 +690,12 @@ protected function _prepareDataForUpdate(array $rowData): array
689690
/**
690691
* Process row data, based on attirbute type
691692
*
692-
* @param string $rowAttributeData
693+
* @param string|array $rowAttributeData
693694
* @param array $attributeParams
694695
* @return \DateTime|int|string
695696
* @throws \Exception
696697
*/
697-
protected function getValueByAttributeType(string $rowAttributeData, array $attributeParams)
698+
protected function getValueByAttributeType($rowAttributeData, array $attributeParams)
698699
{
699700
$multiSeparator = $this->getMultipleValueSeparator();
700701
$value = $rowAttributeData;
@@ -709,8 +710,14 @@ protected function getValueByAttributeType(string $rowAttributeData, array $attr
709710
break;
710711
case 'multiselect':
711712
$ids = [];
712-
foreach (explode($multiSeparator, mb_strtolower($rowAttributeData)) as $subValue) {
713-
$ids[] = $this->getSelectAttrIdByValue($attributeParams, $subValue);
713+
if (is_array($rowAttributeData)) {
714+
foreach ($rowAttributeData as $subValue) {
715+
$ids[] = $this->getSelectAttrIdByValue($attributeParams, mb_strtolower($subValue));
716+
}
717+
} elseif (is_string($rowAttributeData)) {
718+
foreach (explode($multiSeparator, mb_strtolower($rowAttributeData)) as $subValue) {
719+
$ids[] = $this->getSelectAttrIdByValue($attributeParams, $subValue);
720+
}
714721
}
715722
$value = implode(',', $ids);
716723
break;
@@ -880,7 +887,9 @@ protected function _validateRowForUpdate(array $rowData, $rowNumber)
880887

881888
if (in_array($attributeCode, $this->_ignoredAttributes)) {
882889
continue;
883-
} elseif (isset($rowData[$attributeCode]) && strlen($rowData[$attributeCode])) {
890+
} elseif (isset($rowData[$attributeCode])
891+
&& ((is_string($rowData[$attributeCode]) && strlen($rowData[$attributeCode]))
892+
|| (is_array($rowData[$attributeCode]) && count($rowData[$attributeCode])))) {
884893
$this->isAttributeValid(
885894
$attributeCode,
886895
$attributeParams,

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

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\ImportExport\Model\Import;
79

810
use Magento\Framework\App\Config\ScopeConfigInterface;
@@ -440,17 +442,13 @@ protected function _saveValidatedBunches()
440442
$startNewBunch = false;
441443
}
442444
if ($source->valid()) {
443-
$valid = true;
444445
try {
445446
$rowData = $source->current();
447+
$valid = true;
446448
foreach ($rowData as $attrName => $element) {
447-
if (!mb_check_encoding($element, 'UTF-8')) {
448-
$valid = false;
449-
$this->addRowError(
450-
AbstractEntity::ERROR_CODE_ILLEGAL_CHARACTERS,
451-
$this->_processedRowsCount,
452-
$attrName
453-
);
449+
$valid = $this->validateEncoding($element, $attrName);
450+
if (!$valid) {
451+
break;
454452
}
455453
}
456454
} catch (\InvalidArgumentException $e) {
@@ -495,6 +493,42 @@ protected function _saveValidatedBunches()
495493
return $this;
496494
}
497495

496+
/**
497+
* Validates encoding.
498+
*
499+
* @param array|string|null $element
500+
* @param string $attrName
501+
* @return bool
502+
*/
503+
private function validateEncoding(array|string|null $element, string $attrName): bool
504+
{
505+
if (is_array($element)) {
506+
foreach ($element as $value) {
507+
if (!mb_check_encoding($value, 'UTF-8')) {
508+
$this->addRowError(
509+
AbstractEntity::ERROR_CODE_ILLEGAL_CHARACTERS,
510+
$this->_processedRowsCount,
511+
$attrName
512+
);
513+
return false;
514+
}
515+
}
516+
} elseif (is_string($element)) {
517+
if (!mb_check_encoding($element, 'UTF-8')) {
518+
$this->addRowError(
519+
AbstractEntity::ERROR_CODE_ILLEGAL_CHARACTERS,
520+
$this->_processedRowsCount,
521+
$attrName
522+
);
523+
return false;
524+
}
525+
} elseif (is_null($element)) {
526+
return true;
527+
}
528+
529+
return true;
530+
}
531+
498532
/**
499533
* Add error with corresponding current data source row number.
500534
*

0 commit comments

Comments
 (0)