Get Order Increment Id in Magento(在 Magento 中获取订单增量 ID)
问题描述
我正在尝试在 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Magento 中获取订单增量 ID


- PHP foreach() 与数组中的数组? 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- PHP - if 语句中的倒序 2021-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01