Frage

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?

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit magento.stackexchange
scroll top