Skip to content

Commit b65c2ad

Browse files
committed
BUG#AC-1705: Page Cache is not cleared for the parent product on the child product save - issue fixed
1 parent 44a86cb commit b65c2ad

File tree

3 files changed

+222
-6
lines changed

3 files changed

+222
-6
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ public function __construct(
6666
public function execute($ids)
6767
{
6868
$this->_productPriceIndexerRows->execute($ids);
69-
$this->cacheContext->registerEntities(ProductModel::CACHE_TAG, $ids);
7069
}
7170

7271
/**

app/code/Magento/Catalog/Model/Indexer/Product/Price/AbstractAction.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magento\Catalog\Model\Indexer\Product\Price;
88

9+
use Magento\Catalog\Model\Product;
910
use Magento\Catalog\Model\Product\Type;
1011
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\DefaultPrice;
1112
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\Factory;
@@ -20,6 +21,7 @@
2021
use Magento\Framework\Exception\InputException;
2122
use Magento\Framework\Exception\LocalizedException;
2223
use Magento\Framework\Exception\NoSuchEntityException;
24+
use Magento\Framework\Indexer\CacheContext;
2325
use Magento\Framework\Indexer\DimensionalIndexerInterface;
2426
use Magento\Framework\Search\Request\Dimension;
2527
use Magento\Framework\Stdlib\DateTime;
@@ -61,8 +63,6 @@ abstract class AbstractAction
6163
protected $_storeManager;
6264

6365
/**
64-
* Currency factory
65-
*
6666
* @var CurrencyFactory
6767
*/
6868
protected $_currencyFactory;
@@ -83,8 +83,6 @@ abstract class AbstractAction
8383
protected $_catalogProductType;
8484

8585
/**
86-
* Indexer price factory
87-
*
8886
* @var Factory
8987
*/
9088
protected $_indexerPriceFactory;
@@ -109,6 +107,11 @@ abstract class AbstractAction
109107
*/
110108
private $tableMaintainer;
111109

110+
/**
111+
* @var CacheContext
112+
*/
113+
private $cacheContext;
114+
112115
/**
113116
* @param ScopeConfigInterface $config
114117
* @param StoreManagerInterface $storeManager
@@ -121,6 +124,7 @@ abstract class AbstractAction
121124
* @param TierPrice|null $tierPriceIndexResource
122125
* @param DimensionCollectionFactory|null $dimensionCollectionFactory
123126
* @param TableMaintainer|null $tableMaintainer
127+
* @param CacheContext|null $cacheContext
124128
* @SuppressWarnings(PHPMD.NPathComplexity)
125129
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
126130
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
@@ -136,7 +140,8 @@ public function __construct(
136140
DefaultPrice $defaultIndexerResource,
137141
TierPrice $tierPriceIndexResource = null,
138142
DimensionCollectionFactory $dimensionCollectionFactory = null,
139-
TableMaintainer $tableMaintainer = null
143+
TableMaintainer $tableMaintainer = null,
144+
CacheContext $cacheContext = null
140145
) {
141146
$this->_config = $config;
142147
$this->_storeManager = $storeManager;
@@ -156,6 +161,7 @@ public function __construct(
156161
$this->tableMaintainer = $tableMaintainer ?? ObjectManager::getInstance()->get(
157162
TableMaintainer::class
158163
);
164+
$this->cacheContext = $cacheContext ?? ObjectManager::getInstance()->get(CacheContext::class);
159165
}
160166

161167
/**
@@ -391,6 +397,7 @@ protected function _reindexRows($changedIds = [])
391397

392398
if ($changedIds) {
393399
$this->deleteIndexData($changedIds);
400+
$this->cacheContext->registerEntities(Product::CACHE_TAG, $changedIds);
394401
}
395402

396403
$typeIndexers = $this->getTypeIndexers();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
<test name="AdminCheckConfigurableProductPriceWhenChildProductPriceUpdatedTest">
11+
<annotations>
12+
<stories value="Configurable Product"/>
13+
<title value="Check price of configurable product when one child product price is updated"/>
14+
<description value="Login as admin and check the configurable product price when one child product child product price is updated"/>
15+
<severity value="CRITICAL"/>
16+
<group value="product"/>
17+
</annotations>
18+
<before>
19+
<!-- Login as Admin -->
20+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginToAdminPanel"/>
21+
22+
<!-- Create Default Category -->
23+
<createData entity="_defaultCategory" stepKey="createCategory"/>
24+
25+
<!-- Create an attribute with two options to be used in the child product -->
26+
<createData entity="productAttributeWithTwoOptions" stepKey="createConfigProductAttribute"/>
27+
<createData entity="productAttributeOption1" stepKey="createConfigProductAttributeOption1">
28+
<requiredEntity createDataKey="createConfigProductAttribute"/>
29+
</createData>
30+
<createData entity="productAttributeOption2" stepKey="createConfigProductAttributeOption2">
31+
<requiredEntity createDataKey="createConfigProductAttribute"/>
32+
</createData>
33+
34+
<!-- Add the attribute just created to default attribute set -->
35+
<createData entity="AddToDefaultSet" stepKey="createConfigAddToAttributeSet">
36+
<requiredEntity createDataKey="createConfigProductAttribute"/>
37+
</createData>
38+
39+
<!-- Get the first option of the attribute created -->
40+
<getData entity="ProductAttributeOptionGetter" index="1" stepKey="getConfigAttributeOption1">
41+
<requiredEntity createDataKey="createConfigProductAttribute"/>
42+
</getData>
43+
44+
<!-- Get the second option of the attribute created -->
45+
<getData entity="ProductAttributeOptionGetter" index="2" stepKey="getConfigAttributeOption2">
46+
<requiredEntity createDataKey="createConfigProductAttribute"/>
47+
</getData>
48+
49+
<!-- Create Configurable product -->
50+
<createData entity="BaseConfigurableProduct" stepKey="createConfigProduct">
51+
<requiredEntity createDataKey="createCategory"/>
52+
</createData>
53+
54+
<!-- Create a simple product and give it the attribute with the first option -->
55+
<createData entity="ApiSimpleOne" stepKey="createConfigChildProduct1">
56+
<requiredEntity createDataKey="createConfigProductAttribute"/>
57+
<requiredEntity createDataKey="getConfigAttributeOption1"/>
58+
<field key="price">10.00</field>
59+
</createData>
60+
61+
<!--Create a simple product and give it the attribute with the second option -->
62+
<createData entity="ApiSimpleTwo" stepKey="createConfigChildProduct2">
63+
<requiredEntity createDataKey="createConfigProductAttribute"/>
64+
<requiredEntity createDataKey="getConfigAttributeOption2"/>
65+
<field key="price">20.00</field>
66+
</createData>
67+
68+
<!-- Create the configurable product -->
69+
<createData entity="ConfigurableProductTwoOptions" stepKey="createConfigProductOption">
70+
<requiredEntity createDataKey="createConfigProduct"/>
71+
<requiredEntity createDataKey="createConfigProductAttribute"/>
72+
<requiredEntity createDataKey="getConfigAttributeOption1"/>
73+
<requiredEntity createDataKey="getConfigAttributeOption2"/>
74+
</createData>
75+
76+
<!-- Add the first simple product to the configurable product -->
77+
<createData entity="ConfigurableProductAddChild" stepKey="createConfigProductAddChild1">
78+
<requiredEntity createDataKey="createConfigProduct"/>
79+
<requiredEntity createDataKey="createConfigChildProduct1"/>
80+
</createData>
81+
82+
<!-- Add the second simple product to the configurable product -->
83+
<createData entity="ConfigurableProductAddChild" stepKey="createConfigProductAddChild2">
84+
<requiredEntity createDataKey="createConfigProduct"/>
85+
<requiredEntity createDataKey="createConfigChildProduct2"/>
86+
</createData>
87+
88+
<!--Open Index Management Page and Select Index mode "Update by Schedule" -->
89+
<magentoCLI stepKey="setIndexerMode" command="indexer:set-mode" arguments="schedule" />
90+
91+
<!-- Run cron -->
92+
<magentoCron stepKey="runIndexCronJobs" groups="index"/>
93+
<comment userInput="Adding the comment to replace CliCacheFlushActionGroup action group ('cache:flush' command) for preserving Backward Compatibility" stepKey="flushCache"/>
94+
95+
<!-- Wait till cron job runs for schedule updates -->
96+
<wait time="60" stepKey="waitForUpdateStarts"/>
97+
</before>
98+
<after>
99+
<magentoCLI stepKey="setIndexerMode" command="indexer:set-mode" arguments="realtime" />
100+
<comment userInput="Adding the comment to replace CliIndexerReindexActionGroup action group ('indexer:reindex' commands) for preserving Backward Compatibility" stepKey="indexerReindex"/>
101+
102+
<!-- Delete Created Data -->
103+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
104+
<deleteData createDataKey="createConfigProduct" stepKey="deleteConfigProduct"/>
105+
<deleteData createDataKey="createConfigChildProduct1" stepKey="deleteConfigChildProduct1"/>
106+
<deleteData createDataKey="createConfigChildProduct2" stepKey="deleteConfigChildProduct2"/>
107+
<deleteData createDataKey="createConfigProductAttribute" stepKey="deleteAttribute"/>
108+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
109+
110+
<!-- Reindex invalidated indices after product attribute has been created/deleted -->
111+
<magentoCron groups="index" stepKey="reindexInvalidatedIndices"/>
112+
</after>
113+
114+
<!-- Open Product in Store Front Page -->
115+
<actionGroup ref="StorefrontOpenProductEntityPageActionGroup" stepKey="openProductInStoreFront">
116+
<argument name="product" value="$createConfigProduct$"/>
117+
</actionGroup>
118+
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="waitForProductToLoad"/>
119+
120+
<!-- Verify category,Configurable product and initial price -->
121+
<actionGroup ref="StorefrontAssertCategoryNameIsShownInMenuActionGroup" stepKey="seeCategoryInFrontPage">
122+
<argument name="categoryName" value="$$createCategory.name$$"/>
123+
</actionGroup>
124+
<actionGroup ref="StorefrontAssertProductNameOnProductPageActionGroup" stepKey="seeProductNameInStoreFront">
125+
<argument name="productName" value="$$createConfigProduct.name$$"/>
126+
</actionGroup>
127+
<actionGroup ref="StorefrontAssertProductPriceOnProductPageActionGroup" stepKey="seeInitialPriceInStoreFront">
128+
<argument name="productPrice" value="$$createConfigChildProduct1.price$$"/>
129+
</actionGroup>
130+
<actionGroup ref="StorefrontAssertProductSkuOnProductPageActionGroup" stepKey="seeProductSkuInStoreFront">
131+
<argument name="productSku" value="$$createConfigProduct.sku$$"/>
132+
</actionGroup>
133+
<actionGroup ref="AssertStorefrontProductStockStatusOnProductPageActionGroup" stepKey="seeProductStatusInStoreFront">
134+
<argument name="productStockStatus" value="In Stock"/>
135+
</actionGroup>
136+
137+
<!-- Verify First Child Product attribute option is displayed -->
138+
<see selector="{{StorefrontProductInfoMainSection.productOptionSelect($$createConfigProductAttribute.default_value$$)}}" userInput="$$getConfigAttributeOption1.label$$" stepKey="seeOption1"/>
139+
140+
<!-- Select product Attribute option1, option2 and option3 and verify changes in the price -->
141+
<actionGroup ref="StorefrontProductPageSelectDropDownOptionValueActionGroup" stepKey="selectOption1">
142+
<argument name="attributeLabel" value="$$createConfigProductAttribute.default_value$$"/>
143+
<argument name="optionLabel" value="$$getConfigAttributeOption1.label$$"/>
144+
</actionGroup>
145+
<actionGroup ref="StorefrontAssertProductPriceOnProductPageActionGroup" stepKey="seeChildProduct1PriceInStoreFront">
146+
<argument name="productPrice" value="$$createConfigChildProduct1.price$$"/>
147+
</actionGroup>
148+
<actionGroup ref="StorefrontProductPageSelectDropDownOptionValueActionGroup" stepKey="selectOption2">
149+
<argument name="attributeLabel" value="$$createConfigProductAttribute.default_value$$"/>
150+
<argument name="optionLabel" value="$$getConfigAttributeOption2.label$$"/>
151+
</actionGroup>
152+
<actionGroup ref="StorefrontAssertProductPriceOnProductPageActionGroup" stepKey="seeChildProduct2PriceInStoreFront">
153+
<argument name="productPrice" value="$$createConfigChildProduct2.price$$"/>
154+
</actionGroup>
155+
<!-- Open Product Index Page and Filter First Child product -->
156+
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="navigateToProductIndex"/>
157+
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="filterProduct"/>
158+
<actionGroup ref="CliCacheCleanActionGroup" stepKey="cleanFullPageCache">
159+
<argument name="tags" value="full_page"/>
160+
</actionGroup>
161+
<actionGroup ref="AdminProductPageOpenByIdActionGroup" stepKey="selectFirstRow">
162+
<argument name="productId" value="$$createConfigChildProduct1.id$$"/>
163+
</actionGroup>
164+
<waitForPageLoad stepKey="waitForProductPageToLoad"/>
165+
166+
<updateData entity="SimpleProductUpdatePrice90" createDataKey="createConfigChildProduct1" stepKey="updateSimpleProductOne"/>
167+
168+
<!-- Run cron -->
169+
<magentoCron stepKey="runIndexCronJobs" groups="index"/>
170+
<comment userInput="Adding the comment to replace CliCacheFlushActionGroup action group ('cache:flush' command) for preserving Backward Compatibility" stepKey="flushCache"/>
171+
172+
<!-- Wait till cron job runs for schedule updates -->
173+
<wait time="60" stepKey="waitForUpdateStarts"/>
174+
175+
<!-- Open Product Store Front Page -->
176+
<actionGroup ref="StorefrontOpenProductEntityPageActionGroup" stepKey="openProductInStoreFront1">
177+
<argument name="product" value="$createConfigProduct$"/>
178+
</actionGroup>
179+
<comment userInput="CommentConfigurableProductTwoOptions is added to preserve the step key for backward compatibility" stepKey="waitForProductToLoad1"/>
180+
181+
<!-- Verify category,configurable product and updated price -->
182+
<actionGroup ref="StorefrontAssertCategoryNameIsShownInMenuActionGroup" stepKey="seeCategoryInFrontPage1">
183+
<argument name="categoryName" value="$$createCategory.name$$"/>
184+
</actionGroup>
185+
<actionGroup ref="StorefrontAssertProductNameOnProductPageActionGroup" stepKey="seeProductNameInStoreFront1">
186+
<argument name="productName" value="$$createConfigProduct.name$$"/>
187+
</actionGroup>
188+
<actionGroup ref="StorefrontAssertProductPriceOnProductPageActionGroup" stepKey="seeUpdatedProductPriceInStoreFront">
189+
<argument name="productPrice" value="$$createConfigChildProduct2.price$$"/>
190+
</actionGroup>
191+
<actionGroup ref="StorefrontAssertProductSkuOnProductPageActionGroup" stepKey="seeProductSkuInStoreFront1">
192+
<argument name="productSku" value="$$createConfigProduct.sku$$"/>
193+
</actionGroup>
194+
<actionGroup ref="AssertStorefrontProductStockStatusOnProductPageActionGroup" stepKey="seeProductStatusInStoreFront1">
195+
<argument name="productStockStatus" value="In Stock"/>
196+
</actionGroup>
197+
198+
<!-- Verify product Attribute Option1 is displayed -->
199+
<see selector="{{StorefrontProductInfoMainSection.productOptionSelect($$createConfigProductAttribute.default_value$$)}}" userInput="$$getConfigAttributeOption1.label$$" stepKey="seeOption1AfterUpdate"/>
200+
201+
<!--Select product Attribute option1 and verify changes in the price -->
202+
<actionGroup ref="StorefrontProductPageSelectDropDownOptionValueActionGroup" stepKey="selectOption1AfterUpdate">
203+
<argument name="attributeLabel" value="$$createConfigProductAttribute.default_value$$"/>
204+
<argument name="optionLabel" value="$$getConfigAttributeOption1.label$$"/>
205+
</actionGroup>
206+
<actionGroup ref="StorefrontAssertProductPriceOnProductPageActionGroup" stepKey="seeChildProduct1PriceInStoreFrontAfterUpdate">
207+
<argument name="productPrice" value="$$createConfigChildProduct1.price$$"/>
208+
</actionGroup>
209+
</test>
210+
</tests>

0 commit comments

Comments
 (0)