Skip to content

Commit 7723dff

Browse files
committed
MAGETWO-69857: Issue with importing customer address
1 parent 409eef5 commit 7723dff

File tree

3 files changed

+45
-8
lines changed

3 files changed

+45
-8
lines changed

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Framework\App\ObjectManager;
1111
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
1212
use Magento\Store\Model\Store;
13+
use Magento\ImportExport\Model\Import;
1314

1415
/**
1516
* @SuppressWarnings(PHPMD.TooManyFields)
@@ -21,7 +22,7 @@ class Address extends AbstractCustomer
2122
/**#@+
2223
* Attribute collection name
2324
*/
24-
const ATTRIBUTE_COLLECTION_NAME = 'Magento\Customer\Model\ResourceModel\Address\Attribute\Collection';
25+
const ATTRIBUTE_COLLECTION_NAME = \Magento\Customer\Model\ResourceModel\Address\Attribute\Collection::class;
2526

2627
/**#@-*/
2728

@@ -625,6 +626,15 @@ protected function _prepareDataForUpdate(array $rowData)
625626
} elseif ('datetime' == $attributeParams['type']) {
626627
$value = (new \DateTime())->setTimestamp(strtotime($rowData[$attributeAlias]));
627628
$value = $value->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT);
629+
} elseif ('multiselect' == $attributeParams['type']) {
630+
$separator = isset($this->_parameters[Import::FIELD_FIELD_MULTIPLE_VALUE_SEPARATOR]) ?
631+
$this->_parameters[Import::FIELD_FIELD_MULTIPLE_VALUE_SEPARATOR] :
632+
Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR;
633+
$value = str_replace(
634+
$separator,
635+
Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR,
636+
$rowData[$attributeAlias]
637+
);
628638
} else {
629639
$value = $rowData[$attributeAlias];
630640
}
@@ -839,7 +849,16 @@ protected function _validateRowForUpdate(array $rowData, $rowNumber)
839849
continue;
840850
}
841851
if (isset($rowData[$attributeCode]) && strlen($rowData[$attributeCode])) {
842-
$this->isAttributeValid($attributeCode, $attributeParams, $rowData, $rowNumber);
852+
$multiSeparator = isset($this->_parameters[Import::FIELD_FIELD_MULTIPLE_VALUE_SEPARATOR]) ?
853+
$this->_parameters[Import::FIELD_FIELD_MULTIPLE_VALUE_SEPARATOR] :
854+
Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR;
855+
$this->isAttributeValid(
856+
$attributeCode,
857+
$attributeParams,
858+
$rowData,
859+
$rowNumber,
860+
$multiSeparator
861+
);
843862
} elseif ($attributeParams['is_required'] && (!isset(
844863
$this->_addresses[$customerId]
845864
) || !in_array(

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingError;
99
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
1010
use Magento\Framework\App\ResourceConnection;
11+
use Magento\ImportExport\Model\Import;
1112

1213
/**
1314
* Import entity abstract model
@@ -638,11 +639,17 @@ public function getMasterAttributeCode()
638639
* @param array $attributeParams Attribute params
639640
* @param array $rowData Row data
640641
* @param int $rowNumber
642+
* @param string $multiSeparator
641643
* @return bool
642644
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
643645
*/
644-
public function isAttributeValid($attributeCode, array $attributeParams, array $rowData, $rowNumber)
645-
{
646+
public function isAttributeValid(
647+
$attributeCode,
648+
array $attributeParams,
649+
array $rowData,
650+
$rowNumber,
651+
$multiSeparator = Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR
652+
) {
646653
$message = '';
647654
switch ($attributeParams['type']) {
648655
case 'varchar':
@@ -657,7 +664,13 @@ public function isAttributeValid($attributeCode, array $attributeParams, array $
657664
break;
658665
case 'select':
659666
case 'multiselect':
660-
$valid = isset($attributeParams['options'][strtolower($rowData[$attributeCode])]);
667+
$valid = true;
668+
foreach (explode($multiSeparator, strtolower($rowData[$attributeCode])) as $value) {
669+
$valid = isset($attributeParams['options'][$value]);
670+
if (!$valid) {
671+
break;
672+
}
673+
}
661674
$message = self::ERROR_INVALID_ATTRIBUTE_OPTION;
662675
break;
663676
case 'int':

app/code/Magento/ImportExport/Model/Import/Entity/AbstractEav.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ abstract class AbstractEav extends \Magento\ImportExport\Model\Import\AbstractEn
1616
/**
1717
* Attribute collection name
1818
*/
19-
const ATTRIBUTE_COLLECTION_NAME = 'Magento\Framework\Data\Collection';
19+
const ATTRIBUTE_COLLECTION_NAME = \Magento\Framework\Data\Collection::class;
2020

2121
/**
2222
* Store manager
@@ -222,9 +222,14 @@ public function getAttributeOptions(
222222
foreach ($attribute->getSource()->getAllOptions(false) as $option) {
223223
$value = is_array($option['value']) ? $option['value'] : [$option];
224224
foreach ($value as $innerOption) {
225+
// skip ' -- Please Select -- ' option
225226
if (strlen($innerOption['value'])) {
226-
// skip ' -- Please Select -- ' option
227-
$options[strtolower($innerOption[$index])] = $innerOption['value'];
227+
if ($attribute->isStatic()) {
228+
$options[strtolower($innerOption[$index])] = $innerOption['value'];
229+
} else {
230+
// Non-static attributes flip keys an values
231+
$options[$innerOption['value']] = $innerOption[$index];
232+
}
228233
}
229234
}
230235
}

0 commit comments

Comments
 (0)