Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TE-7332 Backport for facade method findCustomerAddressById #2

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/Spryker/Zed/Customer/Business/Customer/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Spryker\Zed\Customer\Dependency\Facade\CustomerToCountryInterface;
use Spryker\Zed\Customer\Dependency\Facade\CustomerToLocaleInterface;
use Spryker\Zed\Customer\Persistence\CustomerQueryContainerInterface;
use Spryker\Zed\Customer\Persistence\CustomerRepositoryInterface;

class Address implements AddressInterface
{
Expand All @@ -38,16 +39,27 @@ class Address implements AddressInterface
*/
protected $localeFacade;

/**
* @var \Spryker\Zed\Customer\Persistence\CustomerRepositoryInterface
*/
protected $customerRepository;

/**
* @param \Spryker\Zed\Customer\Persistence\CustomerQueryContainerInterface $queryContainer
* @param \Spryker\Zed\Customer\Dependency\Facade\CustomerToCountryInterface $countryFacade
* @param \Spryker\Zed\Customer\Dependency\Facade\CustomerToLocaleInterface $localeFacade
* @param \Spryker\Zed\Customer\Persistence\CustomerRepositoryInterface $customerRepository
*/
public function __construct(CustomerQueryContainerInterface $queryContainer, CustomerToCountryInterface $countryFacade, CustomerToLocaleInterface $localeFacade)
{
public function __construct(
CustomerQueryContainerInterface $queryContainer,
CustomerToCountryInterface $countryFacade,
CustomerToLocaleInterface $localeFacade,
CustomerRepositoryInterface $customerRepository
) {
$this->queryContainer = $queryContainer;
$this->countryFacade = $countryFacade;
$this->localeFacade = $localeFacade;
$this->customerRepository = $customerRepository;
}

/**
Expand Down Expand Up @@ -168,6 +180,16 @@ public function updateAddress(AddressTransfer $addressTransfer)
return $this->entityToAddressTransfer($addressEntity);
}

/**
* @param int $idCustomerAddress
*
* @return \Generated\Shared\Transfer\AddressTransfer|null
*/
public function findCustomerAddressById(int $idCustomerAddress): ?AddressTransfer
{
return $this->customerRepository->findCustomerAddressById($idCustomerAddress);
}

/**
* @param \Generated\Shared\Transfer\AddressTransfer $addressTransfer
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ public function getAddresses(CustomerTransfer $customerTransfer);
*/
public function updateAddress(AddressTransfer $addressTransfer);

/**
* @param int $idCustomerAddress
*
* @return \Generated\Shared\Transfer\AddressTransfer|null
*/
public function findCustomerAddressById(int $idCustomerAddress): ?AddressTransfer;

/**
* @param \Generated\Shared\Transfer\AddressTransfer $addressTransfer
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
/**
* @method \Spryker\Zed\Customer\CustomerConfig getConfig()
* @method \Spryker\Zed\Customer\Persistence\CustomerQueryContainerInterface getQueryContainer()
* @method \Spryker\Zed\Customer\Persistence\CustomerRepositoryInterface getRepository()
*/
class CustomerBusinessFactory extends AbstractBusinessFactory
{
Expand Down Expand Up @@ -49,7 +50,12 @@ public function createCustomer()
*/
public function createAddress()
{
return new Address($this->getQueryContainer(), $this->getCountryFacade(), $this->getLocaleFacade());
return new Address(
$this->getQueryContainer(),
$this->getCountryFacade(),
$this->getLocaleFacade(),
$this->getRepository()
);
}

/**
Expand Down
17 changes: 17 additions & 0 deletions src/Spryker/Zed/Customer/Business/CustomerFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

/**
* @method \Spryker\Zed\Customer\Business\CustomerBusinessFactory getFactory()
* @method \Spryker\Zed\Customer\Persistence\CustomerRepositoryInterface getRepository()
*/
class CustomerFacade extends AbstractFacade implements CustomerFacadeInterface
{
Expand Down Expand Up @@ -307,6 +308,22 @@ public function createAddress(AddressTransfer $addressTransfer)
->createAddress($addressTransfer);
}

/**
* {@inheritDoc}
*
* @api
*
* @param int $idCustomerAddress
*
* @return \Generated\Shared\Transfer\AddressTransfer|null
*/
public function findCustomerAddressById(int $idCustomerAddress): ?AddressTransfer
{
return $this->getFactory()
->createAddress()
->findCustomerAddressById($idCustomerAddress);
}

/**
* {@inheritdoc}
*
Expand Down
12 changes: 12 additions & 0 deletions src/Spryker/Zed/Customer/Business/CustomerFacadeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,18 @@ public function createAddressAndUpdateCustomerDefaultAddresses(AddressTransfer $
*/
public function createAddress(AddressTransfer $addressTransfer);

/**
* Specification:
* - Retrieves customer address by address ID.
*
* @api
*
* @param int $idCustomerAddress
*
* @return \Generated\Shared\Transfer\AddressTransfer|null
*/
public function findCustomerAddressById(int $idCustomerAddress): ?AddressTransfer;

/**
* Specification:
* - Sets provided address as default billing address for the related customer.
Expand Down
52 changes: 52 additions & 0 deletions src/Spryker/Zed/Customer/Persistence/CustomerRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace Spryker\Zed\Customer\Persistence;

use Generated\Shared\Transfer\AddressCriteriaFilterTransfer;
use Generated\Shared\Transfer\AddressesTransfer;
use Generated\Shared\Transfer\AddressTransfer;
use Generated\Shared\Transfer\CustomerCollectionTransfer;
use Generated\Shared\Transfer\CustomerCriteriaFilterTransfer;
use Generated\Shared\Transfer\CustomerCriteriaTransfer;
use Generated\Shared\Transfer\CustomerTransfer;
use Generated\Shared\Transfer\FilterTransfer;
use Generated\Shared\Transfer\PaginationTransfer;
use Orm\Zed\Customer\Persistence\Map\SpyCustomerTableMap;
use Orm\Zed\Customer\Persistence\SpyCustomerAddressQuery;
use Orm\Zed\Customer\Persistence\SpyCustomerQuery;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\Formatter\ArrayFormatter;
use Spryker\Zed\Kernel\Persistence\AbstractRepository;
use Spryker\Zed\Propel\PropelFilterCriteria;

/**
* @method \Spryker\Zed\Customer\Persistence\CustomerPersistenceFactory getFactory()
*/
class CustomerRepository extends AbstractRepository implements CustomerRepositoryInterface
{
/**
* @param int $idCustomerAddress
*
* @return \Generated\Shared\Transfer\AddressTransfer|null
*/
public function findCustomerAddressById(int $idCustomerAddress): ?AddressTransfer
{
$customerAddressEntity = $this->getFactory()
->createSpyCustomerAddressQuery()
->filterByIdCustomerAddress($idCustomerAddress)
->findOne();

if (!$customerAddressEntity) {
return null;
}

return $this->getFactory()
->createCustomerMapper()
->mapCustomerAddressEntityToAddressTransfer($customerAddressEntity, new AddressTransfer());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace Spryker\Zed\Customer\Persistence;

use Generated\Shared\Transfer\AddressTransfer;

interface CustomerRepositoryInterface
{
/**
* @param int $idCustomerAddress
*
* @return \Generated\Shared\Transfer\AddressTransfer|null
*/
public function findCustomerAddressById(int $idCustomerAddress): ?AddressTransfer;
}