diff --git a/app/code/Magento/CustomerImportExport/Model/Import/Customer.php b/app/code/Magento/CustomerImportExport/Model/Import/Customer.php index 6cf06f839c175efd29b42a98d63b1ecf8f959b82..ef92b5194c5d004e1fbbaa8bc4b86f0c14a78292 100644 --- a/app/code/Magento/CustomerImportExport/Model/Import/Customer.php +++ b/app/code/Magento/CustomerImportExport/Model/Import/Customer.php @@ -5,6 +5,7 @@ */ namespace Magento\CustomerImportExport\Model\Import; +use Magento\Customer\Api\Data\CustomerInterface; use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface; /** @@ -135,25 +136,25 @@ class Customer extends AbstractCustomer /** * Customer fields in file */ - public $customerFields = [ - 'group_id', - 'store_id', - 'updated_at', - 'created_at', - 'created_in', - 'prefix', - 'firstname', - 'middlename', - 'lastname', - 'suffix', - 'dob', + protected $customerFields = [ + CustomerInterface::GROUP_ID, + CustomerInterface::STORE_ID, + CustomerInterface::UPDATED_AT, + CustomerInterface::CREATED_AT, + CustomerInterface::CREATED_IN, + CustomerInterface::PREFIX, + CustomerInterface::FIRSTNAME, + CustomerInterface::MIDDLENAME, + CustomerInterface::LASTNAME, + CustomerInterface::SUFFIX, + CustomerInterface::DOB, 'password_hash', - 'taxvat', - 'confirmation', - 'gender', + CustomerInterface::TAXVAT, + CustomerInterface::CONFIRMATION, + CustomerInterface::GENDER, 'rp_token', 'rp_token_created_at', - ]; + ]; /** * @param \Magento\Framework\Stdlib\StringUtils $string @@ -237,11 +238,6 @@ class Customer extends AbstractCustomer $this->_initStores(true)->_initAttributes(); - $this->validColumnNames = array_merge( - $this->validColumnNames, - $this->customerFields - ); - $this->_customerModel = $customerFactory->create(); /** @var $customerResource \Magento\Customer\Model\ResourceModel\Customer */ $customerResource = $this->_customerModel->getResource(); @@ -562,4 +558,17 @@ class Customer extends AbstractCustomer { return $this->_entityTable; } + + /** + * @inheritDoc + */ + public function getValidColumnNames() + { + $this->validColumnNames = array_merge( + $this->validColumnNames, + $this->customerFields + ); + + return $this->validColumnNames; + } } diff --git a/app/code/Magento/CustomerImportExport/Model/Import/CustomerComposite.php b/app/code/Magento/CustomerImportExport/Model/Import/CustomerComposite.php index ed7d2f8fe9e85b92ffaf8da22c75b85fb9ffa7b2..97d2407a7805cf8b671ed7588f9d5d27c7823319 100644 --- a/app/code/Magento/CustomerImportExport/Model/Import/CustomerComposite.php +++ b/app/code/Magento/CustomerImportExport/Model/Import/CustomerComposite.php @@ -224,13 +224,6 @@ class CustomerComposite extends \Magento\ImportExport\Model\Import\AbstractEntit } $this->_initAddressAttributes(); - $this->validColumnNames = array_merge( - $this->validColumnNames, - $this->_customerAttributes, - $this->_addressAttributes, - $this->_customerEntity->customerFields - ); - // next customer id if (isset($data['next_customer_id'])) { $this->_nextCustomerId = $data['next_customer_id']; @@ -489,4 +482,19 @@ class CustomerComposite extends \Magento\ImportExport\Model\Import\AbstractEntit return parent::_prepareRowForDb($rowData); } + + /** + * @inheritDoc + */ + public function getValidColumnNames() + { + $this->validColumnNames = array_merge( + $this->validColumnNames, + $this->_customerAttributes, + $this->_addressAttributes, + $this->_customerEntity->customerFields + ); + + return $this->validColumnNames; + } } diff --git a/app/code/Magento/ImportExport/Model/Import/AbstractEntity.php b/app/code/Magento/ImportExport/Model/Import/AbstractEntity.php index e9b684c2bd2a9aeb74dbbc6368c7ff6c0e6b71a5..085c9261e341229fb19bebc078874f87e9dff561 100644 --- a/app/code/Magento/ImportExport/Model/Import/AbstractEntity.php +++ b/app/code/Magento/ImportExport/Model/Import/AbstractEntity.php @@ -792,7 +792,7 @@ abstract class AbstractEntity $emptyHeaderColumns[] = $columnNumber; } elseif (!preg_match('/^[a-z][a-z0-9_]*$/', $columnName)) { $invalidColumns[] = $columnName; - } elseif ($this->needColumnCheck && !in_array($columnName, $this->validColumnNames)) { + } elseif ($this->needColumnCheck && !in_array($columnName, $this->getValidColumnNames())) { $invalidAttributes[] = $columnName; } } @@ -854,4 +854,14 @@ abstract class AbstractEntity $this->countItemsDeleted = count($deleted); return $this; } + + /** + * Retrieve valid column names + * + * @return array + */ + public function getValidColumnNames() + { + return $this->validColumnNames; + } } diff --git a/app/code/Magento/ImportExport/Model/Import/Entity/AbstractEntity.php b/app/code/Magento/ImportExport/Model/Import/Entity/AbstractEntity.php index 81422c45e13a871f8162a0535802db1cf96a2df5..9a0971d18e1042fea2339d50508d0816e2cbdac9 100644 --- a/app/code/Magento/ImportExport/Model/Import/Entity/AbstractEntity.php +++ b/app/code/Magento/ImportExport/Model/Import/Entity/AbstractEntity.php @@ -763,7 +763,7 @@ abstract class AbstractEntity $emptyHeaderColumns[] = $columnNumber; } elseif (!preg_match('/^[a-z][a-z0-9_]*$/', $columnName)) { $invalidColumns[] = $columnName; - } elseif ($this->needColumnCheck && !in_array($columnName, $this->validColumnNames)) { + } elseif ($this->needColumnCheck && !in_array($columnName, $this->getValidColumnNames())) { $invalidAttributes[] = $columnName; } } @@ -818,4 +818,14 @@ abstract class AbstractEntity { return $this->countItemsDeleted; } + + /** + * Retrieve valid column names + * + * @return array + */ + public function getValidColumnNames() + { + return $this->validColumnNames; + } }