Skip to content

Commit 16922f5

Browse files
committed
Merge remote-tracking branch 'local/ACP2E-2204' into PR_06_SEP_2023
2 parents ac6941c + c721c47 commit 16922f5

File tree

3 files changed

+113
-5
lines changed

3 files changed

+113
-5
lines changed

app/code/Magento/Catalog/Model/Indexer/Product/Price/Action/Full.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,15 +311,14 @@ private function reindexByBatchWithDimensions(
311311
if (!empty($entityIds)) {
312312
$this->dimensionTableMaintainer->createMainTmpTable($dimensions);
313313
$temporaryTable = $this->dimensionTableMaintainer->getMainTmpTable($dimensions);
314-
$this->_emptyTable($temporaryTable);
315-
316314
$priceIndexer->executeByDimensions($dimensions, \SplFixedArray::fromArray($entityIds, false));
317315

318316
// Sync data from temp table to index table
319317
$this->_insertFromTable(
320318
$temporaryTable,
321319
$this->dimensionTableMaintainer->getMainReplicaTable($dimensions)
322320
);
321+
$this->_defaultIndexerResource->getConnection()->dropTable($temporaryTable);
323322
}
324323
}
325324

@@ -354,7 +353,6 @@ private function reindexBatch(PriceInterface $priceIndexer, Select $batch): void
354353
if (!empty($entityIds)) {
355354
// Temporary table will created if not exists
356355
$idxTableName = $this->_defaultIndexerResource->getIdxTable();
357-
$this->_emptyTable($idxTableName);
358356

359357
if ($priceIndexer->getIsComposite()) {
360358
$this->_copyRelationIndexData($entityIds);
@@ -489,6 +487,7 @@ private function moveDataFromReplicaTableToReplicaTables(array $dimensions): voi
489487
* Retrieves the index table that should be used
490488
*
491489
* @deprecated 102.0.6
490+
* @see only used in another deprecated method: _copyRelationIndexData
492491
*/
493492
protected function getIndexTargetTable(): string
494493
{

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Price/CustomOptionPriceModifier.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ public function modifyPrice(IndexTableStructure $priceTable, array $entityIds =
122122
$query = $select->crossUpdateFromSelect(['i' => $finalPriceTable]);
123123
$connection->query($query);
124124

125-
$connection->delete($coaTable);
126-
$connection->delete($copTable);
125+
$connection->dropTemporaryTable($coaTable);
126+
$connection->dropTemporaryTable($copTable);
127127
}
128128

129129
/**
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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\Catalog\Test\Unit\Model\Indexer\Product\Price;
9+
10+
use Magento\Catalog\Helper\Data;
11+
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\CustomOptionPriceModifier;
12+
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\IndexTableStructure;
13+
use Magento\Framework\App\ResourceConnection;
14+
use Magento\Framework\DB\Adapter\AdapterInterface;
15+
use Magento\Framework\DB\Select;
16+
use Magento\Framework\DB\Sql\ColumnValueExpressionFactory;
17+
use Magento\Framework\EntityManager\EntityMetadataInterface;
18+
use Magento\Framework\EntityManager\MetadataPool;
19+
use Magento\Framework\Indexer\Table\StrategyInterface;
20+
use PHPUnit\Framework\MockObject\MockObject;
21+
use PHPUnit\Framework\TestCase;
22+
23+
class CustomOptionPriceModifierTest extends TestCase
24+
{
25+
/**
26+
* @var ResourceConnection|MockObject
27+
*/
28+
private ResourceConnection $resource;
29+
30+
/**
31+
* @var MetadataPool|MockObject
32+
*/
33+
private MetadataPool $metadataPool;
34+
35+
/**
36+
* @var ColumnValueExpressionFactory|MockObject
37+
*/
38+
private ColumnValueExpressionFactory $columnValueExpressionFactory;
39+
40+
/**
41+
* @var Data|MockObject
42+
*/
43+
private Data $dataHelper;
44+
45+
/**
46+
* @var StrategyInterface|MockObject
47+
*/
48+
private StrategyInterface $tableStrategy;
49+
50+
/**
51+
* @var CustomOptionPriceModifier
52+
*/
53+
private CustomOptionPriceModifier $priceModifier;
54+
55+
/**
56+
* @return void
57+
*/
58+
protected function setUp(): void
59+
{
60+
$this->resource = $this->createMock(ResourceConnection::class);
61+
$this->metadataPool = $this->createMock(MetadataPool::class);
62+
$this->columnValueExpressionFactory = $this->createMock(ColumnValueExpressionFactory::class);
63+
$this->dataHelper = $this->createMock(Data::class);
64+
$this->tableStrategy = $this->createMock(StrategyInterface::class);
65+
$this->priceModifier = new CustomOptionPriceModifier(
66+
$this->resource,
67+
$this->metadataPool,
68+
$this->columnValueExpressionFactory,
69+
$this->dataHelper,
70+
$this->tableStrategy
71+
);
72+
73+
parent::setUp();
74+
}
75+
76+
/**
77+
* @return void
78+
* @throws \Exception
79+
*/
80+
public function testModifyPrice(): void
81+
{
82+
$priceTable = $this->createMock(IndexTableStructure::class);
83+
$priceTable->expects($this->exactly(2))->method('getTableName')->willReturn('temporary_table_name');
84+
85+
$select = $this->createMock(Select::class);
86+
$select->expects($this->any())->method('from')->willReturn($select);
87+
$select->expects($this->any())->method('join')->willReturn($select);
88+
$select->expects($this->any())->method('group')->willReturn($select);
89+
$select->expects($this->any())->method('columns')->willReturn($select);
90+
91+
$connection = $this->createMock(AdapterInterface::class);
92+
$connection->expects($this->exactly(2))->method('delete');
93+
$connection->expects($this->any())->method('select')->willReturn($select);
94+
$connection->expects($this->any())->method('fetchRow')->willReturn(['exists']);
95+
$connection->expects($this->exactly(4))->method('query');
96+
$connection->expects($this->exactly(2))->method('dropTemporaryTable');
97+
$this->resource->expects($this->any())->method('getConnection')->willReturn($connection);
98+
$this->resource->expects($this->any())->method('getTableName')->willReturn('table');
99+
$this->tableStrategy->expects($this->any())
100+
->method('getTableName')
101+
->willReturn('table_name');
102+
103+
$metadata = $this->createMock(EntityMetadataInterface::class);
104+
$this->metadataPool->expects($this->any())->method('getMetadata')->willReturn($metadata);
105+
$this->dataHelper->expects($this->once())->method('isPriceGlobal')->willReturn(true);
106+
107+
$this->priceModifier->modifyPrice($priceTable);
108+
}
109+
}

0 commit comments

Comments
 (0)