AJK
AJK

Reputation: 435

Magento: Get Fixed Bundle Line item Prices from Order

I'm using Magento 1.8.x CE for now and I'm trying to grab the line item pricing for the options on a fixed bundle:

enter image description here

Here's my current code that I'm using just for testing:

$orderId = 18562;
$order = Mage::getModel('sales/order')->load($orderId);

foreach ($order->getAllItems() as $item){ 
    echo $item->getPrice() . "<br>";
}

This is the output I get from that:

399.9900
0.0000
0.0000

Any idea how I can get the line item prices from a Fixed Bundle order?

Upvotes: 1

Views: 1025

Answers (1)

AJK
AJK

Reputation: 435

Found the answer, not sure if it's best practice but it is working to get all simple product prices from an order (including from Fixed Bundles)

foreach ($order->getAllItems() as $item){

    /* Simple Product */
    if(($item->getProduct()->getTypeID() == 'simple') && !$item->getParentItemId()){        
        $prices[] += $item->getPrice();
    }

    /* Bundle (Fixed & Dynamic) Products */
    if($item->getProduct()->getTypeID() == 'bundle'){
        $items = $item->getProductOptions();    
        $options = $items['bundle_options'];

        foreach ($options as $option) {             
            $price = $option['value'][0]['price'];      
            $prices[] = number_format((float)$price, 2, '.', '');
        }
    }   
}

echo '"' . implode($prices,', ') . '"';

This outputs the example in the original question like this:

"349.99, 50.00"

Upvotes: 2

Related Questions