Skip to content

Commit 4d4a982

Browse files
committed
mutations add<Product Type>ProductsToCart dosn't check if the cart is active
1 parent 2363896 commit 4d4a982

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

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

Lines changed: 6 additions & 10 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 (!$cart->getIsActive()) {
73+
throw new GraphQlNoSuchEntityException(
74+
__('Current customer does not have an active cart.')
75+
);
76+
}
77+
7278
$cartCustomerId = (int)$cart->getCustomerId();
7379

7480
/* Guest cart, allow operations */
@@ -84,16 +90,6 @@ public function execute(string $cartHash, ?int $customerId): Quote
8490
)
8591
);
8692
}
87-
88-
if ($customerId) {
89-
try {
90-
return $this->cartRepository->getActiveForCustomer($customerId);
91-
} catch (\Exception $e) {
92-
throw new GraphQlNoSuchEntityException(
93-
__($e->getMessage())
94-
);
95-
}
96-
}
9793
return $cart;
9894
}
9995
}

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 customer 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

0 commit comments

Comments
 (0)