Get order ids with status = 'Complete' in Magento

前端 未结 2 1113
青春惊慌失措
青春惊慌失措 2021-02-14 10:08

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 st

相关标签:
2条回答
  • 2021-02-14 10:57

    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.

    <?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 all orders 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";
    }
    
    0 讨论(0)
  • 2021-02-14 11:02

    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();
            }
        }
    }
    ?>
    
    0 讨论(0)
提交回复
热议问题