Skip to content

Commit efb6094

Browse files
Merge branch '2.4-develop' into AC-13818
2 parents 57f5690 + 4c8123c commit efb6094

File tree

20 files changed

+1238
-186
lines changed

20 files changed

+1238
-186
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\GiftMessageGraphQl\Model\Config;
9+
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Catalog\Model\Product\Attribute\Source\Boolean;
12+
use Magento\Framework\DataObject;
13+
use Magento\Quote\Model\Quote\Item;
14+
use Magento\Store\Model\ScopeInterface;
15+
use Magento\Store\Model\Store;
16+
17+
class Messages
18+
{
19+
public const XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ITEMS = 'sales/gift_options/allow_items';
20+
21+
/**
22+
* Messages Constructor
23+
*
24+
* @param ScopeConfigInterface $scopeConfig
25+
*/
26+
public function __construct(
27+
private readonly ScopeConfigInterface $scopeConfig,
28+
) {
29+
}
30+
31+
/**
32+
* Check if gift message allowed for specified entity
33+
*
34+
* @param string $type
35+
* @param DataObject $entity
36+
* @param int|Store|null $store
37+
* @return bool
38+
*/
39+
public function isMessagesAllowed(
40+
string $type,
41+
DataObject $entity,
42+
int|Store|null $store = null
43+
): bool {
44+
if ($type === 'items' && !empty($entity->getAllItems())) {
45+
foreach ($entity->getAllItems() as $item) {
46+
if (!$item->getParentItem() && $this->isMessagesAllowed('item', $item, $store)) {
47+
return true;
48+
}
49+
}
50+
}
51+
52+
return $this->isGiftMessageAllowedForProduct(
53+
($type === 'item' || $entity instanceof Item) ?
54+
$entity->getProduct()->getGiftMessageAvailable() : null,
55+
$store
56+
);
57+
}
58+
59+
/**
60+
* Check if gift message allowed for specified product
61+
*
62+
* @param string|null $productConfig
63+
* @param Store|int|null $store
64+
* @return bool
65+
*/
66+
public function isGiftMessageAllowedForProduct(
67+
?string $productConfig,
68+
Store|int|null $store
69+
): bool {
70+
return in_array($productConfig, [null, '', Boolean::VALUE_USE_CONFIG])
71+
? (bool) $this->scopeConfig->getValue(
72+
self::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ITEMS,
73+
ScopeInterface::SCOPE_STORE,
74+
$store
75+
) : (bool) $productConfig;
76+
}
77+
}

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

+11-21
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -15,33 +15,23 @@
1515
use Magento\Framework\GraphQl\Query\ResolverInterface;
1616
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1717
use Magento\GiftMessage\Api\ItemRepositoryInterface;
18-
use Magento\GiftMessage\Helper\Message as GiftMessageHelper;
18+
use Magento\GiftMessageGraphQl\Model\Config\Messages;
1919

2020
/**
2121
* Class provides ability to get GiftMessage for cart item
2222
*/
2323
class GiftMessage implements ResolverInterface
2424
{
2525
/**
26-
* @var ItemRepositoryInterface
27-
*/
28-
private $itemRepository;
29-
30-
/**
31-
* @var GiftMessageHelper
32-
*/
33-
private $giftMessageHelper;
34-
35-
/**
26+
* GiftMessage Constructor
27+
*
3628
* @param ItemRepositoryInterface $itemRepository
37-
* @param GiftMessageHelper $giftMessageHelper
29+
* @param Messages $messagesConfig
3830
*/
3931
public function __construct(
40-
ItemRepositoryInterface $itemRepository,
41-
GiftMessageHelper $giftMessageHelper
32+
private readonly ItemRepositoryInterface $itemRepository,
33+
private readonly Messages $messagesConfig
4234
) {
43-
$this->itemRepository = $itemRepository;
44-
$this->giftMessageHelper = $giftMessageHelper;
4535
}
4636

4737
/**
@@ -70,11 +60,11 @@ public function resolve(
7060

7161
$quoteItem = $value['model'];
7262

73-
if (!$this->giftMessageHelper->isMessagesAllowed('items', $quoteItem)) {
63+
if (!$this->messagesConfig->isMessagesAllowed('items', $quoteItem)) {
7464
return null;
7565
}
7666

77-
if (!$this->giftMessageHelper->isMessagesAllowed('item', $quoteItem)) {
67+
if (!$this->messagesConfig->isMessagesAllowed('item', $quoteItem)) {
7868
return null;
7969
}
8070

@@ -84,7 +74,7 @@ public function resolve(
8474
throw new GraphQlInputException(__('Can\'t load cart item'));
8575
}
8676

87-
if (!isset($giftItemMessage)) {
77+
if (!$giftItemMessage) {
8878
return null;
8979
}
9080

app/code/Magento/GiftMessageGraphQl/Model/Resolver/Order/Item/GiftMessage.php

+11-20
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -16,32 +16,23 @@
1616
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1717
use Magento\GiftMessage\Api\OrderItemRepositoryInterface;
1818
use Magento\GiftMessage\Helper\Message as GiftMessageHelper;
19+
use Magento\GiftMessageGraphQl\Model\Config\Messages;
1920

2021
/**
2122
* Class provides ability to get GiftMessage for order item
2223
*/
2324
class GiftMessage implements ResolverInterface
2425
{
2526
/**
26-
* @var OrderItemRepositoryInterface
27-
*/
28-
private $orderItemRepository;
29-
30-
/**
31-
* @var GiftMessageHelper
32-
*/
33-
private $giftMessageHelper;
34-
35-
/**
36-
* @param OrderItemRepositoryInterface $itemRepository
37-
* @param GiftMessageHelper $giftMessageHelper
27+
* GiftMessage Constructor
28+
*
29+
* @param OrderItemRepositoryInterface $orderItemRepository
30+
* @param Messages $messagesConfig
3831
*/
3932
public function __construct(
40-
OrderItemRepositoryInterface $itemRepository,
41-
GiftMessageHelper $giftMessageHelper
33+
private readonly OrderItemRepositoryInterface $orderItemRepository,
34+
private readonly Messages $messagesConfig
4235
) {
43-
$this->orderItemRepository = $itemRepository;
44-
$this->giftMessageHelper = $giftMessageHelper;
4536
}
4637

4738
/**
@@ -70,11 +61,11 @@ public function resolve(
7061

7162
$orderItem = $value['model'];
7263

73-
if (!$this->giftMessageHelper->isMessagesAllowed('items', $orderItem)) {
64+
if (!$this->messagesConfig->isMessagesAllowed('items', $orderItem)) {
7465
return null;
7566
}
7667

77-
if (!$this->giftMessageHelper->isMessagesAllowed('item', $orderItem)) {
68+
if (!$this->messagesConfig->isMessagesAllowed('item', $orderItem)) {
7869
return null;
7970
}
8071

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\GiftMessageGraphQl\Model\Resolver\Product;
9+
10+
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\Catalog\Model\Product\Type as Virtual;
12+
use Magento\Downloadable\Model\Product\Type as Downloadable;
13+
use Magento\Framework\Exception\LocalizedException;
14+
use Magento\Framework\GraphQl\Config\Element\Field;
15+
use Magento\Framework\GraphQl\Query\ResolverInterface;
16+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
17+
use Magento\GiftMessageGraphQl\Model\Config\Messages;
18+
19+
class GiftMessage implements ResolverInterface
20+
{
21+
/**
22+
* @param Messages $messagesConfig
23+
*/
24+
public function __construct(
25+
private readonly Messages $messagesConfig
26+
) {
27+
}
28+
29+
/**
30+
* @inheritDoc
31+
*/
32+
public function resolve(
33+
Field $field,
34+
$context,
35+
ResolveInfo $info,
36+
array $value = null,
37+
array $args = null
38+
): bool {
39+
if (!isset($value['model']) || !$value['model'] instanceof ProductInterface) {
40+
throw new LocalizedException(__('The product model is not available.'));
41+
}
42+
43+
if (in_array($value['model']['type_id'], [Virtual::TYPE_VIRTUAL, Downloadable::TYPE_DOWNLOADABLE], true)) {
44+
return false;
45+
}
46+
47+
return $this->messagesConfig->isGiftMessageAllowedForProduct(
48+
$value['model']->getGiftMessageAvailable(),
49+
$context->getExtensionAttributes()->getStore()
50+
);
51+
}
52+
}

app/code/Magento/GiftMessageGraphQl/composer.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
"require": {
66
"php": "~8.2.0||~8.3.0||~8.4.0",
77
"magento/framework": "*",
8-
"magento/module-gift-message": "*"
8+
"magento/module-gift-message": "*",
9+
"magento/module-catalog": "*",
10+
"magento/module-quote": "*",
11+
"magento/module-store": "*",
12+
"magento/module-downloadable": "*"
13+
914
},
1015
"suggest": {
1116
"magento/module-graph-ql": "*"

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Copyright © Magento, Inc. All rights reserved.
2-
# See COPYING.txt for license details.
1+
# Copyright 2025 Adobe
2+
# All Rights Reserved.
33

44
type StoreConfig {
55
allow_order : String @doc(description: "The value of the Allow Gift Messages on Order Level option")
@@ -49,3 +49,7 @@ type CustomerOrder {
4949
interface OrderItemInterface {
5050
gift_message: GiftMessage @resolver(class: "\\Magento\\GiftMessageGraphQl\\Model\\Resolver\\Order\\Item\\GiftMessage") @doc(description: "The selected gift message for the order item")
5151
}
52+
53+
interface ProductInterface {
54+
gift_message_available: Boolean! @doc(description: "Returns a value indicating gift message availability for the product.") @resolver(class: "\\Magento\\GiftMessageGraphQl\\Model\\Resolver\\Product\\GiftMessage")
55+
}

app/code/Magento/OrderCancellationGraphQl/Model/CancelOrderGuest.php

+11-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Sales\Api\OrderRepositoryInterface;
1515
use Magento\Sales\Model\Order;
1616
use Magento\SalesGraphQl\Model\Formatter\Order as OrderFormatter;
17+
use Magento\SalesGraphQl\Model\Order\Token;
1718

1819
class CancelOrderGuest
1920
{
@@ -25,13 +26,15 @@ class CancelOrderGuest
2526
* @param ConfirmationKeySender $confirmationKeySender
2627
* @param GetConfirmationKey $confirmationKey
2728
* @param Uid $idEncoder
29+
* @param Token $token
2830
*/
2931
public function __construct(
3032
private readonly OrderFormatter $orderFormatter,
3133
private readonly OrderRepositoryInterface $orderRepository,
3234
private readonly ConfirmationKeySender $confirmationKeySender,
3335
private readonly GetConfirmationKey $confirmationKey,
34-
private readonly Uid $idEncoder
36+
private readonly Uid $idEncoder,
37+
private readonly Token $token
3538
) {
3639
}
3740

@@ -72,7 +75,13 @@ private function sendConfirmationKeyEmail(Order $order, string $reason): void
7275
$order,
7376
[
7477
'order_id' => $this->idEncoder->encode((string)$order->getEntityId()),
75-
'confirmation_key' => $this->confirmationKey->execute($order, $reason)
78+
'confirmation_key' => $this->confirmationKey->execute($order, $reason),
79+
'orderRef' => $this->token->encrypt(
80+
$order->getIncrementId(),
81+
$order->getBillingAddress()->getEmail(),
82+
$order->getBillingAddress()->getLastname()
83+
),
84+
'action' => 'cancel'
7685
]
7786
);
7887

0 commit comments

Comments
 (0)