Skip to content

Commit 3585033

Browse files
committed
ACP2E-330: When partial indexer is executed catalog rule prices get removed
1 parent 2511c79 commit 3585033

File tree

4 files changed

+123
-161
lines changed

4 files changed

+123
-161
lines changed

dev/tests/integration/testsuite/Magento/CatalogRuleConfigurable/Model/Indexer/Product/ProductRuleIndexerTest.php

Lines changed: 76 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,51 +49,109 @@ protected function setUp(): void
4949
}
5050

5151
/**
52+
* @dataProvider productsDataProvider
53+
* @param string $reindexSku
54+
* @param array $expectedPrices
5255
* @return void
56+
* @throws \Magento\Framework\Exception\NoSuchEntityException
5357
*/
54-
public function testExecute(): void
58+
public function testExecute(string $reindexSku, array $expectedPrices): void
5559
{
56-
$product = $this->productRepository->get('configurable');
60+
$product = $this->productRepository->get($reindexSku);
5761
$this->productRuleIndexer->execute([$product->getId()]);
5862

59-
$product = $this->productRepository->get('simple_10');
60-
$price = $this->getCatalogRulePrice($product);
61-
$this->assertEquals(5, $price);
63+
$this->assertEquals($expectedPrices, $this->getCatalogRulePrices(array_keys($expectedPrices)));
6264
}
6365

6466
/**
67+
* @dataProvider productsDataProvider
68+
* @param string $reindexSku
69+
* @param array $expectedPrices
6570
* @return void
71+
* @throws \Magento\Framework\Exception\LocalizedException
72+
* @throws \Magento\Framework\Exception\NoSuchEntityException
6673
*/
67-
public function testExecuteRow(): void
74+
public function testExecuteRow(string $reindexSku, array $expectedPrices): void
6875
{
69-
$product = $this->productRepository->get('configurable');
76+
$product = $this->productRepository->get($reindexSku);
7077
$this->productRuleIndexer->executeRow($product->getId());
7178

72-
$product = $this->productRepository->get('simple_10');
73-
$price = $this->getCatalogRulePrice($product);
74-
$this->assertEquals(5, $price);
79+
$this->assertEquals($expectedPrices, $this->getCatalogRulePrices(array_keys($expectedPrices)));
7580
}
7681

7782
/**
83+
* @dataProvider productsDataProvider
84+
* @param string $reindexSku
85+
* @param array $expectedPrices
7886
* @return void
87+
* @throws \Magento\Framework\Exception\LocalizedException
88+
* @throws \Magento\Framework\Exception\NoSuchEntityException
7989
*/
80-
public function testExecuteList(): void
90+
public function testExecuteList(string $reindexSku, array $expectedPrices): void
8191
{
82-
$product = $this->productRepository->get('configurable');
92+
$product = $this->productRepository->get($reindexSku);
8393
$this->productRuleIndexer->executeList([$product->getId()]);
8494

85-
$product = $this->productRepository->get('simple_10');
86-
$price = $this->getCatalogRulePrice($product);
87-
$this->assertEquals(5, $price);
95+
$this->assertEquals($expectedPrices, $this->getCatalogRulePrices(array_keys($expectedPrices)));
8896
}
8997

98+
/**
99+
* @return void
100+
*/
90101
public function testExecuteFull(): void
91102
{
92103
$this->productRuleIndexer->executeFull();
93104

94-
$product = $this->productRepository->get('simple_10');
95-
$price = $this->getCatalogRulePrice($product);
96-
$this->assertEquals(5, $price);
105+
$expectedPrices = [
106+
'simple_10' => 5,
107+
'simple_20' => 10,
108+
];
109+
$this->assertEquals($expectedPrices, $this->getCatalogRulePrices(array_keys($expectedPrices)));
110+
}
111+
112+
/**
113+
* @return array
114+
*/
115+
public function productsDataProvider(): array
116+
{
117+
return [
118+
[
119+
'configurable',
120+
[
121+
'simple_10' => 5,
122+
'simple_20' => 10,
123+
]
124+
],
125+
[
126+
'simple_10',
127+
[
128+
'simple_10' => 5,
129+
'simple_20' => 10,
130+
]
131+
],
132+
[
133+
'simple_20',
134+
[
135+
'simple_10' => 5,
136+
'simple_20' => 10,
137+
]
138+
],
139+
];
140+
}
141+
142+
/**
143+
* @param array $skus
144+
* @return array
145+
* @throws \Magento\Framework\Exception\NoSuchEntityException
146+
*/
147+
private function getCatalogRulePrices(array $skus): array
148+
{
149+
$actualPrices = [];
150+
foreach ($skus as $sku) {
151+
$product = $this->productRepository->get($sku);
152+
$actualPrices[$sku] = $this->getCatalogRulePrice($product);
153+
}
154+
return $actualPrices;
97155
}
98156

99157
/**

dev/tests/integration/testsuite/Magento/CatalogRuleConfigurable/_files/configurable_product_with_categories_rule.php

Lines changed: 0 additions & 72 deletions
This file was deleted.

dev/tests/integration/testsuite/Magento/CatalogRuleConfigurable/_files/configurable_product_with_categories_rule_rollback.php

Lines changed: 0 additions & 29 deletions
This file was deleted.

dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/configurable_attribute.php

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,54 +12,59 @@
1212
use Magento\Eav\Setup\EavSetup;
1313
use Magento\Framework\Exception\NoSuchEntityException;
1414
use Magento\TestFramework\Helper\Bootstrap;
15+
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
1516

1617
$objectManager = Bootstrap::getObjectManager();
1718

1819
/** @var ProductAttributeRepositoryInterface $attributeRepository */
1920
$attributeRepository = $objectManager->get(ProductAttributeRepositoryInterface::class);
20-
$attributeCode = 'test_configurable';
21+
/** @var ProductAttributeInterfaceFactory $attributeFactory */
22+
$attributeFactory = $objectManager->get(ProductAttributeInterfaceFactory::class);
23+
2124
try {
22-
$attributeRepository->get($attributeCode);
25+
$attributeRepository->get('test_configurable');
26+
Resolver::getInstance()
27+
->requireDataFixture('Magento/ConfigurableProduct/_files/configurable_attribute_rollback.php');
2328
} catch (NoSuchEntityException $e) {
24-
/** @var $installer EavSetup */
25-
$installer = $objectManager->get(EavSetup::class);
26-
$attributeSetId = $installer->getAttributeSetId(Product::ENTITY, 'Default');
27-
$groupId = $installer->getDefaultAttributeGroupId(Product::ENTITY, $attributeSetId);
29+
}
2830

29-
/** @var ProductAttributeInterfaceFactory $attributeFactory */
30-
$attributeFactory = $objectManager->get(ProductAttributeInterfaceFactory::class);
31-
/** @var ProductAttributeInterface $attributeModel */
32-
$attributeModel = $attributeFactory->create();
33-
$attributeModel->setData(
34-
[
35-
'attribute_code' => $attributeCode,
36-
'entity_type_id' => $installer->getEntityTypeId(Product::ENTITY),
37-
'is_global' => 1,
38-
'is_user_defined' => 1,
39-
'frontend_input' => 'select',
40-
'is_unique' => 0,
41-
'is_required' => 0,
42-
'is_searchable' => 0,
43-
'is_visible_in_advanced_search' => 0,
44-
'is_comparable' => 0,
45-
'is_filterable' => 0,
46-
'is_filterable_in_search' => 0,
47-
'is_used_for_promo_rules' => 0,
48-
'is_html_allowed_on_front' => 1,
49-
'is_visible_on_front' => 0,
50-
'used_in_product_listing' => 0,
51-
'used_for_sort_by' => 0,
52-
'frontend_label' => ['Test Configurable'],
53-
'backend_type' => 'int',
54-
'option' => [
55-
'value' => ['option_0' => ['Option 1'], 'option_1' => ['Option 2']],
56-
'order' => ['option_0' => 1, 'option_1' => 2],
57-
],
58-
]
59-
);
60-
$attribute = $attributeRepository->save($attributeModel);
31+
$eavConfig = $objectManager->get(Config::class);
6132

62-
$installer->addAttributeToGroup(Product::ENTITY, $attributeSetId, $groupId, $attribute->getId());
63-
$eavConfig = $objectManager->get(Config::class);
64-
$eavConfig->clear();
65-
}
33+
/** @var $installer EavSetup */
34+
$installer = $objectManager->get(EavSetup::class);
35+
$attributeSetId = $installer->getAttributeSetId(Product::ENTITY, 'Default');
36+
$groupId = $installer->getDefaultAttributeGroupId(Product::ENTITY, $attributeSetId);
37+
/** @var ProductAttributeInterface $attributeModel */
38+
$attributeModel = $attributeFactory->create();
39+
$attributeModel->setData(
40+
[
41+
'attribute_code' => 'test_configurable',
42+
'entity_type_id' => $installer->getEntityTypeId(Product::ENTITY),
43+
'is_global' => 1,
44+
'is_user_defined' => 1,
45+
'frontend_input' => 'select',
46+
'is_unique' => 0,
47+
'is_required' => 0,
48+
'is_searchable' => 0,
49+
'is_visible_in_advanced_search' => 0,
50+
'is_comparable' => 0,
51+
'is_filterable' => 0,
52+
'is_filterable_in_search' => 0,
53+
'is_used_for_promo_rules' => 0,
54+
'is_html_allowed_on_front' => 1,
55+
'is_visible_on_front' => 0,
56+
'used_in_product_listing' => 0,
57+
'used_for_sort_by' => 0,
58+
'frontend_label' => ['Test Configurable'],
59+
'backend_type' => 'int',
60+
'option' => [
61+
'value' => ['option_0' => ['Option 1'], 'option_1' => ['Option 2']],
62+
'order' => ['option_0' => 1, 'option_1' => 2],
63+
],
64+
]
65+
);
66+
67+
$attribute = $attributeRepository->save($attributeModel);
68+
69+
$installer->addAttributeToGroup(Product::ENTITY, $attributeSetId, $groupId, $attribute->getId());
70+
$eavConfig->clear();

0 commit comments

Comments
 (0)