95 private $collectionProcessor;
100 private $notificationStorage;
105 private $delegatedStorage;
142 DelegatedStorage $delegatedStorage =
null 157 $this->collectionProcessor = $collectionProcessor;
158 $this->notificationStorage = $notificationStorage;
159 $this->delegatedStorage = $delegatedStorage
171 $delegatedNewOperation = !
$customer->getId() ? $this->delegatedStorage->consumeNewOperation() :
null;
172 $prevCustomerData =
null;
173 $prevCustomerDataArr =
null;
176 $prevCustomerDataArr = $prevCustomerData->__toArray();
185 $origAddresses =
$customer->getAddresses();
187 $customerData = $this->extensibleDataObjectConverter->toNestedArray(
$customer, [], CustomerInterface::class);
190 $customerModel = $this->customerFactory->create([
'data' =>
$customerData]);
192 $customerModel->setId(
$customer->getId());
193 $storeId = $customerModel->getStoreId();
195 $customerModel->setStoreId($this->storeManager->getStore()->getId());
198 if (!$customerModel->getAttributeSetId()) {
201 $this->populateCustomerWithSecureData($customerModel, $passwordHash);
203 if ($prevCustomerData && $prevCustomerData->getEmail() !== $customerModel->getEmail()) {
204 $customerModel->setRpToken(
null);
205 $customerModel->setRpTokenCreatedAt(
null);
207 if (!array_key_exists(
'default_billing', $customerArr)
208 &&
null !== $prevCustomerDataArr
209 && array_key_exists(
'default_billing', $prevCustomerDataArr)
211 $customerModel->setDefaultBilling($prevCustomerDataArr[
'default_billing']);
213 if (!array_key_exists(
'default_shipping', $customerArr)
214 &&
null !== $prevCustomerDataArr
215 && array_key_exists(
'default_shipping', $prevCustomerDataArr)
217 $customerModel->setDefaultShipping($prevCustomerDataArr[
'default_shipping']);
219 $customerModel->save();
220 $this->customerRegistry->push($customerModel);
223 && $delegatedNewOperation
224 && $delegatedNewOperation->getCustomer()->getAddresses()
226 $customer->setAddresses($delegatedNewOperation->getCustomer()->getAddresses());
228 if (
$customer->getAddresses() !==
null) {
230 $existingAddresses = $this->
getById($customer->
getId())->getAddresses();
234 $existingAddressIds = array_map($getIdFunc, $existingAddresses);
236 $existingAddressIds = [];
238 $savedAddressIds = [];
242 $this->addressRepository->save(
$address);
244 $savedAddressIds[] =
$address->getId();
247 $addressIdsToDelete = array_diff($existingAddressIds, $savedAddressIds);
248 foreach ($addressIdsToDelete as $addressId) {
249 $this->addressRepository->deleteById($addressId);
254 $this->eventManager->dispatch(
255 'customer_save_after_data_object',
257 'customer_data_object' => $savedCustomer,
258 'orig_customer_data_object' => $prevCustomerData,
259 'delegate_data' => $delegatedNewOperation ? $delegatedNewOperation->getAdditionalData() : [],
263 return $savedCustomer;
274 private function populateCustomerWithSecureData($customerModel, $passwordHash =
null)
276 if ($customerModel->getId()) {
277 $customerSecure = $this->customerRegistry->retrieveSecureData($customerModel->getId());
279 $customerModel->setRpToken($passwordHash ?
null : $customerSecure->getRpToken());
280 $customerModel->setRpTokenCreatedAt($passwordHash ?
null : $customerSecure->getRpTokenCreatedAt());
281 $customerModel->setPasswordHash($passwordHash ?: $customerSecure->getPasswordHash());
283 $customerModel->setFailuresNum($customerSecure->getFailuresNum());
284 $customerModel->setFirstFailure($customerSecure->getFirstFailure());
285 $customerModel->setLockExpires($customerSecure->getLockExpires());
286 }
elseif ($passwordHash) {
287 $customerModel->setPasswordHash($passwordHash);
290 if ($passwordHash && $customerModel->getId()) {
291 $this->customerRegistry->remove($customerModel->getId());
300 $customerModel = $this->customerRegistry->retrieveByEmail(
$email,
$websiteId);
301 return $customerModel->getDataModel();
309 $customerModel = $this->customerRegistry->retrieve(
$customerId);
310 return $customerModel->getDataModel();
318 $searchResults = $this->searchResultsFactory->create();
321 $collection = $this->customerFactory->create()->getCollection();
322 $this->extensionAttributesJoinProcessor->process(
324 CustomerInterface::class
327 foreach ($this->customerMetadata->getAllAttributesMetadata() as $metadata) {
328 $collection->addAttributeToSelect($metadata->getAttributeCode());
333 $collection->joinAttribute(
'billing_postcode',
'customer_address/postcode',
'default_billing',
null,
'left')
334 ->joinAttribute(
'billing_city',
'customer_address/city',
'default_billing',
null,
'left')
335 ->joinAttribute(
'billing_telephone',
'customer_address/telephone',
'default_billing',
null,
'left')
336 ->joinAttribute(
'billing_region',
'customer_address/region',
'default_billing',
null,
'left')
337 ->joinAttribute(
'billing_country_id',
'customer_address/country_id',
'default_billing',
null,
'left')
338 ->joinAttribute(
'company',
'customer_address/company',
'default_billing',
null,
'left');
342 $searchResults->setTotalCount(
$collection->getSize());
347 $customers[] = $customerModel->getDataModel();
350 return $searchResults;
366 $customerModel = $this->customerRegistry->retrieve(
$customerId);
367 $customerModel->delete();
388 foreach ($filterGroup->getFilters() as $filter) {
389 $condition = $filter->getConditionType() ? $filter->getConditionType() :
'eq';
390 $fields[] = [
'attribute' => $filter->getField(), $condition => $filter->getValue()];
elseif(isset( $params[ 'redirect_parent']))
__construct(\Magento\Customer\Model\CustomerFactory $customerFactory, \Magento\Customer\Model\Data\CustomerSecureFactory $customerSecureFactory, \Magento\Customer\Model\CustomerRegistry $customerRegistry, \Magento\Customer\Model\ResourceModel\AddressRepository $addressRepository, \Magento\Customer\Model\ResourceModel\Customer $customerResourceModel, \Magento\Customer\Api\CustomerMetadataInterface $customerMetadata, \Magento\Customer\Api\Data\CustomerSearchResultsInterfaceFactory $searchResultsFactory, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Api\ExtensibleDataObjectConverter $extensibleDataObjectConverter, DataObjectHelper $dataObjectHelper, ImageProcessorInterface $imageProcessor, \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $extensionAttributesJoinProcessor, CollectionProcessorInterface $collectionProcessor, NotificationStorage $notificationStorage, DelegatedStorage $delegatedStorage=null)
save(\Magento\Customer\Api\Data\CustomerInterface $customer, $passwordHash=null)
$extensionAttributesJoinProcessor
getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
addFilterGroupToCollection(\Magento\Framework\Api\Search\FilterGroup $filterGroup, \Magento\Customer\Model\ResourceModel\Customer\Collection $collection)
const UPDATE_CUSTOMER_SESSION
$extensibleDataObjectConverter