Skip to main content

Accessing custom options of an order in Magento via PHP


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.


Source: Tips4allCCNA FINAL EXAM

Comments

  1. matt (OP) already self-answered the question.

    Quote:



    EDIT: Found it!

    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.



    Note: It's absolutely OK to self-answer your own question. Please just post it as an real answer, but not in a question or comment. Posting as real answer helps to keep the "Unanswered" list more clear (avoids making other people wasting their time). Thank you.

    ReplyDelete

Post a Comment

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?