I can load sales order via magento model like this:

$order = Mage::getModel('sales/order')->loadByIncrementId('200000025');

How do I get to the amazon values via the model?: Ref: http://support.m2epro.com/forums/138395-m2e-pro-amazon-magento-integration/suggestions/4965271-add-amazon-gift-wrapping-option-to-the-created-m


These were found in the m2epro_amazon_order_item table. enter image description here

I don't see these fields when I dump the order / each line data (using $model->getData()). How do I read the values from that table, for the current sales order object I am working with?


After some tinkering around, I believe I found where the data is, the corresponding model entity names etc... and put together the following:

// Load mage
require 'app/Mage.php';

// Load order
$order = Mage::getModel('sales/order')->loadByIncrementId('200000025');

// Init gift wrap list
$gift_wrapped = array();
foreach ($order->getAllItems() as $order_item)
    // Unserialize additional data
    $additional_data = isset($order_item['additional_data']) 
        ? unserialize($order_item['additional_data']) 
        : null;

    // Proceed if M2EPro extension is detected
    if ($additional_data &&
        isset($additional_data['m2epro_extension']['items']) &&
        // Iterate through each order item id
        foreach ($additional_data['m2epro_extension']['items'] as $data)
            // Anticipate errors
                // Load amazon order item row
                $amazon_order_item = Mage::getModel('M2ePro/Amazon_Order_Item')
                    ->load($data['order_item_id'], 'amazon_order_item_id');

                // Proceed if there is data
                if ($amazon_order_item->getId() && 
                    (float)$amazon_order_item->getGiftPrice() > 0)
                    // Append to list
                    $gift_wrapped[] = array
                        'Sku' => $order_item->getSku(),
                        'Price' => (float)$amazon_order_item->getGiftPrice(),
                        'Message' => $amazon_order_item->getGiftMessage()
            catch (Exception $ex) { }

This appears to be working, but I am not sure if there is a "better/proper" method than the one I posted above.

  • If this is the answer for you please mark it as solved.
    – philwinkle
    Apr 22 '16 at 19:50

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.