質問

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?

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません magento.stackexchange
scroll top