Skip to content

Commit e9f3712

Browse files
committed
MC-37484: Cart query error when trying to switch store view
1 parent 08c2692 commit e9f3712

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,24 @@
1111
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1212
use Magento\GraphQl\Model\Query\ContextInterface;
1313
use Magento\Quote\Api\Data\CartInterface;
14+
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
1415
use Magento\Quote\Model\QuoteRepository;
1516

1617
/**
1718
* Set single shipping address for a specified shopping cart
1819
*/
1920
class SetShippingAddressesOnCart implements SetShippingAddressesOnCartInterface
2021
{
22+
/**
23+
* @var QuoteIdToMaskedQuoteIdInterface
24+
*/
25+
private $quoteIdToMaskedQuoteId;
26+
27+
/**
28+
* @var GetCartForUser
29+
*/
30+
private $getCartForUser;
31+
2132
/**
2233
* @var AssignShippingAddressToCart
2334
*/
@@ -34,15 +45,21 @@ class SetShippingAddressesOnCart implements SetShippingAddressesOnCartInterface
3445
private $quoteRepository;
3546

3647
/**
48+
* @param QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId
49+
* @param GetCartForUser $getCartForUser
3750
* @param AssignShippingAddressToCart $assignShippingAddressToCart
3851
* @param GetShippingAddress $getShippingAddress
3952
* @param QuoteRepository|null $quoteRepository
4053
*/
4154
public function __construct(
55+
QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId,
56+
GetCartForUser $getCartForUser,
4257
AssignShippingAddressToCart $assignShippingAddressToCart,
4358
GetShippingAddress $getShippingAddress,
4459
QuoteRepository $quoteRepository = null
4560
) {
61+
$this->quoteIdToMaskedQuoteId = $quoteIdToMaskedQuoteId;
62+
$this->getCartForUser = $getCartForUser;
4663
$this->assignShippingAddressToCart = $assignShippingAddressToCart;
4764
$this->getShippingAddress = $getShippingAddress;
4865
$this->quoteRepository = $quoteRepository
@@ -81,7 +98,10 @@ public function execute(ContextInterface $context, CartInterface $cart, array $s
8198
throw $e;
8299
}
83100
$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());
85105
$this->quoteRepository->save($cart);
86106
}
87107
}

0 commit comments

Comments
 (0)