Magento2 Cart – Retrieve Custom Attributes from Order Item

cartquote

I've added some 'on-the-fly' custom attributes to the quote item, as explained in this post.

What I'm trying to do is grab the value of these custom attributes in an observer triggering on checkout_onepage_controller_success_action

I've got the order item objects via the following method:

$orderIds = $observer->getEvent()->getOrderIds();
foreach($orderIds as $eachOrderId) {
    $order = Mage::getModel('sales/order')->load($eachOrderId);
    $items = $order->getAllVisibleItems();
    foreach($items as $item)
    {
        //Here are the methods I've used to get the custom attributes below

        //The below works to get an array of product options, but it gets output like this**
        //The custom attributes are in there somewhere though, so I know the information
        //is available, just how to get it?
        $item['product_options']

        //The below doesn't work, $options is a non-object
        $helper = Mage::helper('catalog/product_configuration');
        $options = $helper->getCustomOptions($item);
        if ($options) {
            foreach ($options as $key => $value)
            {
            }
        }

        //The below doesn't work, $options is a non-object
        $optionsArr = $item->getProductOptions();
        if(count($optionsArr['options']) > 0)
        { }
    }
}


**
a:6:{
    s:15:"info_buyRequest";
    a:5:{
        s:4:"uenc";
        s:88:"aHR0cDovL3RhbGtpbmd0b20ubWVyRTHSDF546747J7887HG0UG64X3Byb2R1Y3Qvdmlldy9pZC8yOS8,";
        s:7:"product";
        s:2:"29";
        s:7:"options";
        a:2:{
            s:4:"Logo";
            s:8:"img1.jpg";
            s:5:"Quote";
            s:8:"img2.jpg";
        }
        s:15:"super_attribute";
        a:2:{
            i:141;
            s:1:"9";
            i:152;
            s:2:"18";
        }
        s:3:"qty";
        i:1;
    }
    s:15:"attributes_info";
    a:2:{
        i:0;
        a:2:{
            s:5:"label";
            s:4:"Size";
            s:5:"value";
            s:5:"Large";
        }
        i:1;
        a:2:{
            s:5:"label";
            s:6:"Colour";
            s:5:"value";
            s:3:"Red";
        }
    }
    s:11:"simple_name";
    s:22:"Flower Red Large";
    s:10:"simple_sku";
    s:7:"4t5454t";
    s:20:"product_calculations";
    i:1;
    s:13:"shipment_type";
    i:0;
}

Attributes I'm after here are:

s:4:"Logo";
s:8:"img1.jpg";
s:5:"Quote";
s:8:"img2.jpg";

Best Answer

I wasn't far off. To get the custom attributes I used this in the observer:

$prodOptions = $item->getProductOptions();
$addOptions = $prodOptions['additional_options'];