Skip to content

Commit ad9f66c

Browse files
committedApr 3, 2019
ENGCOM-4648: Resolve coupling between objects in \\Magento\QuoteGraphQl\Model\Cart\SetBillingAddressOnCart\ #488
- Merge Pull Request magento/graphql-ce#488 from vasilii-b/graphql-ce:issue/468 - Merged commits: 1. b3280d0 2. 799f37e 3. ace616f 4. 5b03488
2 parents 4a28abb + 5b03488 commit ad9f66c

File tree

3 files changed

+32
-27
lines changed

3 files changed

+32
-27
lines changed
 

‎app/code/Magento/QuoteGraphQl/Model/Cart/QuoteAddressFactory.php

+20-5
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77

88
namespace Magento\QuoteGraphQl\Model\Cart;
99

10-
use Magento\Customer\Api\Data\AddressInterface as CustomerAddress;
10+
use Magento\CustomerGraphQl\Model\Customer\Address\GetCustomerAddress;
1111
use Magento\Framework\Exception\LocalizedException;
12+
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
1213
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
14+
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
1315
use Magento\Quote\Model\Quote\Address as QuoteAddress;
1416
use Magento\Quote\Model\Quote\AddressFactory as BaseQuoteAddressFactory;
1517

@@ -23,13 +25,21 @@ class QuoteAddressFactory
2325
*/
2426
private $quoteAddressFactory;
2527

28+
/**
29+
* @var GetCustomerAddress
30+
*/
31+
private $getCustomerAddress;
32+
2633
/**
2734
* @param BaseQuoteAddressFactory $quoteAddressFactory
35+
* @param GetCustomerAddress $getCustomerAddress
2836
*/
2937
public function __construct(
30-
BaseQuoteAddressFactory $quoteAddressFactory
38+
BaseQuoteAddressFactory $quoteAddressFactory,
39+
GetCustomerAddress $getCustomerAddress
3140
) {
3241
$this->quoteAddressFactory = $quoteAddressFactory;
42+
$this->getCustomerAddress = $getCustomerAddress;
3343
}
3444

3545
/**
@@ -48,14 +58,19 @@ public function createBasedOnInputData(array $addressInput): QuoteAddress
4858
}
4959

5060
/**
51-
* Create QuoteAddress based on CustomerAddress
61+
* Create Quote Address based on Customer Address
5262
*
53-
* @param CustomerAddress $customerAddress
63+
* @param int $customerAddressId
64+
* @param int $customerId
5465
* @return QuoteAddress
5566
* @throws GraphQlInputException
67+
* @throws GraphQlAuthorizationException
68+
* @throws GraphQlNoSuchEntityException
5669
*/
57-
public function createBasedOnCustomerAddress(CustomerAddress $customerAddress): QuoteAddress
70+
public function createBasedOnCustomerAddress(int $customerAddressId, int $customerId): QuoteAddress
5871
{
72+
$customerAddress = $this->getCustomerAddress->execute((int)$customerAddressId, $customerId);
73+
5974
$quoteAddress = $this->quoteAddressFactory->create();
6075
try {
6176
$quoteAddress->importCustomerAddressData($customerAddress);

‎app/code/Magento/QuoteGraphQl/Model/Cart/SetBillingAddressOnCart.php

+8-11
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
namespace Magento\QuoteGraphQl\Model\Cart;
99

10-
use Magento\CustomerGraphQl\Model\Customer\Address\GetCustomerAddress;
1110
use Magento\CustomerGraphQl\Model\Customer\GetCustomer;
11+
use Magento\Framework\GraphQl\Exception\GraphQlAuthenticationException;
12+
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
1213
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1314
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
1415
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
@@ -29,11 +30,6 @@ class SetBillingAddressOnCart
2930
*/
3031
private $getCustomer;
3132

32-
/**
33-
* @var GetCustomerAddress
34-
*/
35-
private $getCustomerAddress;
36-
3733
/**
3834
* @var AssignBillingAddressToCart
3935
*/
@@ -42,18 +38,15 @@ class SetBillingAddressOnCart
4238
/**
4339
* @param QuoteAddressFactory $quoteAddressFactory
4440
* @param GetCustomer $getCustomer
45-
* @param GetCustomerAddress $getCustomerAddress
4641
* @param AssignBillingAddressToCart $assignBillingAddressToCart
4742
*/
4843
public function __construct(
4944
QuoteAddressFactory $quoteAddressFactory,
5045
GetCustomer $getCustomer,
51-
GetCustomerAddress $getCustomerAddress,
5246
AssignBillingAddressToCart $assignBillingAddressToCart
5347
) {
5448
$this->quoteAddressFactory = $quoteAddressFactory;
5549
$this->getCustomer = $getCustomer;
56-
$this->getCustomerAddress = $getCustomerAddress;
5750
$this->assignBillingAddressToCart = $assignBillingAddressToCart;
5851
}
5952

@@ -65,6 +58,8 @@ public function __construct(
6558
* @param array $billingAddressInput
6659
* @return void
6760
* @throws GraphQlInputException
61+
* @throws GraphQlAuthenticationException
62+
* @throws GraphQlAuthorizationException
6863
* @throws GraphQlNoSuchEntityException
6964
*/
7065
public function execute(ContextInterface $context, CartInterface $cart, array $billingAddressInput): void
@@ -97,8 +92,10 @@ public function execute(ContextInterface $context, CartInterface $cart, array $b
9792
$billingAddress = $this->quoteAddressFactory->createBasedOnInputData($addressInput);
9893
} else {
9994
$customer = $this->getCustomer->execute($context);
100-
$customerAddress = $this->getCustomerAddress->execute((int)$customerAddressId, (int)$customer->getId());
101-
$billingAddress = $this->quoteAddressFactory->createBasedOnCustomerAddress($customerAddress);
95+
$billingAddress = $this->quoteAddressFactory->createBasedOnCustomerAddress(
96+
(int)$customerAddressId,
97+
(int)$customer->getId()
98+
);
10299
}
103100

104101
$this->assignBillingAddressToCart->execute($cart, $billingAddress, $useForShipping);

‎app/code/Magento/QuoteGraphQl/Model/Cart/SetShippingAddressesOnCart.php

+4-11
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace Magento\QuoteGraphQl\Model\Cart;
99

10-
use Magento\CustomerGraphQl\Model\Customer\Address\GetCustomerAddress;
1110
use Magento\CustomerGraphQl\Model\Customer\GetCustomer;
1211
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1312
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
@@ -28,11 +27,6 @@ class SetShippingAddressesOnCart implements SetShippingAddressesOnCartInterface
2827
*/
2928
private $getCustomer;
3029

31-
/**
32-
* @var GetCustomerAddress
33-
*/
34-
private $getCustomerAddress;
35-
3630
/**
3731
* @var AssignShippingAddressToCart
3832
*/
@@ -41,18 +35,15 @@ class SetShippingAddressesOnCart implements SetShippingAddressesOnCartInterface
4135
/**
4236
* @param QuoteAddressFactory $quoteAddressFactory
4337
* @param GetCustomer $getCustomer
44-
* @param GetCustomerAddress $getCustomerAddress
4538
* @param AssignShippingAddressToCart $assignShippingAddressToCart
4639
*/
4740
public function __construct(
4841
QuoteAddressFactory $quoteAddressFactory,
4942
GetCustomer $getCustomer,
50-
GetCustomerAddress $getCustomerAddress,
5143
AssignShippingAddressToCart $assignShippingAddressToCart
5244
) {
5345
$this->quoteAddressFactory = $quoteAddressFactory;
5446
$this->getCustomer = $getCustomer;
55-
$this->getCustomerAddress = $getCustomerAddress;
5647
$this->assignShippingAddressToCart = $assignShippingAddressToCart;
5748
}
5849

@@ -86,8 +77,10 @@ public function execute(ContextInterface $context, CartInterface $cart, array $s
8677
$shippingAddress = $this->quoteAddressFactory->createBasedOnInputData($addressInput);
8778
} else {
8879
$customer = $this->getCustomer->execute($context);
89-
$customerAddress = $this->getCustomerAddress->execute((int)$customerAddressId, (int)$customer->getId());
90-
$shippingAddress = $this->quoteAddressFactory->createBasedOnCustomerAddress($customerAddress);
80+
$shippingAddress = $this->quoteAddressFactory->createBasedOnCustomerAddress(
81+
(int)$customerAddressId,
82+
(int)$customer->getId()
83+
);
9184
}
9285

9386
$this->assignShippingAddressToCart->execute($cart, $shippingAddress);

0 commit comments

Comments
 (0)