我正在使用集合在 Magento 中手动构建报告,并且我正在尝试使用订单完成日期而不是订单创建日期。
我当前的代码是:
$orders = Mage::getModel('sales/order')->getCollection()
->addAttributeToFilter('created_at', array('from'=>$fromDate, 'to'=>$toDate))
->addAttributeToFilter('status', array('eq' => Mage_Sales_Model_Order::STATE_COMPLETE))
->addAttributeToFilter('store_id', array('eq' => 2));
我发现了以下问题,其中用户建议手动记录每个订单的所有状态更改。
Finding out when an order status has been set to completed
因为我想在集合中使用它,所以我认为这不是合适的方式,而且我有点希望可以在 Magento 中访问此类信息。
谢谢,
最佳答案
您可以检索订单状态历史更新的集合:
$collection = Mage::getResourceModel('sales/order_status_history_collection')
->addAttributeToSelect('created_at', 'parent_id')
->addAttributeToFilter('status', array('eq'=>'complete'))
->load();
之后您可以迭代 $collection 并提取您想要的信息的 parent_id 和 created_at。
关于php - 如何在 Magento 中获取订单的完成日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18128750/