Skip to content

Commit

Permalink
Merge remote-tracking branch 'local/ACP2E-2204' into PR_06_SEP_2023
Browse files Browse the repository at this point in the history
  • Loading branch information
o-dubovyk committed Oct 13, 2023
2 parents ac6941c + c721c47 commit 16922f5
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -311,15 +311,14 @@ private function reindexByBatchWithDimensions(
if (!empty($entityIds)) {
$this->dimensionTableMaintainer->createMainTmpTable($dimensions);
$temporaryTable = $this->dimensionTableMaintainer->getMainTmpTable($dimensions);
$this->_emptyTable($temporaryTable);

$priceIndexer->executeByDimensions($dimensions, \SplFixedArray::fromArray($entityIds, false));

// Sync data from temp table to index table
$this->_insertFromTable(
$temporaryTable,
$this->dimensionTableMaintainer->getMainReplicaTable($dimensions)
);
$this->_defaultIndexerResource->getConnection()->dropTable($temporaryTable);
}
}

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

if ($priceIndexer->getIsComposite()) {
$this->_copyRelationIndexData($entityIds);
Expand Down Expand Up @@ -489,6 +487,7 @@ private function moveDataFromReplicaTableToReplicaTables(array $dimensions): voi
* Retrieves the index table that should be used
*
* @deprecated 102.0.6
* @see only used in another deprecated method: _copyRelationIndexData
*/
protected function getIndexTargetTable(): string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ public function modifyPrice(IndexTableStructure $priceTable, array $entityIds =
$query = $select->crossUpdateFromSelect(['i' => $finalPriceTable]);
$connection->query($query);

$connection->delete($coaTable);
$connection->delete($copTable);
$connection->dropTemporaryTable($coaTable);
$connection->dropTemporaryTable($copTable);
}

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

namespace Magento\Catalog\Test\Unit\Model\Indexer\Product\Price;

use Magento\Catalog\Helper\Data;
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\CustomOptionPriceModifier;
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\IndexTableStructure;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\DB\Adapter\AdapterInterface;
use Magento\Framework\DB\Select;
use Magento\Framework\DB\Sql\ColumnValueExpressionFactory;
use Magento\Framework\EntityManager\EntityMetadataInterface;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Framework\Indexer\Table\StrategyInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class CustomOptionPriceModifierTest extends TestCase
{
/**
* @var ResourceConnection|MockObject
*/
private ResourceConnection $resource;

/**
* @var MetadataPool|MockObject
*/
private MetadataPool $metadataPool;

/**
* @var ColumnValueExpressionFactory|MockObject
*/
private ColumnValueExpressionFactory $columnValueExpressionFactory;

/**
* @var Data|MockObject
*/
private Data $dataHelper;

/**
* @var StrategyInterface|MockObject
*/
private StrategyInterface $tableStrategy;

/**
* @var CustomOptionPriceModifier
*/
private CustomOptionPriceModifier $priceModifier;

/**
* @return void
*/
protected function setUp(): void
{
$this->resource = $this->createMock(ResourceConnection::class);
$this->metadataPool = $this->createMock(MetadataPool::class);
$this->columnValueExpressionFactory = $this->createMock(ColumnValueExpressionFactory::class);
$this->dataHelper = $this->createMock(Data::class);
$this->tableStrategy = $this->createMock(StrategyInterface::class);
$this->priceModifier = new CustomOptionPriceModifier(
$this->resource,
$this->metadataPool,
$this->columnValueExpressionFactory,
$this->dataHelper,
$this->tableStrategy
);

parent::setUp();
}

/**
* @return void
* @throws \Exception
*/
public function testModifyPrice(): void
{
$priceTable = $this->createMock(IndexTableStructure::class);
$priceTable->expects($this->exactly(2))->method('getTableName')->willReturn('temporary_table_name');

$select = $this->createMock(Select::class);
$select->expects($this->any())->method('from')->willReturn($select);
$select->expects($this->any())->method('join')->willReturn($select);
$select->expects($this->any())->method('group')->willReturn($select);
$select->expects($this->any())->method('columns')->willReturn($select);

$connection = $this->createMock(AdapterInterface::class);
$connection->expects($this->exactly(2))->method('delete');
$connection->expects($this->any())->method('select')->willReturn($select);
$connection->expects($this->any())->method('fetchRow')->willReturn(['exists']);
$connection->expects($this->exactly(4))->method('query');
$connection->expects($this->exactly(2))->method('dropTemporaryTable');
$this->resource->expects($this->any())->method('getConnection')->willReturn($connection);
$this->resource->expects($this->any())->method('getTableName')->willReturn('table');
$this->tableStrategy->expects($this->any())
->method('getTableName')
->willReturn('table_name');

$metadata = $this->createMock(EntityMetadataInterface::class);
$this->metadataPool->expects($this->any())->method('getMetadata')->willReturn($metadata);
$this->dataHelper->expects($this->once())->method('isPriceGlobal')->willReturn(true);

$this->priceModifier->modifyPrice($priceTable);
}
}

0 comments on commit 16922f5

Please sign in to comment.