Skip to content

Commit 2ada15f

Browse files
cia-2.4.7-beta1-bugfixes-02162023
Merge branch 'AC-7832' into cia-2.4.7-beta1-develop-bugfixes-02162023
2 parents 568c7bf + 764c519 commit 2ada15f

File tree

2 files changed

+51
-6
lines changed

2 files changed

+51
-6
lines changed

app/code/Magento/QuoteGraphQl/Model/Resolver/RemoveItemFromCart.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
8686
$itemId = $processedArgs['input']['cart_item_id'];
8787

8888
$storeId = (int)$context->getExtensionAttributes()->getStore()->getId();
89+
/** Check if the current user is allowed to perform actions with the cart */
90+
$cart = $this->getCartForUser->execute($maskedCartId, $context->getUserId(), $storeId);
8991

9092
try {
9193
$this->cartItemRepository->deleteById($cartId, $itemId);
@@ -95,7 +97,6 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
9597
throw new GraphQlInputException(__($e->getMessage()), $e);
9698
}
9799

98-
$cart = $this->getCartForUser->execute($maskedCartId, $context->getUserId(), $storeId);
99100
return [
100101
'cart' => [
101102
'model' => $cart,

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

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\GraphQl\Quote\GetQuoteItemIdByReservedQuoteIdAndSku;
1212
use Magento\Integration\Api\CustomerTokenServiceInterface;
1313
use Magento\TestFramework\Helper\Bootstrap;
14+
use Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException;
1415
use Magento\TestFramework\TestCase\GraphQlAbstract;
1516

1617
/**
@@ -147,13 +148,56 @@ public function testRemoveItemFromAnotherCustomerCart()
147148
'test_quote',
148149
'simple_product'
149150
);
151+
$query = $this->getQuery($anotherCustomerQuoteMaskedId, $anotherCustomerQuoteItemId);
150152

151-
$this->expectExceptionMessage(
152-
"The current user cannot perform operations on cart \"$anotherCustomerQuoteMaskedId\""
153-
);
153+
try {
154+
$this->graphQlMutation(
155+
$query,
156+
[],
157+
'',
158+
$this->getHeaderMap('customer2@search.example.com')
159+
);
160+
$this->fail('ResponseContainsErrorsException was not thrown');
161+
} catch (ResponseContainsErrorsException $e) {
162+
$this->assertStringContainsString(
163+
"The current user cannot perform operations on cart \"$anotherCustomerQuoteMaskedId\"",
164+
$e->getMessage()
165+
);
166+
$cartQuery = $this->getCartQuery($anotherCustomerQuoteMaskedId);
167+
$cart = $this->graphQlQuery(
168+
$cartQuery,
169+
[],
170+
'',
171+
$this->getHeaderMap('customer@search.example.com')
172+
);
173+
$this->assertTrue(count($cart['cart']['items']) > 0, 'The cart is empty');
174+
$this->assertTrue(
175+
$cart['cart']['items'][0]['product']['sku'] === 'simple_product',
176+
'The cart doesn\'t contain product'
177+
);
178+
}
179+
}
154180

155-
$query = $this->getQuery($anotherCustomerQuoteMaskedId, $anotherCustomerQuoteItemId);
156-
$this->graphQlMutation($query, [], '', $this->getHeaderMap('customer2@search.example.com'));
181+
/**
182+
* @param string $maskedQuoteId
183+
* @return string
184+
*/
185+
private function getCartQuery(string $maskedQuoteId): string
186+
{
187+
return <<<QUERY
188+
{
189+
cart(cart_id: "{$maskedQuoteId}") {
190+
id
191+
items {
192+
id
193+
quantity
194+
product {
195+
sku
196+
}
197+
}
198+
}
199+
}
200+
QUERY;
157201
}
158202

159203
/**

0 commit comments

Comments
 (0)