Is it possible to put orders which been clicked in cancel from admin and do a check if the check fails keep it as pending

  • First of all you cannot change canceled order to pending order, but you can reorder which already been canceled. Please let me know. – Nits Nov 28 '19 at 7:20

Yes it is possible, but you need to do it programmatically

Create a helper in any of your module


And use following code:


namespace Vendor\Module\Helper;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper;
use Magento\Sales\Model\Order;
use Magento\CatalogInventory\Model\Indexer\Stock\Processor as StockProcessor;
class Data extends AbstractHelper
     * @var \Magento\CatalogInventory\Api\StockManagementInterface
    protected $stockManagement;
     * @var StockProcessor
    protected $stockIndexerProcessor;

    public function __construct(
        Helper\Context $context,
        \Magento\CatalogInventory\Api\StockManagementInterface $stockManagement,
        StockProcessor $stockIndexerProcessor

    public function uncancleorder($order, $comment = "")
            throw new \Magento\Framework\Exception\LocalizedException(__('Invalid Order'));

        if ($order->isCanceled()) {
            $state = "new";
            $productStockQty = [];
            foreach ($order->getAllVisibleItems() as $item) {
                $productStockQty[$item->getProductId()] = $item->getQtyCanceled();
                foreach ($item->getChildrenItems() as $child) {
                    $productStockQty[$child->getProductId()] = $item->getQtyCanceled();

            if (!empty($comment)) {
                $order->addStatusHistoryComment($comment, false);

            /* Reverting inventory */
            $itemsForReindex = $this->stockManagement->registerProductsSale(
            $productIds = [];
            foreach ($itemsForReindex as $item) {
                $productIds[] = $item->getProductId();
            if (!empty($productIds)) {


        } else {
            throw new \Magento\Framework\Exception\LocalizedException(__('We cannot un-cancel this order.'));
        return true;

Note: Edit this helper according to your requirements.

Now call uncancel method anywhere, just pass order object and comment(if required)

Reference module: https://github.com/Genmato/M2_UnCancelOrder

| improve this answer | |

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.