|
7 | 7 |
|
8 | 8 | namespace Magento\GraphQl\Quote\Guest;
|
9 | 9 |
|
10 |
| -use Magento\Quote\Model\QuoteFactory; |
| 10 | +use Exception; |
11 | 11 | use Magento\Catalog\Api\ProductRepositoryInterface;
|
| 12 | +use Magento\Quote\Model\QuoteFactory; |
12 | 13 | use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
|
13 | 14 | use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
|
14 | 15 | use Magento\TestFramework\Helper\Bootstrap;
|
@@ -273,6 +274,81 @@ private function getCartQuery(string $maskedQuoteId)
|
273 | 274 | }
|
274 | 275 | }
|
275 | 276 | }
|
| 277 | +QUERY; |
| 278 | + } |
| 279 | + |
| 280 | + /** |
| 281 | + * @magentoConfigFixture default_store sales/gift_options/allow_items 1 |
| 282 | + * @magentoApiDataFixture Magento/GiftMessage/_files/guest/quote_with_item_message.php |
| 283 | + * @throws Exception |
| 284 | + */ |
| 285 | + public function testUpdateGiftMessageCartForItem() |
| 286 | + { |
| 287 | + $query = $this->getUpdateGiftMessageQuery(); |
| 288 | + foreach ($this->graphQlMutation($query)['updateCartItems']['cart']['items'] as $item) { |
| 289 | + self::assertArrayHasKey('gift_message', $item); |
| 290 | + self::assertSame('Alex', $item['gift_message']['to']); |
| 291 | + self::assertSame('Mike', $item['gift_message']['from']); |
| 292 | + self::assertSame('Best regards.', $item['gift_message']['message']); |
| 293 | + } |
| 294 | + } |
| 295 | + |
| 296 | + /** |
| 297 | + * @magentoConfigFixture default_store sales/gift_options/allow_items 0 |
| 298 | + * @magentoApiDataFixture Magento/GiftMessage/_files/guest/quote_with_item_message.php |
| 299 | + * @throws Exception |
| 300 | + */ |
| 301 | + public function testUpdateGiftMessageCartForItemNotAllow() |
| 302 | + { |
| 303 | + $query = $this->getUpdateGiftMessageQuery(); |
| 304 | + foreach ($this->graphQlMutation($query)['updateCartItems']['cart']['items'] as $item) { |
| 305 | + self::assertNull($item['gift_message']); |
| 306 | + } |
| 307 | + } |
| 308 | + |
| 309 | + private function getUpdateGiftMessageQuery() |
| 310 | + { |
| 311 | + $quote = $this->quoteFactory->create(); |
| 312 | + $this->quoteResource->load($quote, 'test_guest_order_with_gift_message', 'reserved_order_id'); |
| 313 | + $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$quote->getId()); |
| 314 | + $itemId = (int)$quote->getItemByProduct($this->productRepository->get('simple'))->getId(); |
| 315 | + |
| 316 | + return <<<QUERY |
| 317 | +mutation { |
| 318 | + updateCartItems( |
| 319 | + input: { |
| 320 | + cart_id: "$maskedQuoteId", |
| 321 | + cart_items: [ |
| 322 | + { |
| 323 | + cart_item_id: $itemId |
| 324 | + quantity: 3 |
| 325 | + gift_message: { |
| 326 | + to: "Alex" |
| 327 | + from: "Mike" |
| 328 | + message: "Best regards." |
| 329 | + } |
| 330 | + } |
| 331 | + ] |
| 332 | + } |
| 333 | + ) { |
| 334 | + cart { |
| 335 | + items { |
| 336 | + id |
| 337 | + product { |
| 338 | + name |
| 339 | + } |
| 340 | + quantity |
| 341 | + ... on SimpleCartItem { |
| 342 | + gift_message { |
| 343 | + to |
| 344 | + from |
| 345 | + message |
| 346 | + } |
| 347 | + } |
| 348 | + } |
| 349 | + } |
| 350 | + } |
| 351 | +} |
276 | 352 | QUERY;
|
277 | 353 | }
|
278 | 354 | }
|
0 commit comments