Skip to content

Commit ba89f12

Browse files
authored
Merge pull request #5445 from magento-honey-badgers/honeycombined24
[honey] MC-32270: Cart.applied_gift_cards resolver exception message thrown when removing an item from cart need to be refactored
2 parents ba5f8eb + a5cfbaa commit ba89f12

File tree

13 files changed

+232
-50
lines changed

13 files changed

+232
-50
lines changed

app/code/Magento/PageCache/etc/varnish4.vcl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ sub vcl_recv {
108108
#unset req.http.Cookie;
109109
}
110110

111+
# Authenticated GraphQL requests should not be cached by default
112+
if (req.url ~ "/graphql" && req.http.Authorization ~ "^Bearer") {
113+
return (pass);
114+
}
115+
111116
return (hash);
112117
}
113118

app/code/Magento/PageCache/etc/varnish5.vcl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ sub vcl_recv {
109109
#unset req.http.Cookie;
110110
}
111111

112+
# Authenticated GraphQL requests should not be cached by default
113+
if (req.url ~ "/graphql" && req.http.Authorization ~ "^Bearer") {
114+
return (pass);
115+
}
116+
112117
return (hash);
113118
}
114119

app/code/Magento/PageCache/etc/varnish6.vcl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ sub vcl_recv {
109109
#unset req.http.Cookie;
110110
}
111111

112+
# Authenticated GraphQL requests should not be cached by default
113+
if (req.url ~ "/graphql" && req.http.Authorization ~ "^Bearer") {
114+
return (pass);
115+
}
116+
112117
return (hash);
113118
}
114119

app/code/Magento/Quote/i18n/en_US.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Subtotal,Subtotal
3131
"Cart %1 does not contain item %2","Cart %1 does not contain item %2"
3232
"Could not save quote","Could not save quote"
3333
"Cart %1 doesn't contain item %2","Cart %1 doesn't contain item %2"
34+
"The cart doesn't contain the item","The cart doesn't contain the item"
3435
"Could not remove item from quote","Could not remove item from quote"
3536
"The qty value is required to update quote item.","The qty value is required to update quote item."
3637
"Minimum order amount is %1","Minimum order amount is %1"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
6565
try {
6666
$this->cartItemRepository->deleteById((int)$cart->getId(), $itemId);
6767
} catch (NoSuchEntityException $e) {
68-
throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e);
68+
throw new GraphQlNoSuchEntityException(__('The cart doesn\'t contain the item'));
6969
} catch (LocalizedException $e) {
7070
throw new GraphQlInputException(__($e->getMessage()), $e);
7171
}

app/code/Magento/SendFriendGraphQl/Model/Resolver/SendEmailToFriend.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,14 @@ public function __construct(
4848
*/
4949
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
5050
{
51+
$storeId = $context->getExtensionAttributes()->getStore()->getId();
52+
53+
if (!$this->sendFriendHelper->isEnabled($storeId)) {
54+
throw new GraphQlInputException(__('"Email to a Friend" is not enabled.'));
55+
}
56+
5157
/** @var ContextInterface $context */
52-
if (!$this->sendFriendHelper->isAllowForGuest()
58+
if (!$this->sendFriendHelper->isAllowForGuest($storeId)
5359
&& false === $context->getExtensionAttributes()->getIsCustomer()
5460
) {
5561
throw new GraphQlAuthorizationException(__('The current customer isn\'t authorized.'));
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\SendFriendGraphQl\Model\Resolver;
9+
10+
use Magento\Framework\GraphQl\Config\Element\Field;
11+
use Magento\Framework\GraphQl\Query\ResolverInterface;
12+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
13+
use Magento\SendFriend\Helper\Data as SendFriendHelper;
14+
15+
/**
16+
* Resolve Store Config information for SendFriend
17+
*/
18+
class SendFriendConfiguration implements ResolverInterface
19+
{
20+
/**
21+
* @var SendFriendHelper
22+
*/
23+
private $sendFriendHelper;
24+
25+
/**
26+
* @param SendFriendHelper $sendFriendHelper
27+
*/
28+
public function __construct(SendFriendHelper $sendFriendHelper)
29+
{
30+
$this->sendFriendHelper = $sendFriendHelper;
31+
}
32+
33+
/**
34+
* @inheritDoc
35+
*/
36+
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
37+
{
38+
$store = $context->getExtensionAttributes()->getStore();
39+
$storeId = $store->getId();
40+
41+
return [
42+
'enabled_for_customers' => $this->sendFriendHelper->isEnabled($storeId),
43+
'enabled_for_guests' => $this->sendFriendHelper->isAllowForGuest($storeId)
44+
];
45+
}
46+
}

app/code/Magento/SendFriendGraphQl/etc/schema.graphqls

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,12 @@ type SendEmailToFriendRecipient {
3737
name: String!
3838
email: String!
3939
}
40+
41+
type StoreConfig {
42+
send_friend: SendFriendConfiguration @resolver(class: "\\Magento\\SendFriendGraphQl\\Model\\Resolver\\SendFriendConfiguration") @doc(description: "Email to a Friend configuration.")
43+
}
44+
45+
type SendFriendConfiguration {
46+
enabled_for_customers: Boolean! @doc(description: "Indicates whether the Email to a Friend feature is enabled.")
47+
enabled_for_guests: Boolean! @doc(description: "Indicates whether the Email to a Friend feature is enabled for guests.")
48+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function testRemoveNonExistentItem()
8484
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
8585
$notExistentItemId = 999;
8686

87-
$this->expectExceptionMessage("Cart doesn't contain the {$notExistentItemId} item.");
87+
$this->expectExceptionMessage("The cart doesn't contain the item");
8888

8989
$query = $this->getQuery($maskedQuoteId, $notExistentItemId);
9090
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
@@ -106,7 +106,7 @@ public function testRemoveItemIfItemIsNotBelongToCart()
106106
'virtual-product'
107107
);
108108

109-
$this->expectExceptionMessage("Cart doesn't contain the {$secondQuoteItemId} item.");
109+
$this->expectExceptionMessage("The cart doesn't contain the item");
110110

111111
$query = $this->getQuery($firstQuoteMaskedId, $secondQuoteItemId);
112112
$this->graphQlMutation($query, [], '', $this->getHeaderMap());

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function testRemoveNonExistentItem()
7474
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
7575
$notExistentItemId = 999;
7676

77-
$this->expectExceptionMessage("Cart doesn't contain the {$notExistentItemId} item.");
77+
$this->expectExceptionMessage("The cart doesn't contain the item");
7878

7979
$query = $this->getQuery($maskedQuoteId, $notExistentItemId);
8080
$this->graphQlMutation($query);
@@ -95,7 +95,7 @@ public function testRemoveItemIfItemIsNotBelongToCart()
9595
'virtual-product'
9696
);
9797

98-
$this->expectExceptionMessage("Cart doesn't contain the {$secondQuoteItemId} item.");
98+
$this->expectExceptionMessage("The cart doesn't contain the item");
9999

100100
$query = $this->getQuery($firstQuoteMaskedId, $secondQuoteItemId);
101101
$this->graphQlMutation($query);

0 commit comments

Comments
 (0)