Magento:第一个订单后increment_id为空
我需要订单中的增量 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
$chkoutSess->getRealOrderId();
而不是$chkoutSess->getLastOrderId();
Try
$chkoutSess->getRealOrderId();
and not$chkoutSess->getLastOrderId();