Skip to content

Commit 23cfe6d

Browse files
author
Valeriy Nayda
committed
Merge remote-tracking branch 'dragons/MAGETWO-32724' into MAGETWO-35251
2 parents 4a08c4d + 8e62f28 commit 23cfe6d

File tree

4 files changed

+132
-1
lines changed

4 files changed

+132
-1
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Model\Plugin\PageCache\Product;
8+
9+
use Magento\Catalog\Model\Product;
10+
use Magento\Indexer\Model\CacheContext;
11+
use Magento\Framework\Event\ManagerInterface as EventManager;
12+
13+
class Action
14+
{
15+
/**
16+
* @var CacheContext
17+
*/
18+
protected $cacheContext;
19+
20+
/**
21+
* @var EventManager
22+
*/
23+
protected $eventManager;
24+
25+
/**
26+
* @param CacheContext $cacheContext
27+
* @param EventManager $eventManager
28+
*/
29+
public function __construct(
30+
CacheContext $cacheContext,
31+
EventManager $eventManager
32+
) {
33+
$this->cacheContext = $cacheContext;
34+
$this->eventManager = $eventManager;
35+
}
36+
37+
/**
38+
* @param Product\Action $subject
39+
* @param callable $proceed
40+
* @param $productIds
41+
* @param $attrData
42+
* @param $storeId
43+
* @return Product\Action
44+
*
45+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
46+
*/
47+
public function aroundUpdateAttributes(
48+
Product\Action $subject,
49+
\Closure $proceed,
50+
$productIds,
51+
$attrData,
52+
$storeId
53+
) {
54+
$returnValue = $proceed($productIds, $attrData, $storeId);
55+
56+
$this->cacheContext->registerEntities(Product::CACHE_TAG, $productIds);
57+
$this->eventManager->dispatch('clean_cache_by_tags', ['object' => $this->cacheContext]);
58+
59+
return $returnValue;
60+
}
61+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Test\Unit\Model\Plugin\PageCache\Product;
7+
8+
use Magento\Catalog\Model\Product;
9+
10+
class ActionTest extends \PHPUnit_Framework_TestCase
11+
{
12+
public function testAroundUpdateAttributes()
13+
{
14+
$productIds = [1, 2, 3];
15+
$attrData = [];
16+
$storeId = 1;
17+
18+
$productActionMock = $this->getMock('Magento\Catalog\Model\Product\Action', [], [], '', false);
19+
20+
$cacheContextMock = $this->getMock('Magento\Indexer\Model\CacheContext', [], [], '', false);
21+
$cacheContextMock->expects($this->once())
22+
->method('registerEntities')
23+
->with(Product::CACHE_TAG, $productIds);
24+
25+
26+
$eventManagerMock = $this->getMock('Magento\Framework\Event\ManagerInterface', [], [], '', false);
27+
$eventManagerMock->expects($this->once())
28+
->method('dispatch')
29+
->with('clean_cache_by_tags', ['object' => $cacheContextMock]);
30+
31+
$model = new \Magento\Catalog\Model\Plugin\PageCache\Product\Action($cacheContextMock, $eventManagerMock);
32+
33+
$closureMock = function () use ($productActionMock) {
34+
return $productActionMock;
35+
};
36+
37+
$model->aroundUpdateAttributes($productActionMock, $closureMock, $productIds, $attrData, $storeId);
38+
}
39+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,7 @@
7676
</argument>
7777
</arguments>
7878
</type>
79+
<type name="Magento\Catalog\Model\Product\Action">
80+
<plugin name="invalidate_pagecache_after_update_product_attributes" type="Magento\Catalog\Model\Plugin\PageCache\Product\Action" />
81+
</type>
7982
</config>

app/code/Magento/CatalogInventory/Model/Indexer/Stock/AbstractAction.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
namespace Magento\CatalogInventory\Model\Indexer\Stock;
1010

11+
use Magento\Catalog\Model\Category;
12+
1113
/**
1214
* Abstract action reindex class
1315
*
@@ -52,6 +54,17 @@ abstract class AbstractAction
5254
*/
5355
protected $_isNeedUseIdxTable = false;
5456

57+
/**
58+
* @var \Magento\Indexer\Model\CacheContext
59+
*/
60+
private $cacheContext;
61+
62+
/**
63+
* @var \Magento\Framework\Event\ManagerInterface
64+
*/
65+
private $eventManager;
66+
67+
5568
/**
5669
* @param \Magento\Framework\App\Resource $resource
5770
* @param \Magento\CatalogInventory\Model\Resource\Indexer\StockFactory $indexerFactory
@@ -60,11 +73,16 @@ abstract class AbstractAction
6073
public function __construct(
6174
\Magento\Framework\App\Resource $resource,
6275
\Magento\CatalogInventory\Model\Resource\Indexer\StockFactory $indexerFactory,
63-
\Magento\Catalog\Model\Product\Type $catalogProductType
76+
\Magento\Catalog\Model\Product\Type $catalogProductType,
77+
\Magento\Indexer\Model\CacheContext $cacheContext,
78+
\Magento\Framework\Event\ManagerInterface $eventManager
79+
6480
) {
6581
$this->_resource = $resource;
6682
$this->_indexerFactory = $indexerFactory;
6783
$this->_catalogProductType = $catalogProductType;
84+
$this->cacheContext = $cacheContext;
85+
$this->eventManager = $eventManager;
6886
}
6987

7088
/**
@@ -228,6 +246,16 @@ protected function _reindexRows($productIds = [])
228246
}
229247
}
230248

249+
$select = $adapter->select()
250+
->distinct(true)
251+
->from($this->_getTable('catalog_category_product'), [ 'category_id'])
252+
->where('product_id IN(?)', $processIds);
253+
254+
$affectedCategories = $adapter->fetchCol($select);
255+
$this->cacheContext->registerEntities(Category::CACHE_TAG, $affectedCategories);
256+
257+
$this->eventManager->dispatch('clean_cache_by_tags', ['object' => $this->cacheContext]);
258+
231259
return $this;
232260
}
233261

0 commit comments

Comments
 (0)