0

I want to get a list of products from only pending orders! i have this is code but works only for register customers i need to show product for all orders even for guests and multi store.

<?php
require_once 'app/Mage.php';
Mage::app();
//Get All Users/Customers
$users = mage::getModel('customer/customer')->getCollection()
   ->addAttributeToSelect('*');

foreach ($users as $user){
$customer_id = $user['entity_id'];

//Get the  all orders by customer id
$order_collection = Mage::getResourceModel('sales/order_collection')
    ->addFieldToSelect('*')
    ->addFieldToFilter('customer_id',$customer_id)
    ->addFieldToFilter('status', array('in' => array('pending')))
    ->setOrder('created_at', 'desc'); 

    foreach($order_collection as $orders) {
        echo $increment_id = $orders['increment_id']."</br>";
        $order_id = $orders['entity_id'];

        //Get all items for the order id
        $order = Mage::getModel('sales/order')->load($order_id);

        $items = $order->getAllItems();

        foreach($items as $i) {

              echo $i->getName()."</br>";
        }

        echo  "</br>";
    } 

}
?>
0

try below code. Guest customers don't have an ID. So it's better to remove customer condition.

<?php
require_once 'app/Mage.php';
Mage::app();
//Get All Users/Customers
//$users = mage::getModel('customer/customer')->getCollection()->addAttributeToSelect('*');

//foreach ($users as $user){
//$customer_id = $user['entity_id'];

//Get the  all orders by customer id
$order_collection = Mage::getResourceModel('sales/order_collection')
    ->addFieldToSelect('*')
    //->addFieldToFilter('customer_id',$customer_id)
    ->addFieldToFilter('status', array('in' => array('pending')))
    ->setOrder('created_at', 'desc'); 

    foreach($order_collection as $orders) {
        echo $increment_id = $orders['increment_id']."</br>";
        $order_id = $orders['entity_id'];

        //Get all items for the order id
        $order = Mage::getModel('sales/order')->load($order_id);

        $items = $order->getAllItems();

        foreach($items as $i) {

              echo $i->getName()."</br>";
        }

        echo  "</br>";
    } 

//}
?>
  • Hello the code is working tank you – GSM Boutique Oct 3 '18 at 21:09
  • i need to add custom attribute to table – GSM Boutique Oct 3 '18 at 21:10
  • Please post another question for it. and close this one – Abhishek Panchal Oct 3 '18 at 21:11
0

i need to add custom attribute text value to table how do i get the value ?

    <?php
require_once 'app/Mage.php';
Mage::app();

//Get All Users/Customers
  //  $users = mage::getModel('customer/customer')->getCollection()
 //     ->addAttributeToSelect('*');



//Get the  all orders by customer id
$order_collection = Mage::getResourceModel('sales/order_collection')
    ->addFieldToSelect('*')
   // ->addFieldToFilter('customer_id',$customer_id)
    ->addFieldToFilter('status', array('in' => array('pending')))
    ->setOrder('created_at', 'desc'); 
echo '<table><tr><th>Comanda</th><th>Produs</th><th>qty</th><th>SKU</th></tr>';
    foreach($order_collection as $orders) {
       // echo $increment_id = $orders['increment_id']."</br>";
        $order_id = $orders['entity_id'];

        //Get all items for the order id
        $order = Mage::getModel('sales/order')->load($order_id);

        $items = $order->getAllItems();


        foreach($items as $i) {

              echo '<tr>
              <td>'.$orders['increment_id'].'</td>
              <td>'.$i->getName().'</td>
              <td>'.$i->getQtyOrdered().'</td>
              <td>'.$i->getSku().'</td>
              <td>'.$i->getCod().'</td><tr>';
        } 
        } 
        echo '</tr></table>';
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.