Get Value from sales_flat_invoice_item Table – Magento Database

database

How to get sku from sales_flat_invoice_item table?
Which model is use for this table?

Best Answer

If you have the order item id, then the sku for the order item should be the same as the sku for the invoice item. so you don't need to go to the invoice items table to get it.

$itemId = 100;
$item = Mage::getModel('sales/order_item')->load($itemId);
$sku = $item->getSku();

but if you insist on getting it from the invoice item table do this:

$collection = Mage::getModel('sales/order_invoice_item')->getCollection()
    ->addFieldToFilter('order_item_id', $itemId);

$invoiceItem = $collection->getFirstItem();
if ($invoiceItem->getId()) {
    $sku = $invoiceItem->getSku();
}
else {
    //the invoice item does not exist
}
Related Topic