|
10 | 10 | use Magento\Framework\Exception\LocalizedException;
|
11 | 11 | use Magento\Framework\GraphQl\Exception\GraphQlInputException;
|
12 | 12 | use Magento\GiftMessage\Api\Data\MessageInterface;
|
| 13 | +use Magento\GiftMessage\Api\Data\MessageInterfaceFactory; |
13 | 14 | use Magento\GiftMessage\Api\ItemRepositoryInterface;
|
14 | 15 | use Magento\GiftMessage\Helper\Message as GiftMessageHelper;
|
15 | 16 | use Magento\Quote\Api\CartItemRepositoryInterface;
|
@@ -41,22 +42,30 @@ class UpdateCartItems
|
41 | 42 | */
|
42 | 43 | private $giftMessageHelper;
|
43 | 44 |
|
| 45 | + /** |
| 46 | + * @var MessageInterfaceFactory |
| 47 | + */ |
| 48 | + private $giftMessageFactory; |
| 49 | + |
44 | 50 | /**
|
45 | 51 | * @param CartItemRepositoryInterface $cartItemRepository
|
46 | 52 | * @param UpdateCartItem $updateCartItem
|
47 | 53 | * @param ItemRepositoryInterface $itemRepository
|
48 | 54 | * @param GiftMessageHelper $giftMessageHelper
|
| 55 | + * @param MessageInterfaceFactory $giftMessageFactory |
49 | 56 | */
|
50 | 57 | public function __construct(
|
51 | 58 | CartItemRepositoryInterface $cartItemRepository,
|
52 | 59 | UpdateCartItem $updateCartItem,
|
53 | 60 | ItemRepositoryInterface $itemRepository,
|
54 |
| - GiftMessageHelper $giftMessageHelper |
| 61 | + GiftMessageHelper $giftMessageHelper, |
| 62 | + MessageInterfaceFactory $giftMessageFactory |
55 | 63 | ) {
|
56 | 64 | $this->cartItemRepository = $cartItemRepository;
|
57 | 65 | $this->updateCartItem = $updateCartItem;
|
58 | 66 | $this->itemRepository = $itemRepository;
|
59 | 67 | $this->giftMessageHelper = $giftMessageHelper;
|
| 68 | + $this->giftMessageFactory = $giftMessageFactory; |
60 | 69 | }
|
61 | 70 |
|
62 | 71 | /**
|
@@ -110,6 +119,9 @@ public function processCartItems(Quote $cart, array $items): void
|
110 | 119 | $giftItemMessage = $this->itemRepository->get($cart->getEntityId(), $itemId);
|
111 | 120 |
|
112 | 121 | if (empty($giftItemMessage)) {
|
| 122 | + /** @var MessageInterface $giftMessage */ |
| 123 | + $giftMessage = $this->giftMessageFactory->create(); |
| 124 | + $this->updateGiftMessageForItem($cart, $giftMessage, $item, $itemId); |
113 | 125 | continue;
|
114 | 126 | }
|
115 | 127 | } catch (LocalizedException $exception) {
|
|
0 commit comments