0

I was working on something in Magento admin on order Management.

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.

Code in MassAction function in class Magento\Sales\Controller\Adminhtml\Order\MassUnhold

foreach ($collection->getItems() as $order) {
            $order->load($order->getId());
            if (!$order->canUnhold()) {
                continue;
            }
            $order->unhold();
            $order->save();
            $countUnHoldOrder++;
        }

Code in MassAction function in class Magento\Sales\Controller\Adminhtml\Order\MassHold

foreach ($collection->getItems() as $order) {
            if (!$order->canHold()) {
                continue;
            }
            $this->orderManagement->hold($order->getEntityId());
            $countHoldOrder++;
        }

Why there are two different approaches for a similar functionality?

2

My money is on "The mass unhold was not refactored yet".
THe order management interface has the methods hold and unHold that work the same way.
They retrieve the order object, call the hold / unhold method then use the repository to save the object.
Just for the fun of it, you can replace the code in the "unhold" mass action with the code from the "hold" mass action (changing hold to unhold obviously) and see if you get the same result.

3
  • I have checked after making the code for Unhold mass action similar to the hold mass action and it is working fine as expected. – Anshu Mishra Apr 10 '18 at 9:42
  • So, can we conclude that "The mass unhold was not refactored yet"? – Anshu Mishra Apr 10 '18 at 9:42
  • I cannot confirm this. It's just a speculation. – Marius Apr 10 '18 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.