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条)

报告相同问题?

悬赏问题

  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教