Skip to content

Commit 3a0ac16

Browse files
committed
Merge remote-tracking branch 'origin/MC-35008' into 2.4-develop-pr32
2 parents 01008af + ce8752e commit 3a0ac16

File tree

2 files changed

+101
-16
lines changed

2 files changed

+101
-16
lines changed

app/code/Magento/Quote/Model/ResourceModel/Quote.php

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ public function subtractProductFromQuotes($product)
230230
'items_qty' => new \Zend_Db_Expr(
231231
$connection->quoteIdentifier('q.items_qty') . ' - ' . $connection->quoteIdentifier('qi.qty')
232232
),
233-
'items_count' => new \Zend_Db_Expr($ifSql)
233+
'items_count' => new \Zend_Db_Expr($ifSql),
234+
'updated_at' => 'q.updated_at',
234235
]
235236
)->join(
236237
['qi' => $this->getTable('quote_item')],
@@ -277,21 +278,27 @@ public function markQuotesRecollect($productIds)
277278
{
278279
$tableQuote = $this->getTable('quote');
279280
$tableItem = $this->getTable('quote_item');
280-
$subSelect = $this->getConnection()->select()->from(
281-
$tableItem,
282-
['entity_id' => 'quote_id']
283-
)->where(
284-
'product_id IN ( ? )',
285-
$productIds
286-
)->group(
287-
'quote_id'
288-
);
289-
290-
$select = $this->getConnection()->select()->join(
291-
['t2' => $subSelect],
292-
't1.entity_id = t2.entity_id',
293-
['trigger_recollect' => new \Zend_Db_Expr('1')]
294-
);
281+
$subSelect = $this->getConnection()
282+
->select()
283+
->from(
284+
$tableItem,
285+
['entity_id' => 'quote_id']
286+
)->where(
287+
'product_id IN ( ? )',
288+
$productIds
289+
)->group(
290+
'quote_id'
291+
);
292+
$select = $this->getConnection()
293+
->select()
294+
->join(
295+
['t2' => $subSelect],
296+
't1.entity_id = t2.entity_id',
297+
[
298+
'trigger_recollect' => new \Zend_Db_Expr('1'),
299+
'updated_at' => 't1.updated_at',
300+
]
301+
);
295302
$updateQuery = $select->crossUpdateFromSelect(['t1' => $tableQuote]);
296303
$this->getConnection()->query($updateQuery);
297304

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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

Comments
 (0)