How to get parameters for related products on the success page?

On the success page, it’s easy for me to get a list of 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);
}

I cannot figure out how to get an object or an array of parameters for related products. These are standard options such as product color.

+3
source share
1 answer

I have not specifically tried this with related products, but the code below works with custom products, and I am sure that you can change it as needed to suit 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 broadly (that is, at a level $item), see what Magento returns (using Zend_Debug::dump($item->getData()), and then work up to what you need.

Hope this helps.

+6

All Articles