Magento:第一个订单后increment_id为空

发布于 2024-12-15 13:57:14 字数 614 浏览 9 评论 0原文

我需要订单中的增量 ID 在我的服务器上创建一个文件夹,以便在客户成功订购商品后将一些特定于订单的文件移动到那里。这就是我到目前为止所得到的:

$chkoutSess = Mage::getSingleton('checkout/session');
$lastOrderId = $chkoutSess->getLastOrderId();
$order = Mage::getModel('sales/order');
$order->load($lastOrderId);
$incid = $order->getData("increment_id");

我想这可以更容易地完成,但它对我有用。我遇到的问题是,当我“第一次”订购某些东西时,$order 完全是空的。此后它总是有效。所以我认为我只能在存在实际会话时从会话对象中获取这些数据......这当然是毫无意义的,因为当客户订购东西时应该始终有一个“lastOrderId”。有没有其他方法可以简单地获取最后一个订单并将其从数据库中递增?我尝试了几件事,但对象总是空的。

我使用的函数是在用户成功点击订单提交按钮(事件观察者“sales_order_place_after”)后立即执行的。任何人都可以帮我解决这个问题吗?

I need the increment id from an order to create a folder on my server for moving some order specific files there, after a customer has successfully ordered something. This is what I've got so far:

$chkoutSess = Mage::getSingleton('checkout/session');
$lastOrderId = $chkoutSess->getLastOrderId();
$order = Mage::getModel('sales/order');
$order->load($lastOrderId);
$incid = $order->getData("increment_id");

I guess this can be done much easier but it works for me. The problem I have with this is that the $order is totally empty when I order something "the first time". After this it always works. So I think I can only get this data out of a session object when there's an actual session...this of course is senseless because there should always be a "lastOrderId" when a customer orders something. Is there any other way to simply get the last order and it's incremented out of the database? I tried several things but the objects where always empty..

The function I use is executed right after the user successfully hits the order submit button (event observer "sales_order_place_after"). Anyone can help me with this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悲喜皆因你 2024-12-22 13:57:14

尝试 $chkoutSess->getRealOrderId(); 而不是 $chkoutSess->getLastOrderId();

Try $chkoutSess->getRealOrderId(); and not $chkoutSess->getLastOrderId();

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文