Magento - 如何通过订单/ customer_id获取电子邮件地址

时间:2012-03-06 15:00:13

标签: magento

如何在Magento中获取客户电子邮件地址?最后,我希望以CSV格式导出所有货件详细信息。

<?php
    //External script - Load magento framework
    require_once("app/Mage.php");
    Mage::app('default');

    $myOrder=Mage::getModel('sales/order'); 
    $orders=Mage::getModel('sales/mysql4_order_collection');
    $allIds=$orders->getAllIds();
    foreach($allIds as $thisId) {
        $myOrder->load($thisId);
        echo "name: ". $myOrder->getShippingAddress()->getFirstname() . " " . $myOrder->getShippingAddress()->getLastname();
        echo "email: " . $myOrder->getPayment()->getOrder()->getEmail();
    }
    ?>

3 个答案:

答案 0 :(得分:22)

您可以使用:

echo "name: ". $myOrder->getCustomerName();
echo "email: " . $myOrder->getCustomerEmail();

(在magento 1.6.2.0中测试)

答案 1 :(得分:1)

我记得,电子邮件地址也与发货/结算信息一起存储,所以:

$myOrder->getShippingAddress()->getEmail()

答案 2 :(得分:1)

使用以下代码通过订单客户ID获取电子邮件地址:

 $orderId = '100000023'; // mention order id here
    $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
    $shippingAddress = $order->getShippingAddress();
    echo $shippingAddress->getEmail();