Amber
Amber

Reputation: 97

How do I get the options for bundled products on the success page?

On the success page, I have no trouble getting a list of the products purchased with the following code:

$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
foreach ($order->getAllItems() as $item){
   $subtotal = number_format($item->getSubtotal(),2);
}

What I can't figure out, is how to get an object or an array of the options for bundled products. These are standard options like what color a product is.

Upvotes: 3

Views: 3106

Answers (1)

Toby Hemmerling
Toby Hemmerling

Reputation: 569

I have not specifically tried this with bundled products, but the code below works with configurable products, and I'm sure you can modify it as needed to fit your situation.

$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
foreach ($order->getAllItems() as $item){
  $productOptions = $item->getProductOptions();
    if (isset($productOptions['attributes_info'])) {
      foreach ($productOptions['attributes_info'] as $productOption) {
        echo $label = $productOption['label']; 
        echo '<br />'; 
        echo $value = $productOption['value'];  
    }  
  }
}

My suggestion is to start broad (i.e. at the $item level), see what Magento returns (using Zend_Debug::dump($item->getData()), and then work your way down to what you need.

Hope that helps.

Upvotes: 6

Related Questions