Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.

Commit e02dc94

Browse files
committed
GraphQL-418: [Shipping methods] Set Shipping Methods on Cart
1 parent 0ef7711 commit e02dc94

6 files changed

+27
-33
lines changed

app/code/Magento/QuoteGraphQl/Model/Cart/AssignBillingAddressToCart.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
use Magento\Framework\Exception\NoSuchEntityException;
1212
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1313
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
14+
use Magento\Quote\Api\Data\AddressInterface;
1415
use Magento\Quote\Api\Data\CartInterface;
1516
use Magento\Quote\Api\BillingAddressManagementInterface;
16-
use Magento\Quote\Model\Quote\Address as QuoteAddress;
1717

1818
/**
1919
* Set billing address for a specified shopping cart
@@ -38,14 +38,14 @@ public function __construct(
3838
* Assign billing address to cart
3939
*
4040
* @param CartInterface $cart
41-
* @param QuoteAddress $billingAddress
41+
* @param AddressInterface $billingAddress
4242
* @param bool $useForShipping
4343
* @throws GraphQlInputException
4444
* @throws GraphQlNoSuchEntityException
4545
*/
4646
public function execute(
4747
CartInterface $cart,
48-
QuoteAddress $billingAddress,
48+
AddressInterface $billingAddress,
4949
bool $useForShipping
5050
): void {
5151
try {

app/code/Magento/QuoteGraphQl/Model/Cart/AssignShippingAddressToCart.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
use Magento\Framework\Exception\NoSuchEntityException;
1212
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1313
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
14+
use Magento\Quote\Api\Data\AddressInterface;
1415
use Magento\Quote\Api\Data\CartInterface;
15-
use Magento\Quote\Model\Quote\Address as QuoteAddress;
1616
use Magento\Quote\Model\ShippingAddressManagementInterface;
1717

1818
/**
@@ -38,13 +38,13 @@ public function __construct(
3838
* Assign shipping address to cart
3939
*
4040
* @param CartInterface $cart
41-
* @param QuoteAddress $shippingAddress
41+
* @param AddressInterface $shippingAddress
4242
* @throws GraphQlInputException
4343
* @throws GraphQlNoSuchEntityException
4444
*/
4545
public function execute(
4646
CartInterface $cart,
47-
QuoteAddress $shippingAddress
47+
AddressInterface $shippingAddress
4848
): void {
4949
try {
5050
$this->shippingAddressManagement->assign($cart->getId(), $shippingAddress);

app/code/Magento/QuoteGraphQl/Model/Cart/AssignShippingMethodToCart.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
use Magento\Framework\Exception\NoSuchEntityException;
1515
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1616
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
17+
use Magento\Quote\Api\Data\AddressInterface;
1718
use Magento\Quote\Api\Data\CartInterface;
18-
use Magento\Quote\Model\Quote\Address as QuoteAddress;
1919

2020
/**
2121
* Assign shipping method to cart
@@ -48,15 +48,15 @@ public function __construct(
4848
* Assign shipping method to cart
4949
*
5050
* @param CartInterface $cart
51-
* @param QuoteAddress $quoteAddress
51+
* @param AddressInterface $quoteAddress
5252
* @param string $carrierCode
5353
* @param string $methodCode
5454
* @throws GraphQlInputException
5555
* @throws GraphQlNoSuchEntityException
5656
*/
5757
public function execute(
5858
CartInterface $cart,
59-
QuoteAddress $quoteAddress,
59+
AddressInterface $quoteAddress,
6060
string $carrierCode,
6161
string $methodCode
6262
): void {

app/code/Magento/QuoteGraphQl/Model/Cart/GetQuoteAddress.php

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,44 +7,38 @@
77

88
namespace Magento\QuoteGraphQl\Model\Cart;
99

10-
use Magento\Customer\Api\AddressRepositoryInterface;
11-
use Magento\Customer\Api\Data\AddressInterface;
12-
use Magento\Framework\Exception\LocalizedException;
13-
use Magento\Framework\Exception\NoSuchEntityException;
1410
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
1511
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1612
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
17-
use Magento\Quote\Model\Quote\Address as QuoteAddress;
18-
use Magento\Quote\Model\Quote\AddressFactory as QuoteAddressFactory;
19-
use Magento\Quote\Model\ResourceModel\Quote\Address as QuoteAddressResource;
20-
13+
use Magento\Quote\Api\Data\AddressInterface;
14+
use Magento\Quote\Api\Data\AddressInterfaceFactory;
15+
use Magento\Quote\Model\ResourceModel\Quote\Address as AddressResource;
2116

2217
/**
2318
* Get quote address
2419
*/
2520
class GetQuoteAddress
2621
{
2722
/**
28-
* @var QuoteAddressFactory
23+
* @var AddressInterfaceFactory
2924
*/
3025
private $quoteAddressFactory;
3126

3227
/**
33-
* @var QuoteAddressResource
28+
* @var AddressResource
3429
*/
3530
private $quoteAddressResource;
3631

3732
/**
38-
* @var AddressRepositoryInterface
33+
* @param AddressInterfaceFactory $quoteAddressFactory
34+
* @param AddressResource $quoteAddressResource
3935
*/
40-
private $addressRepository;
41-
42-
/**
43-
* @param AddressRepositoryInterface $addressRepository
44-
*/
45-
public function __construct(AddressRepositoryInterface $addressRepository)
46-
{
47-
$this->addressRepository = $addressRepository;
36+
public function __construct(
37+
AddressInterfaceFactory $quoteAddressFactory,
38+
AddressResource $quoteAddressResource
39+
) {
40+
$this->quoteAddressFactory = $quoteAddressFactory;
41+
$this->quoteAddressResource = $quoteAddressResource;
4842
}
4943

5044
/**
@@ -57,7 +51,7 @@ public function __construct(AddressRepositoryInterface $addressRepository)
5751
* @throws GraphQlNoSuchEntityException
5852
* @throws GraphQlAuthorizationException
5953
*/
60-
public function execute(int $quoteAddressId, ?int $customerId): QuoteAddress
54+
public function execute(int $quoteAddressId, ?int $customerId): AddressInterface
6155
{
6256
$quoteAddress = $this->quoteAddressFactory->create();
6357

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,13 @@ public function execute(ContextInterface $context, CartInterface $cart, array $b
9797
}
9898

9999
if (null === $customerAddressId) {
100-
$billingAddressInput = $this->quoteAddressFactory->createBasedOnInputData($addressInput);
100+
$billingAddress = $this->quoteAddressFactory->createBasedOnInputData($addressInput);
101101
} else {
102102
$this->checkCustomerAccount->execute($context->getUserId(), $context->getUserType());
103103
$customerAddress = $this->getCustomerAddress->execute((int)$customerAddressId, (int)$context->getUserId());
104-
$billingAddressInput = $this->quoteAddressFactory->createBasedOnCustomerAddress($customerAddress);
104+
$billingAddress = $this->quoteAddressFactory->createBasedOnCustomerAddress($customerAddress);
105105
}
106106

107-
$this->assignBillingAddressToCart->execute($cart, $billingAddressInput, $useForShipping);
107+
$this->assignBillingAddressToCart->execute($cart, $billingAddress, $useForShipping);
108108
}
109109
}

app/code/Magento/QuoteGraphQl/Model/Cart/SetShippingMethodsOnCart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function execute(ContextInterface $context, CartInterface $cart, array $s
6969
}
7070
$methodCode = $shippingMethodInput['method_code'];
7171

72-
$quoteAddress = $this->getQuoteAddress->execute($cartAddressId);
72+
$quoteAddress = $this->getQuoteAddress->execute($cartAddressId, $context->getUserId());
7373

7474
$this->assignShippingMethodToCart->execute($cart, $quoteAddress, $carrierCode, $methodCode);
7575
}

0 commit comments

Comments
 (0)