Skip to content

Commit 139ddea

Browse files
🔃 [GraphQL] Community Contributions - 2.4-develop expedited-1
Accepted Community Pull Requests: - #28205: [GraphQl] Adding Wishlist GraphQl coverage (by @eduard13) - #28072: [GraphQl] Gift Message coverage for cart item (by @Usik2203) Fixed GitHub Issues: - #246: GD2 not working in WYSIWYG (reported by @barbazul) has been fixed in #28072 by @Usik2203 in 2.4-develop branch Related commits: 1. 034af40 2. 7e6e023 3. 81737c0 4. 120a105 5. 035c157 6. 8ed5018 7. cea930b 8. dabbd3c 9. f6ce31d 10. a2f28d8 11. 233b695 12. d127c98 13. d9748d2 14. d994276 15. 938e43b 16. d339ae8 - #253: PHP Extension 0 must be loaded - XML Parse mistake? (reported by @ScreamingDev) has been fixed in #28072 by @Usik2203 in 2.4-develop branch Related commits: 1. 034af40 2. 7e6e023 3. 81737c0 4. 120a105 5. 035c157 6. 8ed5018 7. cea930b 8. dabbd3c 9. f6ce31d 10. a2f28d8 11. 233b695 12. d127c98 13. d9748d2 14. d994276 15. 938e43b 16. d339ae8 - #28519: GraphQL Checkout :: Add support for Gift Wrapping / Gift Message during checkout. (reported by @nrkapoor) has been fixed in #28072 by @Usik2203 in 2.4-develop branch Related commits: 1. 034af40 2. 7e6e023 3. 81737c0 4. 120a105 5. 035c157 6. 8ed5018 7. cea930b 8. dabbd3c 9. f6ce31d 10. a2f28d8 11. 233b695 12. d127c98 13. d9748d2 14. d994276 15. 938e43b 16. d339ae8
2 parents 02b87f6 + 4fbeae4 commit 139ddea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+3569
-73
lines changed

app/code/Magento/GiftMessageGraphQl/Model/Resolver/Cart/GiftMessage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function resolve(
6666
array $args = null
6767
) {
6868
if (!isset($value['model'])) {
69-
throw new GraphQlInputException(__('"model" value should be specified'));
69+
throw new GraphQlInputException(__('"model" value must be specified'));
7070
}
7171

7272
$cart = $value['model'];
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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\GiftMessageGraphQl\Model\Resolver\Cart\Item;
9+
10+
use Magento\Framework\Exception\LocalizedException;
11+
use Magento\Framework\GraphQl\Config\Element\Field;
12+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
13+
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
14+
use Magento\Framework\GraphQl\Query\Resolver\Value;
15+
use Magento\Framework\GraphQl\Query\ResolverInterface;
16+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
17+
use Magento\GiftMessage\Api\ItemRepositoryInterface;
18+
use Magento\GiftMessage\Helper\Message as GiftMessageHelper;
19+
20+
/**
21+
* Class provides ability to get GiftMessage for cart item
22+
*/
23+
class GiftMessage implements ResolverInterface
24+
{
25+
/**
26+
* @var ItemRepositoryInterface
27+
*/
28+
private $itemRepository;
29+
30+
/**
31+
* @var GiftMessageHelper
32+
*/
33+
private $giftMessageHelper;
34+
35+
/**
36+
* @param ItemRepositoryInterface $itemRepository
37+
* @param GiftMessageHelper $giftMessageHelper
38+
*/
39+
public function __construct(
40+
ItemRepositoryInterface $itemRepository,
41+
GiftMessageHelper $giftMessageHelper
42+
) {
43+
$this->itemRepository = $itemRepository;
44+
$this->giftMessageHelper = $giftMessageHelper;
45+
}
46+
47+
/**
48+
* Return information about Gift message for item cart
49+
*
50+
* @param Field $field
51+
* @param ContextInterface $context
52+
* @param ResolveInfo $info
53+
* @param array|null $value
54+
* @param array|null $args
55+
*
56+
* @return array|Value|mixed
57+
* @throws GraphQlInputException
58+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
59+
*/
60+
public function resolve(
61+
Field $field,
62+
$context,
63+
ResolveInfo $info,
64+
array $value = null,
65+
array $args = null
66+
) {
67+
if (!isset($value['model'])) {
68+
throw new GraphQlInputException(__('"model" value must be specified'));
69+
}
70+
71+
$quoteItem = $value['model'];
72+
73+
if (!$this->giftMessageHelper->isMessagesAllowed('items', $quoteItem)) {
74+
return null;
75+
}
76+
77+
if (!$this->giftMessageHelper->isMessagesAllowed('item', $quoteItem)) {
78+
return null;
79+
}
80+
81+
try {
82+
$giftItemMessage = $this->itemRepository->get($quoteItem->getQuoteId(), $quoteItem->getItemId());
83+
} catch (LocalizedException $e) {
84+
throw new GraphQlInputException(__('Can\'t load cart item'));
85+
}
86+
87+
if (!isset($giftItemMessage)) {
88+
return null;
89+
}
90+
91+
return [
92+
'to' => $giftItemMessage->getRecipient() ?? '',
93+
'from' => $giftItemMessage->getSender() ?? '',
94+
'message'=> $giftItemMessage->getMessage() ?? ''
95+
];
96+
}
97+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# GiftMessageGraphQl
22

3-
**GiftMessageGraphQl** provides information about gift messages for cart, cart items, order and order items.
3+
**GiftMessageGraphQl** provides information about gift messages for carts, cart items, orders and order items.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
10+
<type name="Magento\StoreGraphQl\Model\Resolver\Store\StoreConfigDataProvider">
11+
<arguments>
12+
<argument name="extendedConfigData" xsi:type="array">
13+
<item name="allow_order" xsi:type="string">sales/gift_options/allow_order</item>
14+
<item name="allow_items" xsi:type="string">sales/gift_options/allow_items</item>
15+
</argument>
16+
</arguments>
17+
</type>
18+
</config>
Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,47 @@
11
# Copyright © Magento, Inc. All rights reserved.
22
# See COPYING.txt for license details.
33

4+
type StoreConfig {
5+
allow_order : String @doc(description: "The value of the Allow Gift Messages on Order Level option")
6+
allow_items : String @doc(description: "The value of the Allow Gift Messages for Order Items option")
7+
}
8+
49
type Cart {
510
gift_message: GiftMessage @resolver (class: "\\Magento\\GiftMessageGraphQl\\Model\\Resolver\\Cart\\GiftMessage") @doc(description: "The entered gift message for the cart")
611
}
712

8-
type SalesItemInterface {
9-
gift_message: GiftMessage @doc(description: "The entered gift message for the order item")
13+
type SimpleCartItem {
14+
gift_message: GiftMessage @resolver (class: "\\Magento\\GiftMessageGraphQl\\Model\\Resolver\\Cart\\Item\\GiftMessage") @doc(description: "The entered gift message for the cart item")
1015
}
1116

12-
type CustomerOrder {
13-
gift_message: GiftMessage @resolver (class: "\\Magento\\GiftMessageGraphQl\\Model\\Resolver\\Order\\GiftMessage") @doc(description: "The entered gift message for the order")
17+
type ConfigurableCartItem {
18+
gift_message: GiftMessage @resolver (class: "\\Magento\\GiftMessageGraphQl\\Model\\Resolver\\Cart\\Item\\GiftMessage") @doc(description: "The entered gift message for the cart item")
19+
}
20+
21+
type BundleCartItem {
22+
gift_message: GiftMessage @resolver (class: "\\Magento\\GiftMessageGraphQl\\Model\\Resolver\\Cart\\Item\\GiftMessage") @doc(description: "The entered gift message for the cart item")
23+
}
24+
25+
type GiftMessage @doc(description: "Contains the text of a gift message, its sender, and recipient") {
26+
to: String! @doc(description: "Recipient name")
27+
from: String! @doc(description: "Sender name")
28+
message: String! @doc(description: "Gift message text")
29+
}
30+
31+
input CartItemUpdateInput {
32+
gift_message: GiftMessageInput @doc(description: "Gift message details for the cart item")
1433
}
1534

16-
type GiftMessage {
17-
to: String! @doc(description: "Recepient name")
35+
input GiftMessageInput @doc(description: "Contains the text of a gift message, its sender, and recipient") {
36+
to: String! @doc(description: "Recipient name")
1837
from: String! @doc(description: "Sender name")
1938
message: String! @doc(description: "Gift message text")
2039
}
40+
41+
type SalesItemInterface {
42+
gift_message: GiftMessage @doc(description: "The entered gift message for the order item")
43+
}
44+
45+
type CustomerOrder {
46+
gift_message: GiftMessage @resolver (class: "\\Magento\\GiftMessageGraphQl\\Model\\Resolver\\Order\\GiftMessage") @doc(description: "The entered gift message for the order")
47+
}
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
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\QuoteGraphQl\Model\CartItem\DataProvider;
9+
10+
use Magento\Framework\Exception\LocalizedException;
11+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
12+
use Magento\GiftMessage\Api\Data\MessageInterface;
13+
use Magento\GiftMessage\Api\Data\MessageInterfaceFactory;
14+
use Magento\GiftMessage\Api\ItemRepositoryInterface;
15+
use Magento\GiftMessage\Helper\Message as GiftMessageHelper;
16+
use Magento\Quote\Api\CartItemRepositoryInterface;
17+
use Magento\Quote\Model\Quote;
18+
use Magento\QuoteGraphQl\Model\Cart\UpdateCartItem;
19+
20+
/**
21+
* Class contain update cart items methods
22+
*/
23+
class UpdateCartItems
24+
{
25+
/**
26+
* @var CartItemRepositoryInterface
27+
*/
28+
private $cartItemRepository;
29+
30+
/**
31+
* @var UpdateCartItem
32+
*/
33+
private $updateCartItem;
34+
35+
/**
36+
* @var ItemRepositoryInterface
37+
*/
38+
private $itemRepository;
39+
40+
/**
41+
* @var GiftMessageHelper
42+
*/
43+
private $giftMessageHelper;
44+
45+
/**
46+
* @var MessageInterfaceFactory
47+
*/
48+
private $giftMessageFactory;
49+
50+
/**
51+
* @param CartItemRepositoryInterface $cartItemRepository
52+
* @param UpdateCartItem $updateCartItem
53+
* @param ItemRepositoryInterface $itemRepository
54+
* @param GiftMessageHelper $giftMessageHelper
55+
* @param MessageInterfaceFactory $giftMessageFactory
56+
*/
57+
public function __construct(
58+
CartItemRepositoryInterface $cartItemRepository,
59+
UpdateCartItem $updateCartItem,
60+
ItemRepositoryInterface $itemRepository,
61+
GiftMessageHelper $giftMessageHelper,
62+
MessageInterfaceFactory $giftMessageFactory
63+
) {
64+
$this->cartItemRepository = $cartItemRepository;
65+
$this->updateCartItem = $updateCartItem;
66+
$this->itemRepository = $itemRepository;
67+
$this->giftMessageHelper = $giftMessageHelper;
68+
$this->giftMessageFactory = $giftMessageFactory;
69+
}
70+
71+
/**
72+
* Process cart items
73+
*
74+
* @param Quote $cart
75+
* @param array $items
76+
*
77+
* @throws GraphQlInputException
78+
* @throws LocalizedException
79+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
80+
* @SuppressWarnings(PHPMD.NPathComplexity)
81+
*/
82+
public function processCartItems(Quote $cart, array $items): void
83+
{
84+
foreach ($items as $item) {
85+
if (empty($item['cart_item_id'])) {
86+
throw new GraphQlInputException(__('Required parameter "cart_item_id" for "cart_items" is missing.'));
87+
}
88+
89+
$itemId = (int)$item['cart_item_id'];
90+
$customizableOptions = $item['customizable_options'] ?? [];
91+
$cartItem = $cart->getItemById($itemId);
92+
93+
if ($cartItem && $cartItem->getParentItemId()) {
94+
throw new GraphQlInputException(__('Child items may not be updated.'));
95+
}
96+
97+
if (count($customizableOptions) === 0 && !isset($item['quantity'])) {
98+
throw new GraphQlInputException(__('Required parameter "quantity" for "cart_items" is missing.'));
99+
}
100+
101+
$quantity = (float)$item['quantity'];
102+
103+
if ($quantity <= 0.0) {
104+
$this->cartItemRepository->deleteById((int)$cart->getId(), $itemId);
105+
} else {
106+
$this->updateCartItem->execute($cart, $itemId, $quantity, $customizableOptions);
107+
}
108+
109+
if (!empty($item['gift_message'])) {
110+
try {
111+
if (!$this->giftMessageHelper->isMessagesAllowed('items', $cartItem)) {
112+
continue;
113+
}
114+
if (!$this->giftMessageHelper->isMessagesAllowed('item', $cartItem)) {
115+
continue;
116+
}
117+
118+
/** @var MessageInterface $giftItemMessage */
119+
$giftItemMessage = $this->itemRepository->get($cart->getEntityId(), $itemId);
120+
121+
if (empty($giftItemMessage)) {
122+
/** @var MessageInterface $giftMessage */
123+
$giftMessage = $this->giftMessageFactory->create();
124+
$this->updateGiftMessageForItem($cart, $giftMessage, $item, $itemId);
125+
continue;
126+
}
127+
} catch (LocalizedException $exception) {
128+
throw new GraphQlInputException(__('Gift Message cannot be updated.'));
129+
}
130+
131+
$this->updateGiftMessageForItem($cart, $giftItemMessage, $item, $itemId);
132+
}
133+
}
134+
}
135+
136+
/**
137+
* Update Gift Message for Quote item
138+
*
139+
* @param Quote $cart
140+
* @param MessageInterface $giftItemMessage
141+
* @param array $item
142+
* @param int $itemId
143+
*
144+
* @throws GraphQlInputException
145+
*/
146+
private function updateGiftMessageForItem(Quote $cart, MessageInterface $giftItemMessage, array $item, int $itemId)
147+
{
148+
try {
149+
$giftItemMessage->setRecipient($item['gift_message']['to']);
150+
$giftItemMessage->setSender($item['gift_message']['from']);
151+
$giftItemMessage->setMessage($item['gift_message']['message']);
152+
$this->itemRepository->save($cart->getEntityId(), $giftItemMessage, $itemId);
153+
} catch (LocalizedException $exception) {
154+
throw new GraphQlInputException(__('Gift Message cannot be updated'));
155+
}
156+
}
157+
}

0 commit comments

Comments
 (0)