php 在 Magento 中获取 status = 'Complete' 的订单 ID
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8309289/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get order ids with status = 'Complete' in Magento
提问by ivn
I am working on getting order ids and other details for orders with status ='complete' in Magento. I am sure there is a way in magento where we can retrieve all orders with status as Complete. Since I am a new-bie to magento I am finding it hard to work this out.
我正在努力获取 Magento 中状态为“完成”的订单的订单 ID 和其他详细信息。我确信在 magento 中有一种方法可以让我们检索状态为 Complete 的所有订单。由于我是 magento 的新手,我发现很难解决这个问题。
I would like to send the customers with order status as Complete an email and mark them once an email is sent. But thats the later part of it. Can any one tell me how in magento can you get all order id's with status as Complete ?
我想向订单状态为“完成”的客户发送一封电子邮件,并在发送电子邮件后标记他们。但那是它的后半部分。谁能告诉我如何在 magento 中获得所有状态为 Complete 的订单 ID?
Any help is appreciated. Thanks in advance.
任何帮助表示赞赏。提前致谢。
回答by Max
This can be run as a script from the base Magento install folder. If its running inside of a Magento file already (controller or block or whatever) you don't need the first three lines.
这可以作为基本 Magento 安装文件夹中的脚本运行。如果它已经在 Magento 文件中运行(控制器或块或其他),则不需要前三行。
<?php
require_once('app/Mage.php');
Mage::app();
$orders = Mage::getModel('sales/order')->getCollection()
->addFieldToFilter('status', 'complete')
->addAttributeToSelect('customer_email')
;
foreach ($orders as $order) {
$email = $order->getCustomerEmail();
echo $email . "\n";
}
EDIT:
编辑:
To see allorders with statuses and emails:
要查看所有带有状态和电子邮件的订单:
$orders = Mage::getModel('sales/order')->getCollection()
//->addFieldToFilter('status', 'complete')
->addAttributeToSelect('customer_email')
->addAttributeToSelect('status')
;
foreach ($orders as $order) {
$email = $order->getCustomerEmail();
echo $order->getId() . ": '" . $order->getStatus() . "', " . $email . "\n";
}
回答by Ashwin Shahi
To Get All the Products with order status as 'Completed'
获取订单状态为“已完成”的所有产品
$orders = Mage::getResourceModel('sales/order_collection')
->addFieldToSelect('*')
->addFieldToFilter('customer_id', Mage::getSingleton('customer/session')->getCustomer()->getId())
->addFieldToFilter('state', array('in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()))
->addFieldToFilter('status', 'complete')
->setOrder('created_at', 'desc');
$this->setOrders($orders);
foreach ($orders as $order)
{
$order_id=$order->getRealOrderId();
$order = Mage::getModel('sales/order')->load($order_id, 'increment_id');
$order->getAllVisibleItems();
$orderItems = $order->getItemsCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('product_type', array('eq'=>'simple'))
->load();
foreach($orderItems as $Item)
{
$Item = Mage::getModel('catalog/product')->setStoreId($Item->getStoreId())->load($Item->getProductId());
if ($Item->getId())
{
echo $Item->getName();
echo $Item->getPrice();
echo $Item->getProductUrl();
echo $Item->getImageUrl();
}
}
}
?>