Get Simple Products Ordered from a Quote When Configurable Products Are Purchased in Magento 1.7

event-observermagento-1.7ordersquote

I have an observer attached to sales_order_place_before and from that event I am getting the order items using

   $event = $observer->getEvent();
   $order = $event->getOrder();
   $items = $order->getQuote()->getAllItems();

When I log these items in a foreach like so I get double the amount of products. That is, I get the configurable AND the simple product

foreach($items as $item){
            $product = $item;
            $sku = $product->getSku();
            $name = $product->getName();
}

If I change the $items call to be $items = $order->getQuote()->getAllVisibleItems(); then I can get just the configurable products, but I want to get just the simple products.

My question is, how can I get just the simple products from the order.

Best Answer

I think there is no direct method to exclude the configurables, since the logic in Magento is that the configurable is the "main" product where the price is at. The associated simple product might have a wrong price configured. In any case, if you want to still get these items and not the configurables, your best bet is to use the getAllItems() method and then afterwards kick out the configurables:

 $event = $observer->getEvent();
 $order = $event->getOrder();
 $items = $order->getQuote()->getAllItems();
 $itemsExcludingConfigurables = array();
 foreach ($items as $item) {
    if ($item->getTypeId() != 'configurable') {
       $itemsExcludingConfigurables[] = $item;
    }
 }