订单提交后发送邮件

来源:互联网 发布:淘宝店铺装修工具 编辑:程序博客网 时间:2024/05/21 16:55

\app\code\local\Lotusbreath\OneStepCheckout\controllers\IndexController.php

    public function savePostAction()    {        if($this->_expireAjax()){            return false;        }        $updateItems = array();        $previousData = $this->getRequest()->getPost();        $results = $this->process(array(            'billing' => array(),            'shipping' => array(),            'shipping_method' => array(),            'payment_method' => array()           ), true );        $isHasErrors = false;        foreach ($results as $stepIdx =>  $stepResult){            if (!empty($stepResult['error'])){                $isHasErrors = true;                switch ($stepIdx){                    case 'shipping_method':                        $updateItems[] = 'shipping_partial';                        break;                    case 'payment':                        $updateItems[] = 'payment_partial';                        break;                    case 'billing':                        $updateItems[] = 'billing_partial';                        break;                    case 'shipping':                        $updateItems[] = 'shipping_address_partial';                        break;                }            }        }        if (!$isHasErrors){            if (!empty($results['payment']['redirect'])) {                //do not save order                if ($data = $this->getRequest()->getPost('payment', false)) {                    $this->getOnepage()->getQuote()->getPayment()->importData($data);                }                $this->getCheckoutService()->updateQuote();//                发送邮件                $service = Mage::getModel('sales/service_quote', $this->getOnepage()->getQuote());                $order = $service->getOrder();                if ($order->getCanSendNewEmailFlag()) {                    try {                        $order->queueNewOrderEmail();                    } catch (Exception $e) {                        Mage::logException($e);                    }                }            }else{                $saveOrderResult = $this->getCheckoutService()->submitOrder();                $results['save_order'] = $saveOrderResult;                if ($saveOrderResult['success'] == false) {                    $updateItems[] = "review_partial";                }            }        }else{            $this->getCheckoutService()->updateQuote();        }        $return = array(            'results' => $results,            'previous_data' => $previousData,            'update_items' => $updateItems,            'success' => !empty($saveOrderResult['success']) ? $saveOrderResult['success'] : false,            'error' => !empty($saveOrderResult['error']) ? $saveOrderResult['error'] : false,        );        if (count($updateItems)) {            foreach ($updateItems as $updateItem) {                $return['htmlUpdates'][$updateItem] = $this->_getUpdateItem($updateItem);            }        }//        $this->update_customer_points();        $this->getResponse()            ->clearHeaders()            ->setHeader('Content-Type', 'application/json')            ->setBody(Mage::helper('core')->jsonEncode($return));    }
C:\website2\woowj\web\app\code\core\Mage\Checkout\Model\Type\Onepage.php

    /**     * Create order based on checkout type. Create customer if necessary.     *     * @return Mage_Checkout_Model_Type_Onepage     */    public function saveOrder()    {        $this->validate();        $isNewCustomer = false;        switch ($this->getCheckoutMethod()) {            case self::METHOD_GUEST:                $this->_prepareGuestQuote();                break;            case self::METHOD_REGISTER:                $this->_prepareNewCustomerQuote();                $isNewCustomer = true;                break;            default:                $this->_prepareCustomerQuote();                break;        }        $service = Mage::getModel('sales/service_quote', $this->getQuote());        $service->submitAll();        if ($isNewCustomer) {            try {                $this->_involveNewCustomer();            } catch (Exception $e) {                Mage::logException($e);            }        }        $this->_checkoutSession->setLastQuoteId($this->getQuote()->getId())            ->setLastSuccessQuoteId($this->getQuote()->getId())            ->clearHelperData();        $order = $service->getOrder();        if ($order) {            Mage::dispatchEvent('checkout_type_onepage_save_order_after',                array('order'=>$order, 'quote'=>$this->getQuote()));            /**             * a flag to set that there will be redirect to third party after confirmation             * eg: paypal standard ipn             */            $redirectUrl = $this->getQuote()->getPayment()->getOrderPlaceRedirectUrl();            /**             * we only want to send to customer about new order when there is no redirect to third party             *///            if (!$redirectUrl && $order->getCanSendNewEmailFlag()) {            if ($order->getCanSendNewEmailFlag()) {                try {                    $order->queueNewOrderEmail();                } catch (Exception $e) {                    Mage::logException($e);                }            }            // add order information to the session            $this->_checkoutSession->setLastOrderId($order->getId())                ->setRedirectUrl($redirectUrl)                ->setLastRealOrderId($order->getIncrementId());            // as well a billing agreement can be created            $agreement = $order->getPayment()->getBillingAgreement();            if ($agreement) {                $this->_checkoutSession->setLastBillingAgreementId($agreement->getId());            }        }        // add recurring profiles information to the session        $profiles = $service->getRecurringPaymentProfiles();        if ($profiles) {            $ids = array();            foreach ($profiles as $profile) {                $ids[] = $profile->getId();            }            $this->_checkoutSession->setLastRecurringProfileIds($ids);            // TODO: send recurring profile emails        }        Mage::dispatchEvent(            'checkout_submit_all_after',            array('order' => $order, 'quote' => $this->getQuote(), 'recurring_profiles' => $profiles)        );        return $this;    }



阅读全文
0 0