Skip to content

Commit 9d0022d

Browse files
committed
MAGETWO-45666: "Refresh cache" message is not displayed when changing category page layout
- Added observer for invalidating cache on category design change
1 parent d617351 commit 9d0022d

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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\Observer;
9+
10+
use Magento\Framework\Event\Observer;
11+
use Magento\Framework\Event\ObserverInterface;
12+
13+
/**
14+
* Observer for invalidating cache on catalog category design change
15+
*/
16+
class InvalidateCacheOnCategoryDesignChange implements ObserverInterface
17+
{
18+
/**
19+
* @var array
20+
*/
21+
private $designAttributes = [
22+
'custom_design',
23+
'page_layout',
24+
'custom_layout_update',
25+
'custom_apply_to_products',
26+
'custom_use_parent_settings'
27+
];
28+
29+
/**
30+
* @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
31+
*/
32+
public function __construct(\Magento\Framework\App\Cache\TypeListInterface $cacheTypeList)
33+
{
34+
$this->cacheTypeList = $cacheTypeList;
35+
}
36+
37+
/**
38+
* Invalidate cache on category design attribute value changed
39+
*
40+
* @param \Magento\Framework\Event\Observer $observer
41+
*/
42+
public function execute(Observer $observer)
43+
{
44+
$category = $observer->getEvent()->getEntity();
45+
if (!$category->isObjectNew()) {
46+
foreach ($this->designAttributes as $designAttribute) {
47+
if ($category->dataHasChangedFor($designAttribute)) {
48+
$this->cacheTypeList->invalidate(
49+
[
50+
\Magento\PageCache\Model\Cache\Type::TYPE_IDENTIFIER,
51+
\Magento\Framework\App\Cache\Type\Layout::TYPE_IDENTIFIER
52+
]
53+
);
54+
break;
55+
}
56+
}
57+
}
58+
}
59+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="DisplayRefreshCacheAfterChangingCategoryPageLayoutTest">
12+
<annotations>
13+
<features value="Catalog"/>
14+
<title value="'Refresh cache' admin notification is displayed when changing category page layout"/>
15+
<description value="'Refresh cache' message is not displayed when changing category page layout"/>
16+
<severity value="MAJOR"/>
17+
<testCaseId value="MC-17031"/>
18+
<useCaseId value="MAGETWO-45666"/>
19+
<group value="catalog"/>
20+
</annotations>
21+
<before>
22+
<!-- Create category, flush cache and log in -->
23+
<comment userInput="Create category, flush cache and log in" stepKey="createCategoryAndLogIn"/>
24+
<createData entity="SimpleSubCategory" stepKey="simpleCategory"/>
25+
<actionGroup ref="LoginAsAdmin" stepKey="logInAsAdmin"/>
26+
<magentoCLI command="cache:flush" stepKey="flushCache"/>
27+
</before>
28+
<after>
29+
<!-- Delete category and log out -->
30+
<comment userInput="Delete category and log out" stepKey="deleteCategoryAndLogOut"/>
31+
<deleteData createDataKey="simpleCategory" stepKey="deleteCategory"/>
32+
<actionGroup ref="logout" stepKey="logOutFromAdmin"/>
33+
<magentoCLI command="cache:flush" stepKey="flushCache"/>
34+
</after>
35+
<!-- Navigate to category details page -->
36+
<comment userInput="Navigate to category details page" stepKey="navigateToAdminCategoryPage"/>
37+
<actionGroup ref="goToAdminCategoryPageById" stepKey="goToAdminCategoryPage">
38+
<argument name="id" value="$$simpleCategory.id$$"/>
39+
</actionGroup>
40+
<!-- Open design tab and set layout -->
41+
<comment userInput="Open design tab and set layout" stepKey="setLayoutAndSave"/>
42+
<click selector="{{CategoryDesignSection.DesignTab}}" stepKey="clickOnDesignTab"/>
43+
<waitForElementVisible selector="{{CategoryDesignSection.LayoutDropdown}}" stepKey="waitForLayoutDropDown" />
44+
<selectOption selector="{{CategoryDesignSection.LayoutDropdown}}" userInput="2 columns with right bar" stepKey="selectAnOption" />
45+
<click selector="{{ContentManagementSection.Save}}" stepKey="clickSaveConfig" />
46+
<waitForPageLoad stepKey="waitSaveToApply"/>
47+
<!-- See if warning message displays -->
48+
<comment userInput="See if warning message displays" stepKey="checkWarningMessagePresence"/>
49+
<see selector="{{AdminMessagesSection.warningMessage}}" userInput="Please go to Cache Management and refresh cache types" stepKey="seeWarningMessage"/>
50+
</test>
51+
</tests>

app/code/Magento/Catalog/etc/events.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
</event>
2727
<event name="magento_catalog_api_data_categoryinterface_save_after">
2828
<observer name="legacy_category_save_after" instance="Magento\Framework\EntityManager\Observer\AfterEntitySave" />
29+
<observer name="invalidate_cache_on_category_design_change" instance="Magento\Catalog\Observer\InvalidateCacheOnCategoryDesignChange" />
2930
</event>
3031
<event name="magento_catalog_api_data_categoryinterface_delete_before">
3132
<observer name="legacy_category_delete_before" instance="Magento\Framework\EntityManager\Observer\BeforeEntityDelete" />

0 commit comments

Comments
 (0)