|
| 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\Quote\Model\Product\Plugin; |
| 9 | + |
| 10 | +use Magento\Catalog\Model\ProductRepository; |
| 11 | +use Magento\Framework\DB\Adapter\AdapterInterface; |
| 12 | +use Magento\TestFramework\Helper\Bootstrap; |
| 13 | +use Magento\TestFramework\Quote\Model\GetQuoteByReservedOrderId; |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | + |
| 16 | +/** |
| 17 | + * Tests for update quote items plugin |
| 18 | + * |
| 19 | + * @magentoAppArea adminhtml |
| 20 | + */ |
| 21 | +class UpdateQuoteItemsTest extends TestCase |
| 22 | +{ |
| 23 | + /** |
| 24 | + * @var GetQuoteByReservedOrderId |
| 25 | + */ |
| 26 | + private $getQuoteByReservedOrderId; |
| 27 | + |
| 28 | + /** |
| 29 | + * @var ProductRepository |
| 30 | + */ |
| 31 | + private $productRepository; |
| 32 | + |
| 33 | + /** |
| 34 | + * @inheritdoc |
| 35 | + */ |
| 36 | + protected function setUp(): void |
| 37 | + { |
| 38 | + parent::setUp(); |
| 39 | + |
| 40 | + $objectManager = Bootstrap::getObjectManager(); |
| 41 | + $this->getQuoteByReservedOrderId = $objectManager->get(GetQuoteByReservedOrderId::class); |
| 42 | + $this->productRepository = $objectManager->get(ProductRepository::class); |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * Test to mark the quote as need to recollect and doesn't update the field "updated_at" after change product price |
| 47 | + * |
| 48 | + * @magentoDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php |
| 49 | + * @return void |
| 50 | + */ |
| 51 | + public function testMarkQuoteRecollectAfterChangeProductPrice(): void |
| 52 | + { |
| 53 | + $quote = $this->getQuoteByReservedOrderId->execute('test_order_with_simple_product_without_address'); |
| 54 | + $this->assertNotNull($quote); |
| 55 | + $this->assertFalse((bool)$quote->getTriggerRecollect()); |
| 56 | + $this->assertNotEmpty($quote->getItems()); |
| 57 | + $quoteItem = current($quote->getItems()); |
| 58 | + $product = $quoteItem->getProduct(); |
| 59 | + |
| 60 | + $product->setPrice((float)$product->getPrice() + 10); |
| 61 | + $this->productRepository->save($product); |
| 62 | + |
| 63 | + /** @var AdapterInterface $connection */ |
| 64 | + $connection = $quote->getResource()->getConnection(); |
| 65 | + $select = $connection->select() |
| 66 | + ->from( |
| 67 | + $connection->getTableName('quote'), |
| 68 | + ['updated_at', 'trigger_recollect'] |
| 69 | + )->where( |
| 70 | + "reserved_order_id = 'test_order_with_simple_product_without_address'" |
| 71 | + ); |
| 72 | + |
| 73 | + $quoteRow = $connection->fetchRow($select); |
| 74 | + $this->assertNotEmpty($quoteRow); |
| 75 | + $this->assertTrue((bool)$quoteRow['trigger_recollect']); |
| 76 | + $this->assertEquals($quote->getUpdatedAt(), $quoteRow['updated_at']); |
| 77 | + } |
| 78 | +} |
0 commit comments