問題描述
我正在嘗試在 Magento 中的 success.phtml 頁面上獲取訂單增量 ID,以便我可以將其用于會員跟蹤.
I'm trying to get the Order Increment Id in Magento, on the success.phtml page so that I can use this for affiliate tracking.
我正在使用以下代碼,但在第二行出現錯誤;
I'm using the following code, but it is giving an error on the second line;
$order = Mage::getSingleton('sales/order')->getLastOrderId();
$lastOrderId = $order->getIncrementId();
錯誤如下:
致命錯誤:在第 34 行調用非對象上的成員函數 getIncrementId():$LastOrderId = $order->getIncrementId();
Fatal error: Call to a member function getIncrementId() on a non-object on line 34: $LastOrderId = $order->getIncrementId();
我想知道是否有人對如何獲取訂單增量 ID 有任何想法?這是在管理員中看到的參考編號,通常類似于:#1000123
I was wondering if anyone has any ideas on how to get the Order Increment Id? This is the reference number seen in the admin, usually something like: #1000123
推薦答案
如果您專門在結帳成功頁面上執行此操作 - 在 success.phtml 中 - 那么獲取訂單增量 ID 的代碼已在模板中可用, 因為它是顯示給客戶的.
If you're specifically doing this on the checkout success page - in success.phtml - then the code to get the order increment ID is already available in the template, since it is displayed to the customer.
您只需要以下內容:
$orderId = $this->getOrderId();
請注意,這不適用于其他頁面,因此,對于那些頁面,您需要使用:
Note that this won't work on other pages so, for those, you'd need to use:
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
這篇關于在 Magento 中獲取訂單增量 ID的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!