gpt4 book ai didi

php - 如何从 Magento 2.3 中的最后一个订单中检索信息

转载 作者:行者123 更新时间:2023-11-30 21:30:34 27 4
gpt4 key购买 nike

我想从客户端在 magento 2.3 中发出的最后一个请求中获取信息

在编辑 success.phtml 页面时,您需要向我显示一些有关完成请求的信息,如请求的总值和地址,我看了一些教程,说它们可以使用下面的脚本。

$status = Mage::getModel('sales/order')->getCollection()
->setOrder('entity_id', Varien_Data_Collection::SORT_ORDER_DESC)
->getFirstItem()
->getPrice();

代码未检索任何信息。

最佳答案

我建议您使用Observer,拦截刚刚购买的订单数据,然后您可以使用订单数据实现所需的功能。

事件.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">

<event name="checkout_submit_all_after">
<observer name="yourcompany_yourmodule_checkout_submit_all_after" instance="YourCompany\YourModule\Observer\ProcessOrder" />
</event>

</config>

和观察者

public function execute(\Magento\Framework\Event\Observer $observer)
{
$order = $observer->getOrder();
$quote = $observer->getQuote();
// Do whatever you want here
return $this;
}

关于php - 如何从 Magento 2.3 中的最后一个订单中检索信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56460791/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com