Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/MC-35008' into 2.4-develop-pr32
Browse files Browse the repository at this point in the history
  • Loading branch information
serhii-balko committed Jul 1, 2020
2 parents 01008af + ce8752e commit 3a0ac16
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 16 deletions.
39 changes: 23 additions & 16 deletions app/code/Magento/Quote/Model/ResourceModel/Quote.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ public function subtractProductFromQuotes($product)
'items_qty' => new \Zend_Db_Expr(
$connection->quoteIdentifier('q.items_qty') . ' - ' . $connection->quoteIdentifier('qi.qty')
),
'items_count' => new \Zend_Db_Expr($ifSql)
'items_count' => new \Zend_Db_Expr($ifSql),
'updated_at' => 'q.updated_at',
]
)->join(
['qi' => $this->getTable('quote_item')],
Expand Down Expand Up @@ -277,21 +278,27 @@ public function markQuotesRecollect($productIds)
{
$tableQuote = $this->getTable('quote');
$tableItem = $this->getTable('quote_item');
$subSelect = $this->getConnection()->select()->from(
$tableItem,
['entity_id' => 'quote_id']
)->where(
'product_id IN ( ? )',
$productIds
)->group(
'quote_id'
);

$select = $this->getConnection()->select()->join(
['t2' => $subSelect],
't1.entity_id = t2.entity_id',
['trigger_recollect' => new \Zend_Db_Expr('1')]
);
$subSelect = $this->getConnection()
->select()
->from(
$tableItem,
['entity_id' => 'quote_id']
)->where(
'product_id IN ( ? )',
$productIds
)->group(
'quote_id'
);
$select = $this->getConnection()
->select()
->join(
['t2' => $subSelect],
't1.entity_id = t2.entity_id',
[
'trigger_recollect' => new \Zend_Db_Expr('1'),
'updated_at' => 't1.updated_at',
]
);
$updateQuery = $select->crossUpdateFromSelect(['t1' => $tableQuote]);
$this->getConnection()->query($updateQuery);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Quote\Model\Product\Plugin;

use Magento\Catalog\Model\ProductRepository;
use Magento\Framework\DB\Adapter\AdapterInterface;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Quote\Model\GetQuoteByReservedOrderId;
use PHPUnit\Framework\TestCase;

/**
* Tests for update quote items plugin
*
* @magentoAppArea adminhtml
*/
class UpdateQuoteItemsTest extends TestCase
{
/**
* @var GetQuoteByReservedOrderId
*/
private $getQuoteByReservedOrderId;

/**
* @var ProductRepository
*/
private $productRepository;

/**
* @inheritdoc
*/
protected function setUp(): void
{
parent::setUp();

$objectManager = Bootstrap::getObjectManager();
$this->getQuoteByReservedOrderId = $objectManager->get(GetQuoteByReservedOrderId::class);
$this->productRepository = $objectManager->get(ProductRepository::class);
}

/**
* Test to mark the quote as need to recollect and doesn't update the field "updated_at" after change product price
*
* @magentoDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
* @return void
*/
public function testMarkQuoteRecollectAfterChangeProductPrice(): void
{
$quote = $this->getQuoteByReservedOrderId->execute('test_order_with_simple_product_without_address');
$this->assertNotNull($quote);
$this->assertFalse((bool)$quote->getTriggerRecollect());
$this->assertNotEmpty($quote->getItems());
$quoteItem = current($quote->getItems());
$product = $quoteItem->getProduct();

$product->setPrice((float)$product->getPrice() + 10);
$this->productRepository->save($product);

/** @var AdapterInterface $connection */
$connection = $quote->getResource()->getConnection();
$select = $connection->select()
->from(
$connection->getTableName('quote'),
['updated_at', 'trigger_recollect']
)->where(
"reserved_order_id = 'test_order_with_simple_product_without_address'"
);

$quoteRow = $connection->fetchRow($select);
$this->assertNotEmpty($quoteRow);
$this->assertTrue((bool)$quoteRow['trigger_recollect']);
$this->assertEquals($quote->getUpdatedAt(), $quoteRow['updated_at']);
}
}

0 comments on commit 3a0ac16

Please sign in to comment.