163 'rp_token_created_at',
200 $this->_resourceHelper = $resourceHelper;
202 if (isset(
$data[
'attribute_collection'])) {
203 $this->_attributeCollection =
$data[
'attribute_collection'];
204 unset(
$data[
'attribute_collection']);
206 $this->_attributeCollection = $attrCollectionFactory->create();
207 $this->_attributeCollection->addSystemHiddenFilterWithPasswordHash();
229 $this->_indexValueAttributes[] =
'group_id';
232 self::ERROR_DUPLICATE_EMAIL_SITE,
233 __(
'This email is found more than once in the import file.')
236 self::ERROR_ROW_IS_ORPHAN,
237 __(
'Orphan rows that will be skipped due default row errors')
240 self::ERROR_INVALID_STORE,
241 __(
'Invalid value in Store column (store does not exists?)')
244 self::ERROR_EMAIL_SITE_NOT_FOUND,
245 __(
'We can\'t find that email and website combination.')
247 $this->
addMessageTemplate(self::ERROR_PASSWORD_LENGTH,
__(
'Please enter a password with a valid length.'));
249 $this->_initStores(
true)->_initAttributes();
253 $customerResource = $this->_customerModel->getResource();
254 $this->_entityTable = $customerResource->getEntityTable();
266 if ($entitiesToCreate) {
267 $this->_connection->insertMultiple($this->_entityTable, $entitiesToCreate);
270 if ($entitiesToUpdate) {
271 $this->_connection->insertOnDuplicate(
274 $this->getCustomerEntityFieldsToUpdate($entitiesToUpdate)
287 private function getCustomerEntityFieldsToUpdate(array $entitiesToUpdate): array
289 $firstCustomer = reset($entitiesToUpdate);
290 $columnsToUpdate = array_keys($firstCustomer);
291 $customerFieldsToUpdate = array_filter($this->customerFields,
function ($field) use ($columnsToUpdate) {
292 return in_array($field, $columnsToUpdate);
294 return $customerFieldsToUpdate;
312 'attribute_id' => $attributeId,
317 $this->_connection->insertOnDuplicate(
$tableName, $tableData, [
'value']);
330 $condition = $this->_connection->quoteInto(
'entity_id IN (?)', $entitiesToDelete);
331 $this->_connection->delete($this->_entityTable, $condition);
343 if (!$this->_nextEntityId) {
344 $this->_nextEntityId = $this->_resourceHelper->getNextAutoincrement($this->_entityTable);
346 return $this->_nextEntityId++;
359 $customersPresent = [];
360 foreach ($rows as $rowData) {
361 $email = $rowData[static::COLUMN_EMAIL] ??
null;
362 $websiteId = isset($rowData[static::COLUMN_WEBSITE])
363 ? $this->
getWebsiteId($rowData[static::COLUMN_WEBSITE]) :
false;
365 $customersPresent[] = [
382 return parent::validateData();
393 protected function _prepareDataForUpdate(array $rowData)
396 $entitiesToCreate = [];
397 $entitiesToUpdate = [];
398 $attributesToSave = [];
401 $now = new \DateTime();
402 if (empty($rowData[
'created_at'])) {
405 $createdAt = (new \DateTime())->setTimestamp(strtotime($rowData[
'created_at']));
408 $emailInLowercase = strtolower($rowData[self::COLUMN_EMAIL]);
409 $newCustomer =
false;
410 $entityId = $this->
_getCustomerId($emailInLowercase, $rowData[self::COLUMN_WEBSITE]);
419 if (isset($rowData[
'password']) && strlen($rowData[
'password'])) {
420 $rowData[
'password_hash'] = $this->_customerModel->hashPassword($rowData[
'password']);
422 $entityRow = [
'entity_id' => $entityId];
426 if (in_array($attributeParameters[
'type'], [
'select',
'boolean'])) {
428 }
elseif (
'multiselect' == $attributeParameters[
'type']) {
430 foreach (explode($multiSeparator, mb_strtolower(
$value)) as $subValue) {
433 $value = implode(
',', $ids);
434 }
elseif (
'datetime' == $attributeParameters[
'type'] && !empty(
$value)) {
435 $value = (new \DateTime())->setTimestamp(strtotime(
$value));
442 $backendModel =
$attribute->getBackendModel();
445 &&
$attribute->getFrontendInput() !=
'datetime') {
450 ->getTable()][$entityId][$attributeParameters[
'id']] =
$value;
462 $entityRow[
'store_id'] = empty($rowData[self::COLUMN_STORE])
464 $entityRow[
'created_at'] = $createdAt->format(\
Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT);
465 $entityRow[
'updated_at'] = $now->format(\
Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT);
467 $entityRow[
'email'] = $emailInLowercase;
468 $entityRow[
'is_active'] = 1;
469 $entitiesToCreate[] = $entityRow;
472 $entityRow[
'updated_at'] = $now->format(\
Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT);
473 if (!empty($rowData[self::COLUMN_STORE])) {
476 $entitiesToUpdate[] = $entityRow;
480 self::ENTITIES_TO_CREATE_KEY => $entitiesToCreate,
481 self::ENTITIES_TO_UPDATE_KEY => $entitiesToUpdate,
482 self::ATTRIBUTES_TO_SAVE_KEY => $attributesToSave
495 while ($bunch = $this->_dataSourceModel->getNextBunch()) {
497 $entitiesToCreate = [];
498 $entitiesToUpdate = [];
499 $entitiesToDelete = [];
500 $attributesToSave = [];
502 foreach ($bunch as $rowNumber => $rowData) {
513 $rowData[self::COLUMN_EMAIL],
514 $rowData[self::COLUMN_WEBSITE]
517 $processedData = $this->_prepareDataForUpdate($rowData);
518 $entitiesToCreate = array_merge($entitiesToCreate, $processedData[self::ENTITIES_TO_CREATE_KEY]);
519 $entitiesToUpdate = array_merge($entitiesToUpdate, $processedData[self::ENTITIES_TO_UPDATE_KEY]);
520 foreach ($processedData[self::ATTRIBUTES_TO_SAVE_KEY] as
$tableName => $customerAttributes) {
524 $attributesToSave[
$tableName] = array_diff_key(
527 ) + $customerAttributes;
535 if ($entitiesToCreate || $entitiesToUpdate) {
538 if ($attributesToSave) {
541 if ($entitiesToDelete) {
556 return $this->_attributeCollection->getEntityTypeCode();
571 $email = strtolower($rowData[self::COLUMN_EMAIL]);
574 if (isset($this->_newCustomers[strtolower($rowData[self::COLUMN_EMAIL])][
$website])) {
575 $this->
addRowError(self::ERROR_DUPLICATE_EMAIL_SITE, $rowNumber);
579 if (!empty($rowData[self::COLUMN_STORE]) && !isset($this->_storeCodeToId[$rowData[self::COLUMN_STORE]])) {
580 $this->
addRowError(self::ERROR_INVALID_STORE, $rowNumber);
587 ) && $this->string->strlen(
591 $this->
addRowError(self::ERROR_PASSWORD_LENGTH, $rowNumber);
594 foreach ($this->_attributes as
$attributeCode => $attributeParams) {
599 $isFieldRequired = $attributeParams[
'is_required'];
600 $isFieldNotSetAndCustomerDoesNotExist =
602 $isFieldSetAndTrimmedValueIsEmpty
605 if ($isFieldRequired && ($isFieldNotSetAndCustomerDoesNotExist || $isFieldSetAndTrimmedValueIsEmpty)) {
635 if (!$this->
_getCustomerId($rowData[self::COLUMN_EMAIL], $rowData[self::COLUMN_WEBSITE])) {
636 $this->
addRowError(self::ERROR_CUSTOMER_NOT_FOUND, $rowNumber);
658 $this->validColumnNames,
659 $this->customerFields
const ERROR_ROW_IS_ORPHAN
const ERROR_DUPLICATE_EMAIL_SITE
isAttributeValid( $attributeCode, array $attributeParams, array $rowData, $rowNumber, $multiSeparator=Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR)
elseif(isset( $params[ 'redirect_parent']))
getMultipleValueSeparator()
const BEHAVIOR_ADD_UPDATE
addRowError( $errorCode, $errorRowNum, $colName=null, $errorMessage=null, $errorLevel=ProcessingError::ERROR_LEVEL_CRITICAL, $errorDescription=null)
_validateRowForUpdate(array $rowData, $rowNumber)
const COLUMN_DEFAULT_BILLING
_checkUniqueKey(array $rowData, $rowNumber)
const DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR
const FIELD_FIELD_MULTIPLE_VALUE_SEPARATOR
const COLUMN_DEFAULT_SHIPPING
getWebsiteId($websiteCode)
const ATTRIBUTE_COLLECTION_NAME
getBehavior(array $rowData=null)
const ERROR_EMAIL_SITE_NOT_FOUND
const MIN_PASSWORD_LENGTH
const ERROR_INVALID_STORE
const ERROR_PASSWORD_LENGTH
_saveCustomerAttributes(array $attributesData)
getSelectAttrIdByValue(array $attributeParameters, $value)
const ENTITIES_TO_CREATE_KEY
addMessageTemplate($errorCode, $message)
_getCustomerId($email, $websiteCode)
updateItemsCounterStats(array $created=[], array $updated=[], array $deleted=[])
const ATTRIBUTES_TO_SAVE_KEY
__construct(\Magento\Framework\Stdlib\StringUtils $string, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\ImportExport\Model\ImportFactory $importFactory, \Magento\ImportExport\Model\ResourceModel\Helper $resourceHelper, \Magento\Framework\App\ResourceConnection $resource, ProcessingErrorAggregatorInterface $errorAggregator, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\ImportExport\Model\Export\Factory $collectionFactory, \Magento\Eav\Model\Config $eavConfig, \Magento\CustomerImportExport\Model\ResourceModel\Import\Customer\StorageFactory $storageFactory, array $data=[])
prepareCustomerData($rows)
_validateRowForDelete(array $rowData, $rowNumber)
const ENTITIES_TO_UPDATE_KEY
_saveCustomerEntities(array $entitiesToCreate, array $entitiesToUpdate)
validateRow(array $rowData, $rowNumber)
_deleteCustomerEntities(array $entitiesToDelete)