Skip to content

Commit 1137831

Browse files
AnshuMishra17rostyslav-hymon
authored andcommitted
Refactor Code for Mass Order Unhold
I have observed that MassAction Unhold is using the collection to release order from hold, whereas MassAction Hold is using Interface to put the order on hold. So, I have refactor code in app/code/Magento/Sales/Controller/Adminhtml/Order/MassUnhold.php same as in app/code/Magento/Sales/Controller/Adminhtml/Order/MassHold.php
1 parent e6253f5 commit 1137831

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

app/code/Magento/Sales/Controller/Adminhtml/Order/MassUnhold.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,31 @@
99
use Magento\Backend\App\Action\Context;
1010
use Magento\Ui\Component\MassAction\Filter;
1111
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
12+
use Magento\Sales\Api\OrderManagementInterface;
1213

1314
class MassUnhold extends AbstractMassAction
1415
{
1516
/**
1617
* Authorization level of a basic admin session
1718
*/
1819
const ADMIN_RESOURCE = 'Magento_Sales::unhold';
20+
21+
/**
22+
* @var OrderManagementInterface
23+
*/
24+
protected $orderManagement;
1925

2026
/**
2127
* @param Context $context
2228
* @param Filter $filter
2329
* @param CollectionFactory $collectionFactory
30+
* @param OrderManagementInterface $orderManagement
2431
*/
25-
public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory)
32+
public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory, OrderManagementInterface $orderManagement)
2633
{
2734
parent::__construct($context, $filter);
2835
$this->collectionFactory = $collectionFactory;
36+
$this->orderManagement = $orderManagement;
2937
}
3038

3139
/**
@@ -40,12 +48,10 @@ protected function massAction(AbstractCollection $collection)
4048

4149
/** @var \Magento\Sales\Model\Order $order */
4250
foreach ($collection->getItems() as $order) {
43-
$order->load($order->getId());
4451
if (!$order->canUnhold()) {
4552
continue;
4653
}
47-
$order->unhold();
48-
$order->save();
54+
$this->orderManagement->unHold($order->getEntityId());
4955
$countUnHoldOrder++;
5056
}
5157

0 commit comments

Comments
 (0)