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

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...