如何输出Magento的交货说明?

时间:2012-10-24 08:24:16

标签: magento

我正在尝试创建一个可以通过URL访问的脚本,以便输出交付详细信息,特别是我需要显示的字段是:orderID,status,gift_message和一个名为“delivery_instructions”的自定义客户地址属性。到目前为止,我有以下内容,但我仍然坚持尝试获取交付说明,任何帮助将不胜感激。

<?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/ >";
}
?>

2 个答案:

答案 0 :(得分:0)

你很接近:

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

要获取您需要使用的送货地址对象:

$myOrder->getShippingAddress()

并从送货地址对象获取delivery_instruction:

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

答案 1 :(得分: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();