0
votes

i am trying to get customer's sku through product id but m not able to get it till now. i have tried a code which brings the sku but it does not bring all products which a customer has purchased

// Create order collection object $orders = Mage::getResourceModel('sales/order_collection')->addFieldToSelect('*')->addFieldToFilter('customer_id', $custId);

          $order_id= $orders->getFirstItem()->getId();
            $order = Mage::getModel('sales/order')->load($order_id);

                $items = $order->getAllItems();
                $itemcount=count($items);
                $name=array();
                $unitPrice=array();
                $sku=array();
                $ids=array();
                $qty=array();
        foreach ($items as $itemId => $item)
             {
                echo"<h5>You have following:". $name[] = $item->getName()."</h5>";
                $unitPrice[]=$item->getPrice();
                echo"<h5>SKU of your Products:" .$sku[]=$item->getSku()."</h5>";
                echo"<h5>You have following:".$ids[]=$item->getProductId()."</h5>";
                echo"<h5>You have following:".$qty[]=$item->getQtyToInvoice()."</h5>";
             }              


    echo "<h4>Payment Details :</h4>";  



   }

?>

`

1
Your code is working. Can you print the other attributes (name, qty, id)? Check for typos etc.enenen
yup i know its working bt if u placed some orders as you can it won't give all products and its sku. try to checkout with 4 or 5 products and see the outputsantosh bawari
It's working. It should print all products from customer's first order.enenen
bt it is not i have 3 items in my first order and it is displaying only 2.it is not displaying 3rd one. and if i want to show all order products items then can you let me know the changes i have to do.santosh bawari
Maybe you changed something on your product - maybe disabled/deleted it? If it shows 2 products it should show all of them. I tried with order with 14 products, it works.enenen

1 Answers

0
votes

As per above code you are not iterating the orders which customer has purchased. You are only getting the product for a single order. I think that if you will iterate orders as well, so you will be able to get all the products which customer has purchased.