2012-10-24 50 views
0

我想創建一個腳本,我可以通過URL訪問,以便輸出交付細節,特別是我需要顯示的字段是:orderID,status,gift_message和稱爲「delivery_instructions」的自定義客戶地址屬性。到目前爲止,我有以下內容,但我堅持試圖獲得交付說明,任何幫助將不勝感激。如何輸出Magento的傳送指令?

<?php 
require_once 'app/Mage.php'; 
Mage::app('default'); 
$myOrder=Mage::getModel('sales/order'); 

$orders=Mage::getModel('sales/mysql4_order_collection'); 
$message = Mage::getModel('giftmessage/message'); 
$customer = Mage::getModel('customer/customer'); 

$orders->addFieldToFilter('total_paid',Array('gt'=>0)); //Amount paid larger than 0 
//$orders->addFieldToFilter('gift_message_id',Array('gt'=>0)); 

$allIds=$orders->getAllIds(); 
foreach($allIds as $thisId) { 
    $myOrder->reset()->load($thisId); 
    $shippingAddress = $myOrder->getShippingAddress(); 
    $customerDetails = $myOrder->getCustomer(); 
    //echo $myOrder->shippingaddress->getData('delivery_instructions'); 
    $customer_id = $myOrder->getCustomerId() . "',"; 
    echo $customer_id . "',"; 
     echo "'" . $myOrder->getStatus() . "',"; 
    echo "'" . $myOrder->getIncrementID() . "',"; 
    $gift_message_id = $myOrder->getGiftMessageId(); 
     if(!is_null($gift_message_id)) { 
      $message->load($gift_message_id); 
      echo $gift_message = $message->getData('message') . "',"; 
     }; 
$customer = Mage::getModel('customer/customer')->load($customer_id); 
echo $customer = $customer->getData('incrementId'); 
echo "\r\n"; 
echo "<br/ >"; 
} 
?> 

回答

0

你接近這個:

//echo $myOrder->shippingaddress->getData('delivery_instructions'); 

爲了得到你需要使用的送貨地址對象:

$myOrder->getShippingAddress() 

,並得到從送貨地址對象delivery_instruction :

$myOrder->getShippingAddress()->getDeliveryInstructions() 
+0

感謝您的答覆。雖然這似乎獲得了字段delivery_instructions,而不是在客戶級別創建的自定義屬性。 有什麼想法? – user1461770

+0

請參閱@ i.amniels響應...從任何對象獲取屬性如下所示:$ object-> getCamelCaseAttributeName() – FlorinelChis

0

您可以創建自定義地址屬性和自定義客戶屬性。

客戶屬性可以這樣訪問:

// A customer is not mandatory for an order. 
if($myOrder->getCustomerId()){ 
    $customer = Mage::getModel(’customer/customer’)->load($myOrder->getCustomerId()); 
    $customer->getDeliveryInstructions(); 
} 

地址屬性可以這樣訪問:

$myOrder->getShippingAddress()->getDeliveryInstructions();