Skip to content

Commit c8fb910

Browse files
committed
ACP2E-1569: Elasticsearch Indexer document version changes version when new/existing products are imported
1 parent 03ebf08 commit c8fb910

File tree

2 files changed

+84
-36
lines changed

2 files changed

+84
-36
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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\CatalogRule\Model\Indexer;
9+
10+
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
12+
use Magento\CatalogRule\Model\Indexer\Rule\RuleProductProcessor;
13+
use Magento\Framework\DataObject;
14+
use Magento\TestFramework\Fixture\AppIsolation;
15+
use Magento\TestFramework\Fixture\DataFixture;
16+
use Magento\TestFramework\Fixture\DbIsolation;
17+
use Magento\TestFramework\Helper\Bootstrap;
18+
19+
class IndexerBuilderInScheduledModeTest extends \PHPUnit\Framework\TestCase
20+
{
21+
/**
22+
* @var RuleProductProcessor
23+
*/
24+
private $ruleProductProcessor;
25+
26+
/**
27+
* @var CollectionFactory
28+
*/
29+
private $productCollectionFactory;
30+
31+
/**
32+
* @var ProductRepositoryInterface
33+
*/
34+
private $productRepository;
35+
36+
protected function setUp(): void
37+
{
38+
$this->productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
39+
$this->ruleProductProcessor = Bootstrap::getObjectManager()->get(RuleProductProcessor::class);
40+
$this->productCollectionFactory = Bootstrap::getObjectManager()->get(CollectionFactory::class);
41+
}
42+
43+
#[
44+
DbIsolation(false),
45+
AppIsolation(true),
46+
DataFixture('Magento/Catalog/_files/product_with_options.php'),
47+
DataFixture('Magento/CatalogRule/_files/catalog_rule_10_off_not_logged.php'),
48+
DataFixture('Magento/CatalogRule/_files/set_indexer_to_scheduled_mode.php'),
49+
]
50+
public function testReindexOfDependentIndexer(): void
51+
{
52+
$product = $this->productRepository->get('simple');
53+
$productId = (int)$product->getId();
54+
55+
$product = $this->getProductFromCollection($productId);
56+
$this->assertEquals(9, $product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue());
57+
58+
$product->setPrice(100);
59+
$this->productRepository->save($product);
60+
61+
$product = $this->getProductFromCollection($productId);
62+
$this->assertEquals(9, $product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue());
63+
64+
$this->ruleProductProcessor->getIndexer()->reindexList([$productId]);
65+
66+
$product = $this->getProductFromCollection($productId);
67+
$this->assertEquals(90, $product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue());
68+
}
69+
70+
/**
71+
* Get the product from the product collection
72+
*
73+
* @param int $productId
74+
* @return DataObject
75+
*/
76+
private function getProductFromCollection(int $productId) : DataObject
77+
{
78+
$productCollection = $this->productCollectionFactory->create();
79+
$productCollection->addIdFilter($productId);
80+
$productCollection->addPriceData();
81+
$productCollection->load();
82+
return $productCollection->getFirstItem();
83+
}
84+
}

dev/tests/integration/testsuite/Magento/CatalogRule/Model/Indexer/IndexerBuilderTest.php

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
1111
use Magento\CatalogRule\Model\Indexer\Rule\RuleProductProcessor;
1212
use Magento\Framework\App\ResourceConnection;
13-
use Magento\Framework\App\Area;
1413
use Magento\Store\Model\StoreManagerInterface;
1514
use Magento\TestFramework\Fixture\AppIsolation;
1615
use Magento\TestFramework\Fixture\DataFixture;
1716
use Magento\TestFramework\Fixture\DbIsolation;
18-
use Magento\TestFramework\Fixture\AppArea;
1917
use Magento\TestFramework\Helper\Bootstrap;
2018

2119
#[
@@ -287,38 +285,4 @@ protected function prepareProducts()
287285
->setData('test_attribute', 'NO_test_attribute_value')
288286
->save();
289287
}
290-
291-
#[
292-
AppArea(Area::AREA_FRONTEND),
293-
DataFixture('Magento/CatalogRule/_files/simple_product_with_catalog_rule_50_percent_off.php'),
294-
DataFixture('Magento/CatalogRule/_files/set_indexer_to_scheduled_mode.php'),
295-
]
296-
public function testReindexOfDependentIndexer(): void
297-
{
298-
$productId = $this->productRepository->get('simple')->getId();
299-
300-
$productCollection = $this->productCollectionFactory->create();
301-
$productCollection->addIdFilter($productId);
302-
//$productCollection->addPriceData();
303-
$productCollection->load();
304-
echo (string)$productCollection->getSelect();
305-
$product = $productCollection->getFirstItem();
306-
echo "\n\n" . $product->getId() . '=';
307-
//$product = $productCollection->getItemByColumnValue('sku', 'simple');
308-
//$product = $this->productRepository->get('simple');
309-
//print_r($product->getPriceInfo());
310-
echo $product->getFinalPrice();
311-
echo ' * ';
312-
$product->setPrice(500);
313-
$this->productRepository->save($product);
314-
$product = $this->productRepository->get('simple');
315-
echo $product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue();
316-
$product->setPrice(50);
317-
$this->productRepository->save($product);
318-
319-
$this->indexProductProcessor->getIndexer()->setScheduled(false);
320-
$this->ruleProductProcessor->getIndexer()->setScheduled(false);
321-
322-
$this->indexerBuilder->reindexFull();
323-
}
324288
}

0 commit comments

Comments
 (0)