Skip to content

Commit 6093db0

Browse files
author
Egor Shitikov
committed
MAGETWO-33690: Category page displays outdated prices after catalog price rule is deleted
1 parent 7de91b4 commit 6093db0

File tree

3 files changed

+198
-0
lines changed

3 files changed

+198
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@
171171
<plugin name="catalogProductFlatIndexerStoreGroup" type="Magento\Catalog\Model\Indexer\Product\Flat\Plugin\StoreGroup" />
172172
<plugin name="categoryStoreGroupAroundSave" type="Magento\Catalog\Model\Indexer\Category\Product\Plugin\StoreGroup"/>
173173
</type>
174+
<type name="Magento\CatalogRule\Model\Indexer\AbstractIndexer">
175+
<plugin name="abstractIndexerAroundSave" type="Magento\PageCache\Model\Indexer\CatalogRulePlugin"/>
176+
</type>
174177
<type name="Magento\Customer\Api\GroupRepositoryInterface">
175178
<plugin name="invalidatePriceIndexerOnCustomerGroup" type="Magento\Catalog\Model\Indexer\Product\Price\Plugin\CustomerGroup"/>
176179
</type>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\PageCache\Model\Indexer;
7+
8+
/**
9+
* Class CatalogRulePlugin
10+
* @package Magento\PageCache\Model\Indexer
11+
*/
12+
class CatalogRulePlugin
13+
{
14+
/**
15+
* @var \Magento\PageCache\Model\Config
16+
*/
17+
protected $config;
18+
19+
/**
20+
* @var \Magento\Framework\App\CacheInterface
21+
*/
22+
protected $cache;
23+
24+
/**
25+
* @var \Magento\Framework\App\Cache\Type\FrontendPool
26+
*/
27+
protected $pool;
28+
29+
/**
30+
* @param \Magento\PageCache\Model\Config $config
31+
* @param \Magento\Framework\App\Cache\TypeListInterface $typeList
32+
* @param \Magento\Framework\App\Cache\Type\FrontendPool $pool
33+
*/
34+
public function __construct(
35+
\Magento\PageCache\Model\Config $config,
36+
\Magento\Framework\App\CacheInterface $cache,
37+
\Magento\Framework\App\Cache\Type\FrontendPool $pool
38+
) {
39+
$this->config = $config;
40+
$this->cache = $cache;
41+
$this->pool = $pool;
42+
}
43+
44+
/**
45+
* @param \Magento\CatalogRule\Model\Indexer\AbstractIndexer $subject
46+
*
47+
* @return \Magento\CatalogRule\Model\Indexer\AbstractIndexer
48+
*/
49+
public function afterExecuteFull(
50+
\Magento\CatalogRule\Model\Indexer\AbstractIndexer $subject
51+
) {
52+
if ($this->config->isEnabled()) {
53+
$this->pool->get(
54+
\Magento\PageCache\Model\Cache\Type::TYPE_IDENTIFIER
55+
)->clean(
56+
\Zend_Cache::CLEANING_MODE_ALL,
57+
[
58+
\Magento\Catalog\Model\Category::CACHE_TAG,
59+
\Magento\Catalog\Model\Product::CACHE_TAG
60+
]
61+
);
62+
63+
$this->cache->clean(
64+
[
65+
\Magento\Catalog\Model\Category::CACHE_TAG,
66+
\Magento\Catalog\Model\Product::CACHE_TAG,
67+
\Magento\Catalog\Model\Product\Compare\Item::CACHE_TAG,
68+
\Magento\Wishlist\Model\Wishlist::CACHE_TAG
69+
]
70+
);
71+
}
72+
return $subject;
73+
}
74+
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\PageCache\Test\Unit\Model\Indexer;
7+
8+
/**
9+
* Class CatalogRulePluginTest
10+
* @package Magento\PageCache\Test\Unit\Model\Indexer
11+
*/
12+
class CatalogRulePluginTest extends \PHPUnit_Framework_TestCase
13+
{
14+
/**
15+
* @var \PHPUnit_Framework_MockObject_MockObject
16+
*/
17+
protected $configMock;
18+
19+
/**
20+
* @var \PHPUnit_Framework_MockObject_MockObject
21+
*/
22+
protected $cacheMock;
23+
24+
/**
25+
* @var \PHPUnit_Framework_MockObject_MockObject
26+
*/
27+
protected $poolMock;
28+
29+
/**
30+
* @var \PHPUnit_Framework_MockObject_MockObject
31+
*/
32+
protected $frontCache;
33+
34+
/**
35+
* @var \Magento\PageCache\Model\Indexer\CatalogRulePlugin
36+
*/
37+
protected $model;
38+
39+
protected function setUp()
40+
{
41+
$this->configMock = $this->getMock(
42+
'\Magento\PageCache\Model\Config',
43+
['isEnabled'],
44+
[],
45+
'',
46+
false
47+
);
48+
49+
$this->cacheMock = $this->getMockForAbstractClass(
50+
'\Magento\Framework\App\CacheInterface',
51+
[],
52+
'',
53+
false,
54+
true,
55+
true,
56+
['clean']
57+
);
58+
59+
$this->frontCache = $this->getMockForAbstractClass(
60+
'\Magento\Framework\Cache\FrontendInterface',
61+
[],
62+
'',
63+
false,
64+
true,
65+
true,
66+
['clean']
67+
);
68+
69+
$this->poolMock = $this->getMock(
70+
'\Magento\Framework\App\Cache\Type\FrontendPool',
71+
['get'],
72+
['clean'],
73+
'',
74+
false
75+
);
76+
77+
$this->model = new \Magento\PageCache\Model\Indexer\CatalogRulePlugin(
78+
$this->configMock,
79+
$this->cacheMock,
80+
$this->poolMock
81+
);
82+
}
83+
84+
public function testAfterExecuteFull()
85+
{
86+
$this->configMock->expects($this->once())
87+
->method('isEnabled')
88+
->willReturn(true);
89+
$this->poolMock->expects($this->once())
90+
->method('get')
91+
->with(\Magento\PageCache\Model\Cache\Type::TYPE_IDENTIFIER)
92+
->willReturn($this->frontCache);
93+
$this->frontCache->expects($this->once())->method('clean')
94+
->with(
95+
\Zend_Cache::CLEANING_MODE_ALL,
96+
[
97+
\Magento\Catalog\Model\Category::CACHE_TAG,
98+
\Magento\Catalog\Model\Product::CACHE_TAG
99+
]
100+
);
101+
$this->cacheMock->expects($this->once())
102+
->method('clean')
103+
->with(
104+
[
105+
\Magento\Catalog\Model\Category::CACHE_TAG,
106+
\Magento\Catalog\Model\Product::CACHE_TAG,
107+
\Magento\Catalog\Model\Product\Compare\Item::CACHE_TAG,
108+
\Magento\Wishlist\Model\Wishlist::CACHE_TAG
109+
]
110+
);
111+
112+
$this->model->afterExecuteFull(
113+
$this->getMockForAbstractClass(
114+
'\Magento\CatalogRule\Model\Indexer\AbstractIndexer',
115+
[],
116+
'',
117+
false
118+
)
119+
);
120+
}
121+
}

0 commit comments

Comments
 (0)