Bhaveshpp

Professional Magento Developr - Healp eachother to grow

Magento2 How to load order by increment id

27 May 2021 » magento2, order
namespace Bhaveshpp\Custom\ViewModel;

use Magento\Sales\Api\Data\OrderInterfaceFactory;

class OrderPendingMessage implements \Magento\Framework\View\Element\Block\ArgumentInterface
{

    protected $orderFactory;

    public function __construct(
        OrderInterfaceFactory $orderFactory
    ) {
        $this->orderFactory = $orderFactory;
    }

    public function hasPendingStatus($orderId)
    {
        $order = $this->getOrder($orderId);
        $status =  $order->getStatus();
        $payment = $order->getPayment();
        $method = $payment->getMethodInstance();
        $methodCode = $method->getCode();
        if (($status == "pending")&&(strpos($methodCode,"monetico"))) {
            return true;   
        }
        return false;   
    }

    public function getOrder($id)
    {
        return $this->orderFactory->Create()->loadByIncrementId($id);
    }
}