Skip to content

Commit

Permalink
core-922: use customer reference to get customer
Browse files Browse the repository at this point in the history
  • Loading branch information
Auris committed Jun 14, 2017
1 parent 408c48c commit 2ec9462
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/Spryker/Zed/Customer/Business/Customer/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,42 @@ public function findById($customerTransfer)
return null;
}

$customerTransfer = $this->hydrateCustomerTransferFromEntity($customerTransfer, $customerEntity);

return $customerTransfer;
}

/**
* @param string $customerReference
*
* @return \Generated\Shared\Transfer\CustomerTransfer $customerTransfer|null
*/
public function findByReference($customerReference)
{
$customerEntity = $this->queryContainer
->queryCustomerByReference($customerReference)
->findOne();

if ($customerEntity === null) {
return null;
}

$customerTransfer = new CustomerTransfer();
$customerTransfer = $this->hydrateCustomerTransferFromEntity($customerTransfer, $customerEntity);

return $customerTransfer;
}

/**
* @param \Generated\Shared\Transfer\CustomerTransfer $customerTransfer
* @param \Orm\Zed\Customer\Persistence\SpyCustomer $customerEntity
*
* @return \Generated\Shared\Transfer\CustomerTransfer
*/
protected function hydrateCustomerTransferFromEntity(
CustomerTransfer $customerTransfer,
SpyCustomer $customerEntity
) {
$customerTransfer->fromArray($customerEntity->toArray(), true);
$customerTransfer = $this->attachAddresses($customerTransfer, $customerEntity);
$customerTransfer = $this->attachLocale($customerTransfer, $customerEntity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,11 @@ public function tryAuthorizeCustomerByEmailAndPassword(CustomerTransfer $custome
*/
public function findById($customerTransfer);

/**
* @param string $customerReference
*
* @return \Generated\Shared\Transfer\CustomerTransfer $customerTransfer|null
*/
public function findByReference($customerReference);

}
16 changes: 16 additions & 0 deletions src/Spryker/Zed/Customer/Business/CustomerFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,4 +417,20 @@ public function anonymizeCustomer(CustomerTransfer $customerTransfer)
->process($customerTransfer);
}

/**
* @api
*
* {@inheritdoc}
*
* @param string $customerReference
*
* @return \Generated\Shared\Transfer\CustomerTransfer|null
*/
public function findByReference($customerReference)
{
return $this->getFactory()
->createCustomer()
->findByReference($customerReference);
}

}
13 changes: 13 additions & 0 deletions src/Spryker/Zed/Customer/Business/CustomerFacadeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,17 @@ public function checkOrderPreSaveConditions(
*/
public function anonymizeCustomer(CustomerTransfer $customerTransfer);

/**
* @api
*
* Specification:
* - Finds customer by reference
* - Returns customer transfer
*
* @param string $customerReference
*
* @return \Generated\Shared\Transfer\CustomerTransfer|null
*/
public function findByReference($customerReference);

}

0 comments on commit 2ec9462

Please sign in to comment.