2015-10-05 88 views
0

我可以像这样通过Magento的模型加载销售订单:负载M2EPro亚马逊数据

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

我如何通过模型?: 参考亚马逊的值: 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 

这些在m2epro_amazon_order_item表被发现。 enter image description here

我在转储订单/每行数据(使用$order->getData()$order->getItemsCollection())时看不到这些字段。我如何从该表中读取当前销售订单对象的值?

+0

此模块是否覆盖sales_order对象中的项目?这是真的,你尝试$ order-> getItemsCollection()? – miwata

+0

@miwata是的,我已经试过了,它不起作用。我不认为模块覆盖了sales_order对象。 – Latheesan

回答

0

一些修修补补左右后,我相信,我发现那里的数据是,相应的模型实体名称等等放在一起如下:

// 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) { } 
     } 
    } 
} 

这似乎是工作,但我不确定是否有比我上面发布的方法“更好/适当”的方法。