-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
magento/graphql-ce:#468 - Resolve coupling between objects in `\Magen…
…to\QuoteGraphQl\Model\Cart\SetBillingAddressOnCart`
- Loading branch information
Vasilii
committed
Mar 16, 2019
1 parent
7b1cd79
commit b3280d0
Showing
2 changed files
with
95 additions
and
33 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
app/code/Magento/QuoteGraphQl/Model/Cart/CreateQuoteAddressByCustomerAddress.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\QuoteGraphQl\Model\Cart; | ||
|
||
use Magento\CustomerGraphQl\Model\Customer\Address\GetCustomerAddress; | ||
use Magento\CustomerGraphQl\Model\Customer\GetCustomer; | ||
use Magento\Framework\GraphQl\Exception\GraphQlAuthenticationException; | ||
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException; | ||
use Magento\Framework\GraphQl\Exception\GraphQlInputException; | ||
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; | ||
use Magento\Quote\Model\Quote\Address; | ||
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; | ||
|
||
/** | ||
* Creates a quote address based on given context, customer address ID and customer address | ||
*/ | ||
class CreateQuoteAddressByCustomerAddress | ||
{ | ||
/** | ||
* @var QuoteAddressFactory | ||
*/ | ||
private $quoteAddressFactory; | ||
|
||
/** | ||
* @var GetCustomer | ||
*/ | ||
private $getCustomer; | ||
|
||
/** | ||
* @var GetCustomerAddress | ||
*/ | ||
private $getCustomerAddress; | ||
|
||
/** | ||
* @param QuoteAddressFactory $quoteAddressFactory | ||
* @param GetCustomer $getCustomer | ||
* @param GetCustomerAddress $getCustomerAddress | ||
*/ | ||
public function __construct( | ||
QuoteAddressFactory $quoteAddressFactory, | ||
GetCustomer $getCustomer, | ||
GetCustomerAddress $getCustomerAddress | ||
) { | ||
$this->quoteAddressFactory = $quoteAddressFactory; | ||
$this->getCustomer = $getCustomer; | ||
$this->getCustomerAddress = $getCustomerAddress; | ||
} | ||
|
||
/** | ||
* @param ContextInterface $context | ||
* @param int|string|null $customerAddressId | ||
* @param array|null $customerAddress | ||
* @return Address | ||
* @throws GraphQlAuthenticationException | ||
* @throws GraphQlAuthorizationException | ||
* @throws GraphQlInputException | ||
* @throws GraphQlNoSuchEntityException | ||
*/ | ||
public function execute( | ||
ContextInterface $context, | ||
$customerAddressId, | ||
$customerAddress | ||
): Address { | ||
if (null === $customerAddressId) { | ||
return $this->quoteAddressFactory->createBasedOnInputData($customerAddress); | ||
} | ||
|
||
$customer = $this->getCustomer->execute($context); | ||
$customerAddress = $this->getCustomerAddress->execute((int)$customerAddressId, (int)$customer->getId()); | ||
|
||
return $this->quoteAddressFactory->createBasedOnCustomerAddress($customerAddress); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters