The custom di.xml
has this
<preference for="Magento\Customer\Model\ResourceModel\CustomerRepository"
type="Custom\Mod\Model\ResourceModel\CustomerRepository" />
The customized CustomerRepository is
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Custom\Mod\Model\ResourceModel;
/**
* Customer repository.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class CustomerRepository extends \Magento\Customer\Model\ResourceModel\CustomerRepository
{
/**
* {@inheritdoc}
*/
public function save(\Magento\Customer\Api\Data\CustomerInterface $customer, $passwordHash = null) {
$prevCustomerData = null;
$prevCustomerDataArr = null;
if ($customer->getId()) {
$prevCustomerData = $this->getById($customer->getId());
$prevCustomerDataArr = $prevCustomerData->__toArray();
}
/** @var $customer \Magento\Customer\Model\Data\Customer */
$customerArr = $customer->__toArray();
$customer = $this->imageProcessor->save(
$customer, \Magento\Customer\Api\CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, $prevCustomerData
);
$origAddresses = $customer->getAddresses();
$customer->setAddresses([]);
$customerData = $this->extensibleDataObjectConverter->toNestedArray(
$customer, [], \Magento\Customer\Api\Data\CustomerInterface::class
);
$customer->setAddresses($origAddresses);
$customerModel = $this->customerFactory->create(['data' => $customerData]);
$storeId = $customerModel->getStoreId();
if ($storeId === null) {
$customerModel->setStoreId($this->storeManager->getStore()->getId());
}
$customerModel->setId($customer->getId());
// Need to use attribute set or future updates can cause data loss
if (!$customerModel->getAttributeSetId()) {
$customerModel->setAttributeSetId(
\Magento\Customer\Api\CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER
);
}
// Populate model with secure data
$this->populateCustomerModelWithSecureData($customer, $passwordHash, $customerModel);
// If customer email was changed, reset RpToken info
if ($prevCustomerData && $prevCustomerData->getEmail() !== $customerModel->getEmail()
) {
$customerModel->setRpToken(null);
$customerModel->setRpTokenCreatedAt(null);
}
$this->setDefaultBilling($customerArr, $prevCustomerDataArr, $customerModel);
$this->setDefaultShipping($customerArr, $prevCustomerDataArr, $customerModel);
$bo=0;
if(isset($customerArr['custom_attributes']['back_office']['value'])){
if($customerArr['custom_attributes']['back_office']['value']==1)
$bo=1;
}
if($customerArr['custom_attributes']['customer_type']['value']=='abal'||$bo==1){
if($customerArr['custom_attributes']['customer_type']['value']=='abal'){
$customerModel->setGroupId(4);
}
$customerModel->save();
$this->customerRegistry->push($customerModel);
$customerId = $customerModel->getId();
$this->updateAddresses($customer, $customerId);
if($bo=1){
$this->updateft($customer);
}
if(isset($customerArr['id'])&&$customerArr['custom_attributes']['customer_type']['value']=='abal'){
$this->insertcustdetails($customer,$customerId);
}
$savedCustomer = $this->get($customer->getEmail(), $customer->getWebsiteId());
$this->eventManager->dispatch(
'customer_save_after_data_object', ['customer_data_object' => $savedCustomer, 'orig_customer_data_object' => $customer]
);
return $savedCustomer;
}
else{
$resp = NULL;
if (!isset($customerArr['id'])) {
$customerArr = $customer->__toArray();
$resp = $this->curlCall($customerArr);
if ($resp == "registration_successfull") {
$customerModel->save();
$this->customerRegistry->push($customerModel);
$customerId = $customerModel->getId();
$this->updateAddresses($customer, $customerId);
$savedCustomer = $this->get($customer->getEmail(), $customer->getWebsiteId());
$this->eventManager->dispatch(
'customer_save_after_data_object', ['customer_data_object' => $savedCustomer, 'orig_customer_data_object' => $customer]
);
return $savedCustomer;
} else {
try{
$number = 5/0;
} catch (\Exception $e) {
$this->messageManager->addException($e, __('We can\'t save the customer.'));
}
}
}
else{
$customerModel->save();
$this->customerRegistry->push($customerModel);
$customerId = $customerModel->getId();
$this->updateft($customer);
$this->updateaddress($customer);
$this->updateAddresses($customer, $customerId);
$savedCustomer = $this->get($customer->getEmail(), $customer->getWebsiteId());
$this->eventManager->dispatch(
'customer_save_after_data_object', ['customer_data_object' => $savedCustomer, 'orig_customer_data_object' => $customer]
);
return $savedCustomer;
}
}
}
}