11
11
use Magento \Framework \GraphQl \Exception \GraphQlInputException ;
12
12
use Magento \GraphQl \Model \Query \ContextInterface ;
13
13
use Magento \Quote \Api \Data \CartInterface ;
14
+ use Magento \Quote \Model \QuoteIdToMaskedQuoteIdInterface ;
14
15
use Magento \Quote \Model \QuoteRepository ;
15
16
16
17
/**
17
18
* Set single shipping address for a specified shopping cart
18
19
*/
19
20
class SetShippingAddressesOnCart implements SetShippingAddressesOnCartInterface
20
21
{
22
+ /**
23
+ * @var QuoteIdToMaskedQuoteIdInterface
24
+ */
25
+ private $ quoteIdToMaskedQuoteId ;
26
+
27
+ /**
28
+ * @var GetCartForUser
29
+ */
30
+ private $ getCartForUser ;
31
+
21
32
/**
22
33
* @var AssignShippingAddressToCart
23
34
*/
@@ -34,15 +45,21 @@ class SetShippingAddressesOnCart implements SetShippingAddressesOnCartInterface
34
45
private $ quoteRepository ;
35
46
36
47
/**
48
+ * @param QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId
49
+ * @param GetCartForUser $getCartForUser
37
50
* @param AssignShippingAddressToCart $assignShippingAddressToCart
38
51
* @param GetShippingAddress $getShippingAddress
39
52
* @param QuoteRepository|null $quoteRepository
40
53
*/
41
54
public function __construct (
55
+ QuoteIdToMaskedQuoteIdInterface $ quoteIdToMaskedQuoteId ,
56
+ GetCartForUser $ getCartForUser ,
42
57
AssignShippingAddressToCart $ assignShippingAddressToCart ,
43
58
GetShippingAddress $ getShippingAddress ,
44
59
QuoteRepository $ quoteRepository = null
45
60
) {
61
+ $ this ->quoteIdToMaskedQuoteId = $ quoteIdToMaskedQuoteId ;
62
+ $ this ->getCartForUser = $ getCartForUser ;
46
63
$ this ->assignShippingAddressToCart = $ assignShippingAddressToCart ;
47
64
$ this ->getShippingAddress = $ getShippingAddress ;
48
65
$ this ->quoteRepository = $ quoteRepository
@@ -81,7 +98,10 @@ public function execute(ContextInterface $context, CartInterface $cart, array $s
81
98
throw $ e ;
82
99
}
83
100
$ this ->assignShippingAddressToCart ->execute ($ cart , $ shippingAddress );
84
- // trigger quote re-evaluation after address change
101
+
102
+ // reload updated cart & trigger quote re-evaluation after address change
103
+ $ maskedId = $ this ->quoteIdToMaskedQuoteId ->execute ((int )$ cart ->getId ());
104
+ $ cart = $ this ->getCartForUser ->execute ($ maskedId , $ context ->getUserId (), $ cart ->getStoreId ());
85
105
$ this ->quoteRepository ->save ($ cart );
86
106
}
87
107
}
0 commit comments