1

i want to get all data (order_id , Bill to Name , ship to Name , BaseGrandTotal , GrandTotal ,Status ) about order with the known of product ids

Here is the sample of my code

    $ids=array();
    foreach ($collection as $product) { 
        $ids[]=$product->getId();
    }
    $collection = Mage::getResourceModel('sales/order_item_collection')
                ->addAttributeToFilter('product_id', array('in' => $ids))
                ->load();

1 Answer 1

1
$productId = 12735;
$collection = Mage::getResourceModel('sales/order_item_collection')
    ->addAttributeToFilter('product_id', array('eq' => $productId))
    ->load();

$order_ids = $collection->getColumnValues('order_id');

foreach($order_ids as $order_id){
    $order = Mage::getModel('sales/order')->load($order_id);    
    echo $order->getId(); // order id
    echo $order->getBillingAddress()->getFirstname().' '.$order->getBillingAddress()->getLastname(); 
    echo $order->getBillingAddress()->getFirstname().' '.$order->getBillingAddress()->getLastname(); 
    echo $order->getBaseGrandTotal(); // BaseGrandTotal
    echo $order->getGrandTotal(); // GrandTotal
    echo $order->getStatus(); // Status
}

if you need still more information about order use the following code

echo "<pre>"; print_r($order->getData());

if you need still more information about order billing data use the following code

echo "<pre>"; print_r($order->getBillingAddress()->getData());

if you need still more information about order shipping data use the following code

echo "<pre>"; print_r($order->getShippingAddress()->getData());
9
  • i have this is error Call to a member function getName() $order->getBillingAddress()->getName(); ` Jun 23, 2016 at 10:05
  • show your code... Jun 23, 2016 at 10:07
  • $collection = Mage::getResourceModel('sales/order_item_collection') ->addAttributeToFilter('product_id', array('in' => $ids)) ->load(); var_dump($collection); die; $order_ids = $collection->getColumnValues('order_id'); foreach ($order_ids as $order){ $order = Mage::getModel('sales/order')->load($order_id); echo $order->getBillingAddress()->getName(); } Jun 23, 2016 at 10:09
  • try using echo $order->getBillingAddress()->getFirstname().$order->getBillingAddress()->getLastname(); Jun 23, 2016 at 10:13
  • see my updated answer Jun 23, 2016 at 10:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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