Skip to content

Commit 0239ea5

Browse files
Merge remote-tracking branch 'remotes/github/MC-15256' into EPAM-PR-74
2 parents fe280cf + 81c3ae3 commit 0239ea5

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

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

Lines changed: 11 additions & 3 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\CustomerImportExport\Model\Import;
79

810
use Magento\Customer\Api\Data\CustomerInterface;
@@ -21,7 +23,7 @@
2123
class Customer extends AbstractCustomer
2224
{
2325
/**
24-
* Attribute collection name
26+
* Collection name attribute
2527
*/
2628
const ATTRIBUTE_COLLECTION_NAME = \Magento\Customer\Model\ResourceModel\Attribute\Collection::class;
2729

@@ -519,8 +521,10 @@ protected function _importData()
519521
);
520522
} elseif ($this->getBehavior($rowData) == \Magento\ImportExport\Model\Import::BEHAVIOR_ADD_UPDATE) {
521523
$processedData = $this->_prepareDataForUpdate($rowData);
524+
// phpcs:disable Magento2.Performance.ForeachArrayMerge
522525
$entitiesToCreate = array_merge($entitiesToCreate, $processedData[self::ENTITIES_TO_CREATE_KEY]);
523526
$entitiesToUpdate = array_merge($entitiesToUpdate, $processedData[self::ENTITIES_TO_UPDATE_KEY]);
527+
// phpcs:enable
524528
foreach ($processedData[self::ATTRIBUTES_TO_SAVE_KEY] as $tableName => $customerAttributes) {
525529
if (!isset($attributesToSave[$tableName])) {
526530
$attributesToSave[$tableName] = [];
@@ -598,14 +602,18 @@ protected function _validateRowForUpdate(array $rowData, $rowNumber)
598602
$isFieldNotSetAndCustomerDoesNotExist =
599603
!isset($rowData[$attributeCode]) && !$this->_getCustomerId($email, $website);
600604
$isFieldSetAndTrimmedValueIsEmpty
601-
= isset($rowData[$attributeCode]) && '' === trim($rowData[$attributeCode]);
605+
= isset($rowData[$attributeCode]) && '' === trim((string)$rowData[$attributeCode]);
602606

603607
if ($isFieldRequired && ($isFieldNotSetAndCustomerDoesNotExist || $isFieldSetAndTrimmedValueIsEmpty)) {
604608
$this->addRowError(self::ERROR_VALUE_IS_REQUIRED, $rowNumber, $attributeCode);
605609
continue;
606610
}
607611

608-
if (isset($rowData[$attributeCode]) && strlen($rowData[$attributeCode])) {
612+
if (isset($rowData[$attributeCode]) && strlen((string)$rowData[$attributeCode])) {
613+
if ($attributeParams['type'] == 'select') {
614+
continue;
615+
}
616+
609617
$this->isAttributeValid(
610618
$attributeCode,
611619
$attributeParams,

dev/tests/integration/testsuite/Magento/Customer/_files/import_export/customer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
)->setLastname(
3131
'Alston'
3232
)->setGender(
33-
2
33+
'2'
3434
);
3535
$customer->isObjectNew(true);
3636

dev/tests/integration/testsuite/Magento/CustomerImportExport/Model/Import/CustomerTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function testImportData()
7878
$expectAddedCustomers = 5;
7979

8080
$source = new \Magento\ImportExport\Model\Import\Source\Csv(
81-
__DIR__ . '/_files/customers_to_import.csv',
81+
__DIR__ . '/_files/customers_with_gender_to_import.csv',
8282
$this->directoryWrite
8383
);
8484

@@ -133,6 +133,11 @@ public function testImportData()
133133
$updatedCustomer->getCreatedAt(),
134134
'Creation date must be changed'
135135
);
136+
$this->assertEquals(
137+
$existingCustomer->getGender(),
138+
$updatedCustomer->getGender(),
139+
'Gender must be changed'
140+
);
136141
}
137142

138143
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
email,_website,_store,confirmation,created_at,created_in,default_billing,default_shipping,disable_auto_group_change,dob,firstname,gender,group_id,lastname,middlename,password_hash,prefix,rp_token,rp_token_created_at,store_id,suffix,taxvat,website_id,password
2+
[email protected],base,admin,,5/6/2012 15:53,Admin,1,1,0,5/6/2010,Anthony,Female,1,Nealy,A.,6a9c9bfb2ba88a6ad2a64e7402df44a763e0c48cd21d7af9e7e796cd4677ee28:RF,,,,0,,,1,
3+
[email protected],admin,admin,,5/6/2012 15:59,Admin,3,3,0,5/6/2010,Lori,Female,1,Banks,B.,7ad6dbdc83d3e9f598825dc58b84678c7351e4281f6bc2b277a32dcd88b9756b:pz,,,,0,,,0,
4+
[email protected],base,admin,,5/6/2012 16:13,Admin,4,4,0,,Jhon,Female,1,Doe,T.,145d12bfff8a6a279eb61e277e3d727c0ba95acc1131237f1594ddbb7687a564:l1,,,,0,,,2,
5+
[email protected],base,admin,,5/6/2012 16:15,Admin,4,4,0,,Firstname,Female,1,Lastname,T.,145d12bfff8a6a279eb61e277e3d727c0ba95acc1131237f1594ddbb7687a564:l1,,,,0,,,2,
6+
[email protected],base,admin,,5/6/2012 16:19,Admin,4,4,0,,Julie,Female,1,Worrell,T.,145d12bfff8a6a279eb61e277e3d727c0ba95acc1131237f1594ddbb7687a564:l1,,,,0,,,2,
7+
[email protected],base,admin,,5/6/2012 16:25,Admin,4,4,0,,David,,1,Lamar,T.,145d12bfff8a6a279eb61e277e3d727c0ba95acc1131237f1594ddbb7687a564:l1,,,,0,,,2,

0 commit comments

Comments
 (0)