doudun2565 2013-12-06 16:05
浏览 35
已采纳

Magento 1.7.0.2获取订单信息

I have created an observer module that will send an email whenever a certain product is bought and paid for. In order to populate that email, I need to retrieve the Shipping Address, Billing Address, and Customer Name for a given order. Thus far my Observer.php looks like this:

<?php
class Electricjesus_Notifyowner_Model_Observer {
    public function notifyOwnerEvent($observer) {

        $invoice = $observer->getInvoice();

        // derivative data
        $order = $invoice->getOrder(); // Mage_Sales_Model_Order
        $items = $order->getAllItems();

        $i = 0;
        foreach($items as $item) {
            $skus[$i] = $item->getSku();
            $i++;
        }
        $needle = 'train-01';

        if( in_array( $needle, $skus ) ) {

            ob_start();
            var_dump($skus);
            $skuDump = ob_get_clean();
            $filedump = '$skuDump: ' . $skuDump . "
" . '------------------------------' . "
";

            $shipAddr = $order->getBillingAddress();
            ob_start();
            var_dump($shipAddr);
            $shipAddrDump = ob_get_clean();
            $filedump .= '$shipAddrDump: ' . $shipAddrDump . "
" . '------------------------------' . "
";

            $billAddr = $invoice->getShippingAddress();
            ob_start();
            var_dump($billAddr);
            $billAddrDump = ob_get_clean();
            $filedump .= '$billAddrDump: ' . $billAddrDump . "
" . '------------------------------' . "
";

            $custName = $order->getCustomerName();
            ob_start();
            var_dump($custName);
            $custNameDump = ob_get_clean();
            $filedump .= '$custNamedump: ' . $custNameDump;

            file_put_contents('observer_log.txt', $filedump);

            $email = array(
                'to' => 'daniel@danielclarke.ca',
                'subject' => 'Confirmed Purchase',
                'message' => "
                    <html>
                        <body>
                            ". $custName ." has ordered and paid for the following products.
                            <table>
                                <th>
                                    <td>
                                        Items Ordered
                                    </td>
                                    <td>
                                        Shipping Address
                                    </td>
                                    <td>
                                        Billing Address
                                    </td>
                                </th>
                                <tr>
                                    <td>
                                        ". $skuDump ."
                                    </td>
                                    <td>
                                        ". $shipAddr ."
                                    </td>
                                    <td>
                                        ". $billAddr ."
                                    </td>
                                </tr>
                            </table>
                        </body>
                    </html>",
                'headers' => 'MIME-Version: 1.0' . "
" . 'Content-type: text/html; charset=iso-8859-1' . "
" . 'From: Ashop.in Store'
            ); 

            //mail($email['to'], $email['subject'], $email['message'], $email['headers']);
        }

        return $this;  // always return $this.
    }

I have commented out the line to actually send the email preferring instead to simply output to a file as it's faster and easier given the large amount of information in the objects involved. I thought that $shipAddr = $order->getBillingAddress(); $billAddr = $invoice->getShippingAddress(); and $custName = $order->getCustomerName(); would be all I need but they return large objects rather than the simple strings I need.

How do I get the Addresses and Name output into simple strings that I can insert into an email?

Thank you in advance.

}
  • 写回答

2条回答 默认 最新

  • dsgdhf5674 2013-12-06 17:12
    关注

    Try

    $order->getBillingAddress()->format('html')

    Also it would be better if you using the magento transactional email, take a look @ magento sending custom emails

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 c语言,请帮蒟蒻看一个题
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)