您的当前位置:首页正文

MAGENTO通过支付发票获取订单中相关信息

来源:花图问答

1.在监听订单完成事件可以这样写在config.xml中:

        <events>
            <sales_order_invoice_pay>
                <observers>
                    <boc_receiveorder>
                        <class>boc/observer</class>
                        <method>getSuccessBocOrders</method>
                    </boc_receiveorder>
                </observers>
            </sales_order_invoice_pay>
        </events>

其中sales_order_invoice_pay
是订单完成事件2.在调用的时间中可以这样获取订单信息:

public function getSuccessBocOrders($observer){
        $event = $observer->getEvent();
        $invoice = $event->getInvoice();
        $order = $invoice->getOrder();
        $order = Mage::getModel('sales/order')->load($order->getId());
        $customerId = $order->getCustomerId();
        $customer = Mage::getModel('customer/customer')->load($customerId);
        $userId = $customer->getResource()
            ->getAttribute('boc_id')
            ->getFrontend()
            ->getValue($customer);
        $exOrderNo = $order->getIncrementId();
        $createTime = Mage::app()
            ->getLocale()
            ->date(strtotime($order->getCreatedAtStoreDate()), null, null, false)
            ->addHour(8)
            ->toString('yyyy-MM-dd HH:mm:ss');

        Mage::log('orderNumber is'.$exOrderNo.'</br>',null,'tang_order_receive.log');
        Mage::log('orderTime is '.$createTime.'</br>',null,'tang_order_receive.log');
        Mage::log('orderTotal is '.$orderValue.'</br>',null,'tang_order_receive.log');
        Mage::log('orderCustomer Id is '.$customerId.'</br>',null,'tang_order_receive.log');
        Mage::log('orderBoc Id is '.$userId.'</br>',null,'tang_order_receive.log');


        foreach ($invoice->getAllItems() as $item){
            if ($item->getOrderItem()->getParentItem()) {
                continue;
            }
            /* Draw item */

            $productName = urlencode($item->getName());
            $type = $item->getSku();
            $id = $item->getProductId();
            $amount = $item->getQty();
            $amount = (int)$amount;
            $product = Mage::getModel('catalog/product')->load($id);
            $productPageAddr = $product->getProductUrl();
            $productMediaConfig = Mage::getModel('catalog/product_media_config');
            $productPic = $productMediaConfig->getMediaUrl($product->getImage());
            $ticketValue = $item->getPrice();


            Mage::log('name is:'.$productName.'</br>',null,'order_information_tang.log');
            Mage::log('sku is:'.$type.'</br>',null,'order_information_tang.log');
            Mage::log('productId is:'.$id.'</br>',null,'order_information_tang.log');
            Mage::log('Qty is:'.$amount.'</br>',null,'order_information_tang.log');
            Mage::log('ProductUrl is:'.$productPageAddr.'</br>',null,'order_information_tang.log');
            Mage::log('Product Image Url is:'.$productPic.'</br>',null,'order_information_tang.log');
            Mage::log('Product price is:'.$ticketValue.'</br>',null,'order_information_tang.log');

        }


    }