Magento 2:如何在成功页面之前的访客结帐中获取订单 ID?

Magento 2 : How to get order id in guest checkout before success page?

我正在使用 Magento 2.1.3。我想在成功页面之前的访客结帐中获取订单 ID。我在 google 上搜索并找到了一些这样的代码。

$orderIncrementId = $this->checkoutSession->getLastRealOrderId();

使用 chcekout seesion \Magento\Checkout\Model\Session 对象,我尝试获取订单 ID 但它不起作用。 在 magento 1.x 中,我们可以使用相同的方法轻松地从结帐会话中获取订单 ID。在 magento 2.x 中我们无法做到这一点。

在 magento 中 2.x 如何在成功页面之前的访客结帐中获取订单 ID?

如有任何帮助,我们将不胜感激。

谢谢

试试这些代码行:

$this->checkoutSession->getQuote()->reserveOrderId();
$reservedOrderId = $this->checkoutSession->getQuote()->getReservedOrderId();
$this->_checkoutSession->getQuote()->reserveOrderId();
$order = $this->_checkoutSession->getQuote()->getReservedOrderId();