0

我正在尝试创建一个可以通过 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/ >";
}
?>
4

2 回答 2

0

你很接近这个:

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

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

$myOrder->getShippingAddress()

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

$myOrder->getShippingAddress()->getDeliveryInstructions()
于 2012-10-24T10:31:46.343 回答
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();
于 2012-10-25T08:11:14.620 回答