Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing custom options of an order in Magento via PHP

Tags:

php

magento

I'm loading an order like this:

$order = Mage::getModel('sales/order')->load(2886);
$items = $order->getAllItems();

Then I use a foreach loop:

foreach ($items as $itemId => $item){
    $name[] = $item->getName();
    $unitPrice[]=$item->getPrice();
    $sku[]=$item->getSku();
    $ids[]=$item->getProductId();
    $qty[]=$item->getQtyToInvoice();
}

And I am able to get most of the data I need. However, I'm having problems getting the custom options that were selected for the order. I can see the data in a var dump, but I have had no success in mining it out. I've also tried a handful of built in functions that I found via google, but no luck.

like image 292
matt Avatar asked Oct 26 '11 04:10

matt


2 Answers

matt (OP) already self-answered the question.

Quote:


I was able to get what I needed by using:

$opts = $item->getProductOptions();

Within my foreach loop. A var_dump on that shows how to access the data easily.

like image 146
3 revs, 2 users 84% Avatar answered Nov 05 '22 07:11

3 revs, 2 users 84%


As Nuno Furtado stated above, this returns nothing in Magento 1.8+.

My solution was:

$opts=$item->getData('product_options');
$opts=unserialize($opts);
print_r($opts);
like image 2
DjHexy Avatar answered Nov 05 '22 05:11

DjHexy