0

I installed an extension which works fine on previous versions of Magento 2.2 but does not work on latest versions (e.g. Magento 2.2).

In that extension, they use following code in model to get current order:

$order = $this->_saleCollection->create()->getLastItem();

where _saleCollection is an instance of \Magento\Sales\Model\ResourceModel\Order\CollectionFactory.

I debugged this code and found that getLastItem() is causing problem. Could you guys please suggest me why Magento 2.2 is not properly executing this code and suggest some alternate solution?

This line of code actually runs in several locations:

  1. When customer places an order.
  2. When admin opens any order and clicks "send email".

In both scenarios $order contains current instance of order.

1 Answer 1

0

Try this

 $this->_checkoutSession->getQuote()->reserveOrderId();
 $order = $this->_checkoutSession->getQuote()->getReservedOrderId();
1
  • It does not return correct order id.
    – umair ayub
    Commented Mar 8, 2018 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.