Skip to content

Commit 49a1f0b

Browse files
committed
Merge remote-tracking branch 'l3/ACP2E-635' into PR_L3_05_04_2022
2 parents 7051798 + 75e4252 commit 49a1f0b

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\Controller\ResultFactory;
1313
use Magento\Ui\Component\MassAction\Filter;
1414
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
15+
use Magento\Catalog\Helper\Product\Edit\Action\Attribute as AttributeHelper;
1516

1617
/**
1718
* Updates status for a batch of products.
@@ -41,27 +42,36 @@ class MassStatus extends \Magento\Catalog\Controller\Adminhtml\Product implement
4142
*/
4243
private $productAction;
4344

45+
/**
46+
* @var AttributeHelper
47+
*/
48+
private $attributeHelper;
49+
4450
/**
4551
* @param \Magento\Backend\App\Action\Context $context
4652
* @param Builder $productBuilder
4753
* @param \Magento\Catalog\Model\Indexer\Product\Price\Processor $productPriceIndexerProcessor
4854
* @param Filter $filter
4955
* @param CollectionFactory $collectionFactory
5056
* @param \Magento\Catalog\Model\Product\Action $productAction
57+
* @param AttributeHelper $attributeHelper
5158
*/
5259
public function __construct(
5360
\Magento\Backend\App\Action\Context $context,
5461
Product\Builder $productBuilder,
5562
\Magento\Catalog\Model\Indexer\Product\Price\Processor $productPriceIndexerProcessor,
5663
Filter $filter,
5764
CollectionFactory $collectionFactory,
58-
\Magento\Catalog\Model\Product\Action $productAction = null
65+
\Magento\Catalog\Model\Product\Action $productAction = null,
66+
AttributeHelper $attributeHelper = null
5967
) {
6068
$this->filter = $filter;
6169
$this->collectionFactory = $collectionFactory;
6270
$this->_productPriceIndexerProcessor = $productPriceIndexerProcessor;
6371
$this->productAction = $productAction ?: ObjectManager::getInstance()
6472
->get(\Magento\Catalog\Model\Product\Action::class);
73+
$this->attributeHelper = $attributeHelper ?: ObjectManager::getInstance()
74+
->get(AttributeHelper::class);
6575
parent::__construct($context, $productBuilder);
6676
}
6777

@@ -93,6 +103,7 @@ public function execute()
93103
{
94104
$collection = $this->filter->getCollection($this->collectionFactory->create());
95105
$productIds = $collection->getAllIds();
106+
$this->attributeHelper->setProductIds($productIds);
96107
$requestStoreId = $storeId = $this->getRequest()->getParam('store', null);
97108
$filterRequest = $this->getRequest()->getParam('filters', null);
98109
$status = (int) $this->getRequest()->getParam('status');

app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/MassStatusTest.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Magento\Framework\Data\Collection\AbstractDb;
2222
use Magento\Ui\Component\MassAction\Filter;
2323
use PHPUnit\Framework\MockObject\MockObject;
24+
use Magento\Catalog\Helper\Product\Edit\Action\Attribute as AttributeHelper;
2425

2526
/**
2627
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -57,6 +58,11 @@ class MassStatusTest extends ProductTest
5758
*/
5859
private $actionMock;
5960

61+
/**
62+
* @var AttributeHelper|MockObject
63+
*/
64+
private $attributeHelperMock;
65+
6066
protected function setUp(): void
6167
{
6268
$this->priceProcessorMock = $this->getMockBuilder(Processor::class)
@@ -104,6 +110,10 @@ protected function setUp(): void
104110
$this->actionMock = $this->getMockBuilder(Action::class)
105111
->disableOriginalConstructor()
106112
->getMock();
113+
$this->attributeHelperMock = $this->getMockBuilder(AttributeHelper::class)
114+
->disableOriginalConstructor()
115+
->setMethods(['setProductIds'])
116+
->getMock();
107117

108118
$collectionFactoryMock =
109119
$this->getMockBuilder(CollectionFactory::class)
@@ -126,7 +136,8 @@ protected function setUp(): void
126136
$this->priceProcessorMock,
127137
$this->filterMock,
128138
$collectionFactoryMock,
129-
$this->actionMock
139+
$this->actionMock,
140+
$this->attributeHelperMock
130141
);
131142
}
132143

@@ -137,13 +148,14 @@ public function testMassStatusAction()
137148
$filters = [
138149
'store_id' => 2,
139150
];
151+
$productIds = [3];
140152

141153
$this->filterMock->expects($this->once())
142154
->method('getCollection')
143155
->willReturn($this->abstractDbMock);
144156
$this->abstractDbMock->expects($this->once())
145157
->method('getAllIds')
146-
->willReturn([3]);
158+
->willReturn($productIds);
147159
$this->request->expects($this->exactly(3))
148160
->method('getParam')
149161
->willReturnMap(
@@ -153,9 +165,12 @@ public function testMassStatusAction()
153165
['filters', [], $filters]
154166
]
155167
);
168+
$this->attributeHelperMock->expects($this->once())
169+
->method('setProductIds')
170+
->with($productIds);
156171
$this->actionMock->expects($this->once())
157172
->method('updateAttributes')
158-
->with([3], ['status' => $status], 2);
173+
->with($productIds, ['status' => $status], 2);
159174
$this->priceProcessorMock->expects($this->once())
160175
->method('reindexList');
161176

0 commit comments

Comments
 (0)