skip to Main Content

Here I show how to get items from a Order by the order number id:

$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) {
    $name[] = $item->getName();
    $unitPrice[] = $item->getPrice();
    $sku[] = $item->getSku();
    $ids[] = $item->getProductId();
    $qty[] = $item->getQtyToInvoice();
}

How can I do the same but in SQL, get all the items information (name, price, image..) by order number id.

2

Answers


  1. // getSelect() method allowed for order collection only so you can print query for specific order as as below.

    $order_id = 12345;
    $orders = Mage::getResourceModel('sales/order_collection')
      ->addAttributeToSelect('*')
      ->addAttributeToFilter('entity_id', $order_id);
    echo $orders->getSelect();
    
    Login or Signup to reply.
  2. Use sql query like :

    This is for select item name and data

    select sales_flat_order.entity_id,sales_flat_order.increment_id,sales_flat_order_item.item_id, sales_flat_order_item.sku, sales_flat_order_item.name from sales_flat_order right join sales_flat_order_item on sales_flat_order.entity_id = sales_flat_order_item.order_id where increment_id = 100000042
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search