diff --git a/vendor/magento/module-customer-import-export/Model/Import/AbstractCustomer.php b/vendor/magento/module-customer-import-export/Model/Import/AbstractCustomer.php index 8fb08cecc54c..1b5674b85fe4 100644 --- a/vendor/magento/module-customer-import-export/Model/Import/AbstractCustomer.php +++ b/vendor/magento/module-customer-import-export/Model/Import/AbstractCustomer.php @@ -6,6 +6,8 @@ namespace Magento\CustomerImportExport\Model\Import; +use Magento\Customer\Model\Config\Share; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Validator\EmailAddress; use Magento\Framework\Validator\ValidateException; use Magento\Framework\Validator\ValidatorChain; @@ -87,6 +89,11 @@ abstract class AbstractCustomer extends \Magento\ImportExport\Model\Import\Entit */ protected $masterAttributeCode = '_email'; + /** + * @var Share + */ + private $configShare; + /** * @param \Magento\Framework\Stdlib\StringUtils $string * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig @@ -99,6 +106,7 @@ abstract class AbstractCustomer extends \Magento\ImportExport\Model\Import\Entit * @param \Magento\Eav\Model\Config $eavConfig * @param \Magento\CustomerImportExport\Model\ResourceModel\Import\Customer\StorageFactory $storageFactory * @param array $data + * @param Share|null $configShare * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -112,7 +120,8 @@ public function __construct( \Magento\ImportExport\Model\Export\Factory $collectionFactory, \Magento\Eav\Model\Config $eavConfig, \Magento\CustomerImportExport\Model\ResourceModel\Import\Customer\StorageFactory $storageFactory, - array $data = [] + array $data = [], + ?Share $configShare = null ) { $this->_storageFactory = $storageFactory; parent::__construct( @@ -127,7 +136,7 @@ public function __construct( $eavConfig, $data ); - + $this->configShare = $configShare ?? ObjectManager::getInstance()->get(Share::class); $this->addMessageTemplate(self::ERROR_WEBSITE_IS_EMPTY, __('Please specify a website.')); $this->addMessageTemplate( self::ERROR_EMAIL_IS_EMPTY, @@ -174,6 +183,11 @@ protected function _initCustomers(array $data) protected function _getCustomerId($email, $websiteCode) { $email = strtolower(trim($email)); + + if ($this->configShare->isGlobalScope()) { + return $this->_customerStorage->getCustomerIdByEmail($email); + } + if (isset($this->_websiteCodeToId[$websiteCode])) { $websiteId = $this->_websiteCodeToId[$websiteCode]; return $this->_customerStorage->getCustomerId($email, $websiteId); diff --git a/vendor/magento/module-customer-import-export/Model/Import/Address.php b/vendor/magento/module-customer-import-export/Model/Import/Address.php index 4ba93557f854..88483af46115 100644 --- a/vendor/magento/module-customer-import-export/Model/Import/Address.php +++ b/vendor/magento/module-customer-import-export/Model/Import/Address.php @@ -6,6 +6,7 @@ namespace Magento\CustomerImportExport\Model\Import; +use Magento\Customer\Model\Config\Share; use Magento\Customer\Model\ResourceModel\Address\Attribute\Source\CountryWithWebsites as CountryWithWebsitesSource; use Magento\Eav\Model\Entity\Attribute\AbstractAttribute; use Magento\Framework\App\ObjectManager; @@ -272,7 +273,8 @@ class Address extends AbstractCustomer * @param array $data * @param CountryWithWebsitesSource|null $countryWithWebsites * @param AddressStorage|null $addressStorage - * @param Processor $indexerProcessor + * @param Processor|null $indexerProcessor + * @param Share|null $configShare * * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.ExcessiveParameterList) @@ -297,7 +299,8 @@ public function __construct( array $data = [], ?CountryWithWebsitesSource $countryWithWebsites = null, ?AddressStorage $addressStorage = null, - ?Processor $indexerProcessor = null + ?Processor $indexerProcessor = null, + ?Share $configShare = null ) { $this->_customerFactory = $customerFactory; $this->_addressFactory = $addressFactory; @@ -325,7 +328,8 @@ public function __construct( $collectionFactory, $eavConfig, $storageFactory, - $data + $data, + $configShare ); $this->_entityTable = isset( diff --git a/vendor/magento/module-customer-import-export/Model/ResourceModel/Import/Customer/Storage.php b/vendor/magento/module-customer-import-export/Model/ResourceModel/Import/Customer/Storage.php index 21a2252257f7..0c16e2010fe5 100644 --- a/vendor/magento/module-customer-import-export/Model/ResourceModel/Import/Customer/Storage.php +++ b/vendor/magento/module-customer-import-export/Model/ResourceModel/Import/Customer/Storage.php @@ -5,6 +5,7 @@ */ namespace Magento\CustomerImportExport\Model\ResourceModel\Import\Customer; +use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Customer\Model\ResourceModel\Customer\Collection as CustomerCollection; use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory as CustomerCollectionFactory; use Magento\Framework\DataObject; @@ -29,6 +30,11 @@ class Storage */ protected $_customerIds = []; + /** + * @var array + */ + private $customerIdsByEmail = []; + /** * Number of items to fetch from db in one query * @@ -60,12 +66,19 @@ class Storage */ private $customerStoreIds = []; + /** + * @var CustomerRepositoryInterface + */ + private $customerRepository; + /** * @param CustomerCollectionFactory $collectionFactory + * @param CustomerRepositoryInterface $customerRepository * @param array $data */ public function __construct( CustomerCollectionFactory $collectionFactory, + CustomerRepositoryInterface $customerRepository, array $data = [] ) { $this->_customerCollection = isset( @@ -73,6 +86,7 @@ public function __construct( ) ? $data['customer_collection'] : $collectionFactory->create(); $this->_pageSize = isset($data['page_size']) ? (int) $data['page_size'] : 0; $this->customerCollectionFactory = $collectionFactory; + $this->customerRepository = $customerRepository; } /** @@ -130,7 +144,8 @@ public function addCustomerByArray(array $customer): Storage /** * Add customer to array * - * @deprecated 100.3.0 @see addCustomerByArray + * @deprecated 100.3.0 + * @see addCustomerByArray * @param DataObject $customer * @return $this */ @@ -164,6 +179,25 @@ public function getCustomerId(string $email, int $websiteId) return false; } + /** + * Find customer ID by email. + * + * @param string $email + * @return bool|int + */ + public function getCustomerIdByEmail(string $email) + { + if (!isset($this->customerIdsByEmail[$email])) { + try { + $this->customerIdsByEmail[$email] = $this->customerRepository->get($email)->getId(); + } catch (\Magento\Framework\Exception\NoSuchEntityException $e) { + $this->customerIdsByEmail[$email] = false; + } + } + + return $this->customerIdsByEmail[$email]; + } + /** * Get previously loaded customer id. *