3

How can we write the below code lines in Magento 2.2.5 controller and model?

$order = Mage::getModel('sales/order')
            ->getCollection()
            ->addFieldToFilter('quote_id', $quote->getId())
            ->getFirstItem();
0

Try the below code in your controller or Model:

protected $_orderInterface;
public function __construct(
    \Magento\Sales\Api\Data\OrderInterface $orderInterface,
    .....
){
    .....
    $this->_orderInterface = $orderInterface;
    .....
}

public function getOrder($quoteId){
    return $this->_orderInterface->load($quoteId, 'quote_id');
}

Then run di compile and other required commands and test.

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.