Esempio n. 1
0
 /**
  * @param \Generated\Shared\Transfer\CustomerTransfer $customerTransfer
  *
  * @return \Generated\Shared\Transfer\CustomerResponseTransfer
  */
 public function register(CustomerTransfer $customerTransfer)
 {
     $customerTransfer = $this->encryptPassword($customerTransfer);
     $customerEntity = new SpyCustomer();
     $customerEntity->fromArray($customerTransfer->toArray());
     if (!$this->isEmailAvailableForCustomer($customerEntity)) {
         $customerResponseTransfer = $this->createCustomerEmailAlreadyUsedResponse();
         return $customerResponseTransfer;
     }
     $customerResponseTransfer = $this->createCustomerResponseTransfer();
     $customerEntity->setCustomerReference($this->customerReferenceGenerator->generateCustomerReference($customerTransfer));
     $customerEntity->setRegistrationKey($this->generateKey());
     $customerEntity->save();
     $customerTransfer->setIdCustomer($customerEntity->getPrimaryKey());
     $customerTransfer->setCustomerReference($customerEntity->getCustomerReference());
     $customerTransfer->setRegistrationKey($customerEntity->getRegistrationKey());
     $this->sendRegistrationToken($customerTransfer);
     $customerResponseTransfer->setIsSuccess(true)->setCustomerTransfer($customerTransfer);
     return $customerResponseTransfer;
 }