Hi there
I am trying to create my own custom sales report which collates together a list of all items sold. I have the following code, which is a collection of invoices:
$collection = Mage::getModel('sales/order_invoice')->getCollection() ->addAttributeToFilter('created_at', array('from'=>$collection_date_start, 'to'=>$collection_date_end)); foreach($collection as $invoice){ foreach ($invoice->getAllItems() as $item) { $item["product_id"]; $item->getProductId(); } }
You will notice a have a few variations of obtaining the product ID. My issue is that when the product is configurable, the configurable product ID is given (and not the child product ID). The Qty and SKU are the child product, but not the product ID (which I need to retrieve product attributes of the child product).
How can I get the underlying child product ID from this code, without using "Mage::getModel('catalog/product')->load()" (which would very quickly exhaust memory limits since it would run on all items sold within a quarter)?
A few notes:
Thanks!
M.
Hi @Marked13,
I guess you should check items into the Order and not only into the Invoice.
The order items table has that kind of information (you can ask for products with parent_item_id. Rows with values on that row are simple or virtual products and when the column is empty the item is a complex product type.