Skip to content

Commit 706a4da

Browse files
authored
ENGCOM-4494: mutations add<Product Type>ProductsToCart dosn't check if the cart is active #455
2 parents 4b841c2 + db2a76c commit 706a4da

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ public function execute(string $cartHash, ?int $customerId): Quote
6969
);
7070
}
7171

72+
if (false === (bool)$cart->getIsActive()) {
73+
throw new GraphQlNoSuchEntityException(
74+
__('Current user does not have an active cart.')
75+
);
76+
}
77+
7278
$cartCustomerId = (int)$cart->getCustomerId();
7379

7480
/* Guest cart, allow operations */

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetCartTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,26 @@ public function testGetNonExistentCart()
114114
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
115115
}
116116

117+
/**
118+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
119+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
120+
* @expectedException \Exception
121+
* @expectedExceptionMessage Current user does not have an active cart.
122+
*/
123+
public function testGetInactiveCart()
124+
{
125+
$quote = $this->quoteFactory->create();
126+
$this->quoteResource->load($quote, 'test_order_with_simple_product_without_address', 'reserved_order_id');
127+
$quote->setCustomerId(1);
128+
$quote->setIsActive(false);
129+
$this->quoteResource->save($quote);
130+
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$quote->getId());
131+
132+
$query = $this->getCartQuery($maskedQuoteId);
133+
134+
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
135+
}
136+
117137
/**
118138
* @param string $maskedQuoteId
119139
* @return string

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetCartTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,24 @@ public function testGetNonExistentCart()
9797
$this->graphQlQuery($query);
9898
}
9999

100+
/**
101+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
102+
* @expectedException \Exception
103+
* @expectedExceptionMessage Current user does not have an active cart.
104+
*/
105+
public function testGetInactiveCart()
106+
{
107+
$quote = $this->quoteFactory->create();
108+
$this->quoteResource->load($quote, 'test_order_with_simple_product_without_address', 'reserved_order_id');
109+
$quote->setIsActive(false);
110+
$this->quoteResource->save($quote);
111+
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$quote->getId());
112+
113+
$query = $this->getCartQuery($maskedQuoteId);
114+
115+
$this->graphQlQuery($query);
116+
}
117+
100118
/**
101119
* @param string $maskedQuoteId
102120
* @return string

0 commit comments

Comments
 (0)