Skip to content

Commit 437bbaa

Browse files
author
Momotenko,Natalia(nmomotenko)
committed
Merge pull request #150 from magento-webdev/UI
[UI & Troll] Bug fixes
2 parents 10d1600 + f6d3657 commit 437bbaa

File tree

12 files changed

+227
-10
lines changed

12 files changed

+227
-10
lines changed

app/code/Magento/CatalogRule/Model/Indexer/AbstractIndexer.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,23 @@ abstract class AbstractIndexer implements IndexerActionInterface, MviewActionInt
1616
*/
1717
protected $indexBuilder;
1818

19+
/**
20+
* Application Event Dispatcher
21+
*
22+
* @var \Magento\Framework\Event\ManagerInterface
23+
*/
24+
protected $_eventManager;
25+
1926
/**
2027
* @param IndexBuilder $indexBuilder
28+
* @param \Magento\Framework\Event\ManagerInterface $eventManager
2129
*/
22-
public function __construct(IndexBuilder $indexBuilder)
23-
{
30+
public function __construct(
31+
IndexBuilder $indexBuilder,
32+
\Magento\Framework\Event\ManagerInterface $eventManager
33+
) {
2434
$this->indexBuilder = $indexBuilder;
35+
$this->_eventManager = $eventManager;
2536
}
2637

2738
/**
@@ -43,6 +54,20 @@ public function execute($ids)
4354
public function executeFull()
4455
{
4556
$this->indexBuilder->reindexFull();
57+
$this->_eventManager->dispatch('clean_cache_by_tags', ['object' => $this]);
58+
}
59+
60+
/**
61+
* Get affected cache tags
62+
*
63+
* @return array
64+
*/
65+
public function getIdentities()
66+
{
67+
return [
68+
\Magento\Catalog\Model\Category::CACHE_TAG,
69+
\Magento\Catalog\Model\Product::CACHE_TAG
70+
];
4671
}
4772

4873
/**

app/code/Magento/CatalogRule/Model/Rule.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ class Rule extends \Magento\Rule\Model\AbstractModel
143143
*/
144144
protected $dateTime;
145145

146+
/**
147+
* @var \Magento\CatalogRule\Model\Indexer\Rule\RuleProductProcessor;
148+
*/
149+
protected $_ruleProductProcessor;
150+
146151
/**
147152
* @param \Magento\Framework\Model\Context $context
148153
* @param \Magento\Framework\Registry $registry
@@ -158,6 +163,7 @@ class Rule extends \Magento\Rule\Model\AbstractModel
158163
* @param \Magento\CatalogRule\Helper\Data $catalogRuleData
159164
* @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypesList
160165
* @param \Magento\Framework\Stdlib\DateTime $dateTime
166+
* @param \Magento\CatalogRule\Model\Indexer\Rule\RuleProductProcessor $ruleProductProcessor
161167
* @param \Magento\Framework\Model\Resource\AbstractResource $resource
162168
* @param \Magento\Framework\Data\Collection\Db $resourceCollection
163169
* @param array $relatedCacheTypes
@@ -179,6 +185,7 @@ public function __construct(
179185
\Magento\CatalogRule\Helper\Data $catalogRuleData,
180186
\Magento\Framework\App\Cache\TypeListInterface $cacheTypesList,
181187
\Magento\Framework\Stdlib\DateTime $dateTime,
188+
\Magento\CatalogRule\Model\Indexer\Rule\RuleProductProcessor $ruleProductProcessor,
182189
\Magento\Framework\Model\Resource\AbstractResource $resource = null,
183190
\Magento\Framework\Data\Collection\Db $resourceCollection = null,
184191
array $relatedCacheTypes = [],
@@ -195,6 +202,7 @@ public function __construct(
195202
$this->_cacheTypesList = $cacheTypesList;
196203
$this->_relatedCacheTypes = $relatedCacheTypes;
197204
$this->dateTime = $dateTime;
205+
$this->_ruleProductProcessor = $ruleProductProcessor;
198206
parent::__construct($context, $registry, $formFactory, $localeDate, $resource, $resourceCollection, $data);
199207
}
200208

@@ -445,4 +453,33 @@ protected function _invalidateCache()
445453
}
446454
return $this;
447455
}
456+
457+
/**
458+
* {@inheritdoc}
459+
*
460+
* @return $this
461+
*/
462+
public function afterSave()
463+
{
464+
if ($this->isObjectNew()) {
465+
$this->getMatchingProductIds();
466+
if (!empty($this->_productIds) && is_array($this->_productIds)) {
467+
$this->_ruleProductProcessor->reindexList($this->_productIds);
468+
}
469+
} else {
470+
$this->_ruleProductProcessor->getIndexer()->invalidate();
471+
}
472+
return parent::afterSave();
473+
}
474+
475+
/**
476+
* {@inheritdoc}
477+
*
478+
* @return $this
479+
*/
480+
public function afterDelete()
481+
{
482+
$this->_ruleProductProcessor->getIndexer()->invalidate();
483+
return parent::afterDelete();
484+
}
448485
}

app/code/Magento/CatalogRule/Test/Unit/Model/Indexer/AbstractIndexerTest.php

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,35 @@ class AbstractIndexerTest extends \PHPUnit_Framework_TestCase
1818
*/
1919
protected $indexer;
2020

21+
/**
22+
* @var \Magento\Framework\Event\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject
23+
*/
24+
protected $_eventManagerMock;
25+
26+
/**
27+
* Set up test
28+
*
29+
* @return void
30+
*/
2131
protected function setUp()
2232
{
33+
$this->_eventManagerMock = $this->getMock('\Magento\Framework\Event\ManagerInterface');
2334
$this->indexBuilder = $this->getMock('Magento\CatalogRule\Model\Indexer\IndexBuilder', [], [], '', false);
2435

2536
$this->indexer = $this->getMockForAbstractClass(
2637
'Magento\CatalogRule\Model\Indexer\AbstractIndexer',
27-
[$this->indexBuilder]
38+
[
39+
$this->indexBuilder,
40+
$this->_eventManagerMock
41+
]
2842
);
2943
}
3044

45+
/**
46+
* Test execute
47+
*
48+
* @return void
49+
*/
3150
public function testExecute()
3251
{
3352
$ids = [1, 2, 5];
@@ -36,22 +55,40 @@ public function testExecute()
3655
$this->indexer->execute($ids);
3756
}
3857

58+
/**
59+
* Test execute full reindex action
60+
*
61+
* @return void
62+
*/
3963
public function testExecuteFull()
4064
{
4165
$this->indexBuilder->expects($this->once())->method('reindexFull');
66+
$this->_eventManagerMock->expects($this->once())
67+
->method('dispatch')
68+
->with(
69+
'clean_cache_by_tags',
70+
['object' => $this->indexer]
71+
);
4272

4373
$this->indexer->executeFull();
4474
}
4575

4676
/**
4777
* @expectedException \Magento\CatalogRule\CatalogRuleException
4878
* @expectedExceptionMessage Could not rebuild index for empty products array
79+
*
80+
* @return void
4981
*/
5082
public function testExecuteListWithEmptyIds()
5183
{
5284
$this->indexer->executeList([]);
5385
}
5486

87+
/**
88+
* @throws \Magento\CatalogRule\CatalogRuleException
89+
*
90+
* @return void
91+
*/
5592
public function testExecuteList()
5693
{
5794
$ids = [1, 2, 5];
@@ -63,12 +100,19 @@ public function testExecuteList()
63100
/**
64101
* @expectedException \Magento\CatalogRule\CatalogRuleException
65102
* @expectedExceptionMessage Could not rebuild index for undefined product
103+
*
104+
* @return void
66105
*/
67106
public function testExecuteRowWithEmptyId()
68107
{
69108
$this->indexer->executeRow(null);
70109
}
71110

111+
/**
112+
* @throws \Magento\CatalogRule\CatalogRuleException
113+
*
114+
* @return void
115+
*/
72116
public function testExecuteRow()
73117
{
74118
$id = 5;

app/code/Magento/CatalogRule/Test/Unit/Model/RuleTest.php

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,31 @@ class RuleTest extends \PHPUnit_Framework_TestCase
3131
/** @var \Magento\Rule\Model\Condition\Combine|\PHPUnit_Framework_MockObject_MockObject */
3232
protected $condition;
3333

34+
/**
35+
* @var \Magento\CatalogRule\Model\Indexer\Rule\RuleProductProcessor|\PHPUnit_Framework_MockObject_MockObject
36+
*/
37+
protected $_ruleProductProcessor;
38+
39+
/**
40+
* @var \Magento\Catalog\Model\Resource\Product\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
41+
*/
42+
protected $_productCollectionFactory;
43+
44+
/**
45+
* @var \Magento\Framework\Model\Resource\Iterator|\PHPUnit_Framework_MockObject_MockObject
46+
*/
47+
protected $_resourceIterator;
48+
49+
/**
50+
* @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject
51+
*/
52+
protected $productModel;
53+
54+
/**
55+
* Set up before test
56+
*
57+
* @return void
58+
*/
3459
protected function setUp()
3560
{
3661
$this->storeManager = $this->getMock('Magento\Store\Model\StoreManagerInterface');
@@ -74,20 +99,48 @@ protected function setUp()
7499
'',
75100
false
76101
);
102+
$this->_ruleProductProcessor = $this->getMock(
103+
'\Magento\CatalogRule\Model\Indexer\Rule\RuleProductProcessor',
104+
[],
105+
[],
106+
'',
107+
false
108+
);
109+
110+
$this->_productCollectionFactory = $this->getMock(
111+
'\Magento\Catalog\Model\Resource\Product\CollectionFactory',
112+
['create'],
113+
[],
114+
'',
115+
false
116+
);
117+
118+
$this->_resourceIterator = $this->getMock(
119+
'\Magento\Framework\Model\Resource\Iterator',
120+
['walk'],
121+
[],
122+
'',
123+
false
124+
);
77125

78126
$this->objectManagerHelper = new ObjectManagerHelper($this);
79127
$this->rule = $this->objectManagerHelper->getObject(
80128
'Magento\CatalogRule\Model\Rule',
81129
[
82130
'storeManager' => $this->storeManager,
83-
'combineFactory' => $this->combineFactory
131+
'combineFactory' => $this->combineFactory,
132+
'ruleProductProcessor' => $this->_ruleProductProcessor,
133+
'productCollectionFactory' => $this->_productCollectionFactory,
134+
'resourceIterator' => $this->_resourceIterator,
84135
]
85136
);
86137
}
87138

88139
/**
89140
* @dataProvider dataProviderCallbackValidateProduct
90141
* @param bool $validate
142+
*
143+
* @return void
91144
*/
92145
public function testCallbackValidateProduct($validate)
93146
{
@@ -134,11 +187,43 @@ public function testCallbackValidateProduct($validate)
134187
}
135188
}
136189

190+
/**
191+
* Data provider for callbackValidateProduct test
192+
*
193+
* @return array
194+
*/
137195
public function dataProviderCallbackValidateProduct()
138196
{
139197
return [
140198
[false],
141199
[true],
142200
];
143201
}
202+
203+
/**
204+
* Test after delete action
205+
*
206+
* @return void
207+
*/
208+
public function testAfterDelete()
209+
{
210+
$indexer = $this->getMock('\Magento\Indexer\Model\IndexerInterface');
211+
$indexer->expects($this->once())->method('invalidate');
212+
$this->_ruleProductProcessor->expects($this->once())->method('getIndexer')->will($this->returnValue($indexer));
213+
$this->rule->afterDelete();
214+
}
215+
216+
/**
217+
* Test after update action
218+
*
219+
* @return void
220+
*/
221+
public function testAfterUpdate()
222+
{
223+
$this->rule->isObjectNew(false);
224+
$indexer = $this->getMock('\Magento\Indexer\Model\IndexerInterface');
225+
$indexer->expects($this->once())->method('invalidate');
226+
$this->_ruleProductProcessor->expects($this->once())->method('getIndexer')->will($this->returnValue($indexer));
227+
$this->rule->afterSave();
228+
}
144229
}

app/design/frontend/Magento/blank/Magento_Catalog/web/css/source/_module.less

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,13 @@
210210
.product-reviews-summary .reviews-actions {
211211
.font-size(@font-size__base);
212212
}
213+
.product-options-wrapper {
214+
.field {
215+
.note {
216+
display: block;
217+
}
218+
}
219+
}
213220
}
214221

215222
.product-info-main,

app/design/frontend/Magento/blank/Magento_CatalogSearch/web/css/source/_module.less

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
display: none;
2323
}
2424
}
25+
.block-content {
26+
margin-bottom: 0;
27+
}
2528
.label {
2629
.icon-font(
2730
@_icon-font-content: @icon-search,

app/design/frontend/Magento/blank/web/css/source/_forms.less

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ select:focus ~ .tooltip .tooltip-content {
9292
margin: 0;
9393
> .field:not(.choice) >,
9494
.fields > .field {
95-
margin: 0 0 @form-field__vertical-indent;
95+
&:not(:last-child) {
96+
margin: 0 0 @form-field__vertical-indent;
97+
}
9698
.label {
9799
margin: 0 0 4px;
98100
padding: 0 0 @indent__xs;

app/design/frontend/Magento/luma/Magento_Catalog/web/css/source/_module.less

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,14 @@
249249
margin-top: @form-field__vertical-indent;
250250
}
251251
}
252+
.product-options-wrapper {
253+
.field {
254+
.note {
255+
display: block;
256+
.css(margin-top, @indent__xs);
257+
}
258+
}
259+
}
252260
}
253261

254262
.product-options-bottom .price-box,

0 commit comments

Comments
 (0)