Skip to content

Commit cabd186

Browse files
committed
Merge pull request #468 from magento-goinc/MAGETWO-35251
[GoInc] Bugfix
2 parents 8892f35 + 1bd0597 commit cabd186

File tree

15 files changed

+244
-57
lines changed

15 files changed

+244
-57
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,69 @@
66
*/
77
namespace Magento\Catalog\Controller\Adminhtml\Product;
88

9+
use Magento\Catalog\Model\Resource\Product\Collection;
10+
use Magento\Framework\Controller\ResultFactory;
11+
912
class MassDelete extends \Magento\Catalog\Controller\Adminhtml\Product
1013
{
14+
/**
15+
* Field id
16+
*/
17+
const ID_FIELD = 'entity_id';
18+
19+
/**
20+
* Redirect url
21+
*/
22+
const REDIRECT_URL = 'catalog/*/index';
23+
24+
/**
25+
* Resource collection
26+
*
27+
* @var string
28+
*/
29+
protected $collection = 'Magento\Catalog\Model\Resource\Product\Collection';
30+
1131
/**
1232
* @return \Magento\Backend\Model\View\Result\Redirect
1333
*/
1434
public function execute()
1535
{
16-
$productIds = $this->getRequest()->getParam('selected');
17-
if (!is_array($productIds) || empty($productIds)) {
18-
$this->messageManager->addError(__('Please select product(s).'));
19-
} else {
20-
try {
21-
foreach ($productIds as $productId) {
22-
$product = $this->_objectManager->get('Magento\Catalog\Model\Product')->load($productId);
23-
$product->delete();
24-
}
25-
$this->messageManager->addSuccess(
26-
__('A total of %1 record(s) have been deleted.', count($productIds))
27-
);
28-
} catch (\Exception $e) {
29-
$this->messageManager->addError($e->getMessage());
36+
$selected = $this->getRequest()->getParam('selected');
37+
$excluded = $this->getRequest()->getParam('excluded');
38+
39+
$collection = $this->_objectManager->create($this->collection);
40+
try {
41+
if (!empty($excluded)) {
42+
$collection->addFieldToFilter(static::ID_FIELD, ['nin' => $excluded]);
43+
$this->massAction($collection);
44+
} elseif (!empty($selected)) {
45+
$collection->addFieldToFilter(static::ID_FIELD, ['in' => $selected]);
46+
$this->massAction($collection);
47+
} else {
48+
$this->messageManager->addError(__('Please select product(s).'));
3049
}
50+
} catch (\Exception $e) {
51+
$this->messageManager->addError($e->getMessage());
52+
}
53+
54+
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
55+
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
56+
return $resultRedirect->setPath(static::REDIRECT_URL);
57+
}
58+
59+
/**
60+
* Cancel selected orders
61+
*
62+
* @param Collection $collection
63+
* @return void
64+
*/
65+
protected function massAction($collection)
66+
{
67+
$count = 0;
68+
foreach ($collection->getItems() as $product) {
69+
$product->delete();
70+
++$count;
3171
}
32-
return $this->resultRedirectFactory->create()->setPath('catalog/*/index');
72+
$this->messageManager->addSuccess(__('A total of %1 record(s) have been deleted.', $count));
3373
}
3474
}
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+
namespace Magento\Catalog\Plugin\Model\Product\Action;
7+
8+
use Magento\Catalog\Model\Product;
9+
use Magento\Catalog\Model\Product\Action;
10+
use Magento\Indexer\Model\CacheContext;
11+
use Magento\Framework\Event\ManagerInterface as EventManager;
12+
13+
class UpdateAttributesFlushCache
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 Action $subject
39+
* @param \Closure $proceed
40+
* @param array $productIds
41+
* @param array $attrData
42+
* @param int $storeId
43+
* @return Action
44+
*
45+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
46+
*/
47+
public function aroundUpdateAttributes(
48+
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: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Test\Unit\Plugin\Model\Product\Action;
7+
8+
use Magento\Catalog\Model\Product;
9+
10+
class UpdateAttributesFlushCacheTest 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');
27+
$eventManagerMock->expects($this->once())
28+
->method('dispatch')
29+
->with('clean_cache_by_tags', ['object' => $cacheContextMock]);
30+
31+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
32+
$model = $objectManager->getObject(
33+
'Magento\Catalog\Plugin\Model\Product\Action\UpdateAttributesFlushCache',
34+
[
35+
'cacheContext' => $cacheContextMock,
36+
'eventManager' => $eventManagerMock,
37+
]
38+
);
39+
40+
$closureMock = function () use ($productActionMock) {
41+
return $productActionMock;
42+
};
43+
44+
$model->aroundUpdateAttributes($productActionMock, $closureMock, $productIds, $attrData, $storeId);
45+
}
46+
}

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\Plugin\Model\Product\Action\UpdateAttributesFlushCache"/>
81+
</type>
7982
</config>

app/code/Magento/Catalog/view/adminhtml/web/js/custom-options.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ define([
132132
at: 'center top',
133133
of: 'body'
134134
},
135+
create: function (event, ui) {
136+
$(document).on('click', '#productGrid_massaction-form button', function () {
137+
$('#import-custom-options-apply-button').trigger('click', 'massActionTrigger');
138+
});
139+
},
135140
open: function () {
136141
$(this).closest('.ui-dialog').addClass('ui-dialog-active');
137142

@@ -195,19 +200,14 @@ define([
195200
}]
196201
});
197202
importContainer.load(
198-
this.options.productGridUrl, {
199-
form_key: this.options.formKey
200-
},
203+
this.options.productGridUrl,
204+
{form_key: this.options.formKey},
201205
function () {
202206
importContainer.dialog('open');
203207
}
204208
);
205209
},
206210

207-
'click #productGrid_massaction-form button': function () {
208-
$('#import-custom-options-apply-button').trigger('click', 'massActionTrigger');
209-
},
210-
211211
/**
212212
* Change custom option type
213213
*/
@@ -470,4 +470,4 @@ define([
470470
}
471471
});
472472

473-
});
473+
});

app/code/Magento/Catalog/view/adminhtml/web/product/product.css

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,6 @@
280280
position: static;
281281
}
282282

283-
/* Change Attribute Set */
284-
.admin__scope-old #product_info_tabs li.removed,
285-
.admin__scope-old div.removed,
286-
.admin__scope-old .field.removed {
287-
display: none !important;
288-
}
289-
290283
/*
291284
Custom Options
292285
-------------------------------------- */

app/code/Magento/Catalog/view/base/web/js/price-box.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ define([
9797
'amount': 0,
9898
'adjustments': {}
9999
};
100-
additionalPrice[priceCode].amount = parseInt(additionalPrice[priceCode].amount || 0, 10)
100+
additionalPrice[priceCode].amount = 0 + (additionalPrice[priceCode].amount || 0)
101101
+ priceValue.amount;
102102
_.each(priceValue.adjustments, function (adValue, adCode) {
103-
additionalPrice[priceCode].adjustments[adCode] =
104-
parseInt(additionalPrice[priceCode].adjustments[adCode] || 0, 10) + adValue;
103+
additionalPrice[priceCode].adjustments[adCode] = 0
104+
+ (additionalPrice[priceCode].adjustments[adCode] || 0) + adValue;
105105
});
106106
});
107107
});
@@ -117,9 +117,9 @@ define([
117117
origin.adjustments = origin.adjustments || {};
118118
final.adjustments = final.adjustments || {};
119119

120-
final.amount = parseInt(origin.amount, 10) + option.amount;
120+
final.amount = 0 + origin.amount + option.amount;
121121
_.each(option.adjustments, function (pa, paCode) {
122-
final.adjustments[paCode] = parseInt(origin.adjustments[paCode] || 0, 10) + pa;
122+
final.adjustments[paCode] = 0 + (origin.adjustments[paCode] || 0) + pa;
123123
});
124124
}, this);
125125
}

app/code/Magento/Catalog/view/frontend/web/js/catalog-add-to-cart.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ define([
7474
$('body').trigger(self.options.processStop);
7575
}
7676

77-
if (res.redirect) {
78-
window.location = res.redirect;
77+
if (res.backUrl) {
78+
window.location = res.backUrl;
7979
return;
8080
}
8181
if (res.messages) {

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

Lines changed: 30 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,19 +54,36 @@ 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
5871
* @param \Magento\Catalog\Model\Product\Type $catalogProductType
72+
* @param \Magento\Indexer\Model\CacheContext $cacheContext
73+
* @param \Magento\Framework\Event\ManagerInterface $eventManager
5974
*/
6075
public function __construct(
6176
\Magento\Framework\App\Resource $resource,
6277
\Magento\CatalogInventory\Model\Resource\Indexer\StockFactory $indexerFactory,
63-
\Magento\Catalog\Model\Product\Type $catalogProductType
78+
\Magento\Catalog\Model\Product\Type $catalogProductType,
79+
\Magento\Indexer\Model\CacheContext $cacheContext,
80+
\Magento\Framework\Event\ManagerInterface $eventManager
6481
) {
6582
$this->_resource = $resource;
6683
$this->_indexerFactory = $indexerFactory;
6784
$this->_catalogProductType = $catalogProductType;
85+
$this->cacheContext = $cacheContext;
86+
$this->eventManager = $eventManager;
6887
}
6988

7089
/**
@@ -228,6 +247,16 @@ protected function _reindexRows($productIds = [])
228247
}
229248
}
230249

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

app/code/Magento/CatalogInventory/Test/Unit/Model/Indexer/Stock/Action/FullTest.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,23 @@ public function testExecuteWithAdapterErrorThrowsException()
2525
$adapterMock = $this->getMock('Magento\Framework\DB\Adapter\AdapterInterface');
2626

2727
$exceptionMessage = 'exception message';
28-
$exception = new \Exception($exceptionMessage);
2928

3029
$adapterMock->expects($this->once())
3130
->method('delete')
32-
->will($this->throwException($exception));
31+
->will($this->throwException(new \Exception($exceptionMessage)));
3332

3433
$resourceMock->expects($this->any())
3534
->method('getConnection')
3635
->will($this->returnValue($adapterMock));
3736

38-
$model = new \Magento\CatalogInventory\Model\Indexer\Stock\Action\Full(
39-
$resourceMock,
40-
$indexerFactoryMock,
41-
$productTypeMock
37+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
38+
$model = $objectManager->getObject(
39+
'Magento\CatalogInventory\Model\Indexer\Stock\Action\Full',
40+
[
41+
'resource' => $resourceMock,
42+
'indexerFactory' => $indexerFactoryMock,
43+
'catalogProductType' => $productTypeMock,
44+
]
4245
);
4346

4447
$this->setExpectedException('\Magento\Framework\Exception\LocalizedException', $exceptionMessage);

0 commit comments

Comments
 (0)