获取当前订单ID magento 2


8

我知道如何通过此代码检索上一个订单ID,

$this->_checkoutSession->getQuote()->getReservedOrderId();

通过注入获得_checkoutSession的地方,

\Magento\Checkout\Model\Session $checkoutSession

我想知道如何在magento 2中获取当前的订单ID。


您要在哪个地方获得当前的订单ID?
Nalin Savaliya

下订单后@Nalin。我观察到事件发生后下的订单。
Mrunmay Deswandikar

Answers:


10

下面的代码将为您提供最后的订单ID

protected $_checkoutSession;


public function __construct(
 .....
\Magento\Checkout\Model\Session $checkoutSession,

.....
) {

        $this->_checkoutSession = $checkoutSession;


    }

 $order = $this->_checkoutSession->getLastRealOrder();
 $orderId=$order->getEntityId();
 $order->getIncrementId();

参考


向我++ 1,以及如何获取由实体ID插入的增量ID?
Mrunmay Deswandikar

2
嗯... 我猜$ order-> getIncrementId()应该可以工作
magento noob

好吧,我将检查..
Mrunmay Deswandikar '17

1
@DishaSingh我更新的代码..
凯萨尔萨蒂
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.