0

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

gift_price
gift_message
gift_type

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 $order->getData() and $order->getItemsCollection()). How do I read the values from that table, for the current sales order object I am working with?

Latheesan
  • 23,247
  • 32
  • 107
  • 201
  • Did this module override the item from sales_order object? It it is true, did you try $order->getItemsCollection()? – miwata Oct 05 '15 at 18:54
  • @miwata yes, I have tried that already, it does not work. I don't think module overrides the sales_order object. – Latheesan Oct 06 '15 at 09:10

1 Answers1

0

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';
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

// 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']) &&
        sizeof($additional_data['m2epro_extension']['items']))
    {
        // Iterate through each order item id
        foreach ($additional_data['m2epro_extension']['items'] as $data)
        {
            // Anticipate errors
            try
            {
                // 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.

Latheesan
  • 23,247
  • 32
  • 107
  • 201