1

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";

  • Please define $eachOrderId – user2045 Jun 6 '14 at 17:09
  • @user2045 Yes, my mistake. Amended, thank you. – user2565123 Jun 8 '14 at 10:09
  • Can anybody help? – user2565123 Jun 9 '14 at 10:12
0

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

$prodOptions = $item->getProductOptions();
$addOptions = $prodOptions['additional_options'];
  • If you solved the problem this way, this is fine. I also used this some times and it solved my problem. However, these are not custom attributes, you know. These are just "additional options" that you attached to the product (or order item? I am not sure). To make proper custom attributes, I think you would have to design more tables using the sql upgrade scripts. – Vladimir Despotovic Oct 11 '17 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.