From d6c6e66da1d1c42f23a8eec44e71526826b9d46e Mon Sep 17 00:00:00 2001 From: alojua Date: Thu, 2 Nov 2017 18:23:17 +0100 Subject: [PATCH 1/2] Fix bug that deletes exiting customer entity Fields, if the columns are not present on Import file --- .../CustomerImportExport/Model/Import/Customer.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/CustomerImportExport/Model/Import/Customer.php b/app/code/Magento/CustomerImportExport/Model/Import/Customer.php index bee4479526037..1122ac8f17826 100644 --- a/app/code/Magento/CustomerImportExport/Model/Import/Customer.php +++ b/app/code/Magento/CustomerImportExport/Model/Import/Customer.php @@ -270,13 +270,23 @@ protected function _saveCustomerEntities(array $entitiesToCreate, array $entitie $this->_connection->insertOnDuplicate( $this->_entityTable, $entitiesToUpdate, - $this->customerFields + $this->getCustomerEntityFieldsToUpdate($entitiesToUpdate) ); } return $this; } + private function getCustomerEntityFieldsToUpdate(array $entitiesToUpdate): array + { + $firstCustomer = reset($entitiesToUpdate); + $columnsToUpdate = array_keys($firstCustomer); + $customerFieldsToUpdate = array_filter($this->customerFields, function ($field) use ($columnsToUpdate) { + return in_array($field, $columnsToUpdate); + }); + return $customerFieldsToUpdate; + } + /** * Save customer attributes. * From 3ae078594c051c551d6b00d6bddc231561465839 Mon Sep 17 00:00:00 2001 From: David Manners Date: Thu, 9 Nov 2017 13:37:44 +0000 Subject: [PATCH 2/2] Filter the import to make sure we only update fields present in the import file. - https://github.com/magento/magento2/pull/11968 - Importing a import file to update customer data, results in entity fields being removed if the columns are not present on the imported file. --- .../Magento/CustomerImportExport/Model/Import/Customer.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/code/Magento/CustomerImportExport/Model/Import/Customer.php b/app/code/Magento/CustomerImportExport/Model/Import/Customer.php index 1122ac8f17826..016dca2fa526c 100644 --- a/app/code/Magento/CustomerImportExport/Model/Import/Customer.php +++ b/app/code/Magento/CustomerImportExport/Model/Import/Customer.php @@ -277,6 +277,12 @@ protected function _saveCustomerEntities(array $entitiesToCreate, array $entitie return $this; } + /** + * Filter the entity that are being updated so we only change fields found in the importer file + * + * @param array $entitiesToUpdate + * @return array + */ private function getCustomerEntityFieldsToUpdate(array $entitiesToUpdate): array { $firstCustomer = reset($entitiesToUpdate);