支付失败不清空购物车

来源:互联网 发布:用友支票打印软件 编辑:程序博客网 时间:2024/04/30 03:05

app\code\local\Lotusbreath\Checkout\Model\Service\Checkout.php

    public function submitOrder()    {        try {            $data = $this->getRequest()->getPost('payment', array());            if ($data) {                $data['checks'] = Mage_Payment_Model_Method_Abstract::CHECK_USE_CHECKOUT                    | Mage_Payment_Model_Method_Abstract::CHECK_USE_FOR_COUNTRY                    | Mage_Payment_Model_Method_Abstract::CHECK_USE_FOR_CURRENCY                    | Mage_Payment_Model_Method_Abstract::CHECK_ORDER_TOTAL_MIN_MAX                    | Mage_Payment_Model_Method_Abstract::CHECK_ZERO_TOTAL;                $this->getOnepage()->getQuote()->getPayment()->importData($data);            }            //save comment            if (Mage::getStoreConfig('lotusbreath_onestepcheckout/general/allowcomment')) {                Mage::getSingleton('customer/session')->setOrderCustomerComment($this->getRequest()->getPost('order_comment'));            }            $this->subscribeNewsletter();            $result = array();            $dispatchParams = array(                'data' => $this->getRequest()->getPost(),                'result' => $result            );            Mage::dispatchEvent('lotus_checkout_submit_order_before',$dispatchParams);            $this->getOnepage()->saveOrder();            $redirectUrl = $this->getOnepage()->getCheckout()->getRedirectUrl();            $result['success'] = true;            $result['error'] = false;        } catch (Mage_Payment_Model_Info_Exception $e) {            $message = $e->getMessage();            $result['success'] = false;            $result['error'] = true;            if (!empty($message)) {                $result['error_messages'] = $message;            }        } catch (Mage_Core_Exception $e) {            Mage::logException($e);            Mage::helper('checkout')->sendPaymentFailedEmail($this->getOnepage()->getQuote(), $e->getMessage());            $result['success'] = false;            $result['error'] = true;            $result['error_messages'] = $e->getMessage();            if ($gotoSection = $this->getOnepage()->getCheckout()->getGotoSection()) {                $result['goto_section'] = $gotoSection;                $this->getOnepage()->getCheckout()->setGotoSection(null);            }        } catch (Exception $e) {            Mage::logException($e);            //echo $e->getMessage();            Mage::helper('checkout')->sendPaymentFailedEmail($this->getOnepage()->getQuote(), $e->getMessage());            $result['success'] = false;            $result['error'] = true;            $result['error_messages'] = $this->__('There was an error processing your order. Please contact us or try again later.');        }//        $this->getOnepage()->getQuote()->save();        /**         * when there is redirect to third party, we don't want to save order yet.         * we will save the order in return action.         */        if (isset($redirectUrl)) {            $result['redirect'] = $redirectUrl;        }else{            $this->getOnepage()->getQuote()->save();        }        return $result;    }


app\code\core\Mage\Checkout\controllers\OnepageController.php

    /**     * Create order action     */    public function saveOrderAction()    {        if (!$this->_validateFormKey()) {            $this->_redirect('*/*');            return;        }        if ($this->_expireAjax()) {            return;        }        $result = array();        try {            $requiredAgreements = Mage::helper('checkout')->getRequiredAgreementIds();            if ($requiredAgreements) {                $postedAgreements = array_keys($this->getRequest()->getPost('agreement', array()));                $diff = array_diff($requiredAgreements, $postedAgreements);                if ($diff) {                    $result['success'] = false;                    $result['error'] = true;                    $result['error_messages'] = $this->__('Please agree to all the terms and conditions before placing the order.');                    $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));                    return;                }            }            $data = $this->getRequest()->getPost('payment', array());            if ($data) {                $data['checks'] = Mage_Payment_Model_Method_Abstract::CHECK_USE_CHECKOUT                    | Mage_Payment_Model_Method_Abstract::CHECK_USE_FOR_COUNTRY                    | Mage_Payment_Model_Method_Abstract::CHECK_USE_FOR_CURRENCY                    | Mage_Payment_Model_Method_Abstract::CHECK_ORDER_TOTAL_MIN_MAX                    | Mage_Payment_Model_Method_Abstract::CHECK_ZERO_TOTAL;                $this->getOnepage()->getQuote()->getPayment()->importData($data);            }            $this->getOnepage()->saveOrder();            $redirectUrl = $this->getOnepage()->getCheckout()->getRedirectUrl();            $result['success'] = true;            $result['error']   = false;        } catch (Mage_Payment_Model_Info_Exception $e) {            $message = $e->getMessage();            if (!empty($message)) {                $result['error_messages'] = $message;            }            $result['goto_section'] = 'payment';            $result['update_section'] = array(                'name' => 'payment-method',                'html' => $this->_getPaymentMethodsHtml()            );        } catch (Mage_Core_Exception $e) {            Mage::logException($e);            Mage::helper('checkout')->sendPaymentFailedEmail($this->getOnepage()->getQuote(), $e->getMessage());            $result['success'] = false;            $result['error'] = true;            $result['error_messages'] = $e->getMessage();            $gotoSection = $this->getOnepage()->getCheckout()->getGotoSection();            if ($gotoSection) {                $result['goto_section'] = $gotoSection;                $this->getOnepage()->getCheckout()->setGotoSection(null);            }            $updateSection = $this->getOnepage()->getCheckout()->getUpdateSection();            if ($updateSection) {                if (isset($this->_sectionUpdateFunctions[$updateSection])) {                    $updateSectionFunction = $this->_sectionUpdateFunctions[$updateSection];                    $result['update_section'] = array(                        'name' => $updateSection,                        'html' => $this->$updateSectionFunction()                    );                }                $this->getOnepage()->getCheckout()->setUpdateSection(null);            }        } catch (Exception $e) {            Mage::logException($e);            Mage::helper('checkout')->sendPaymentFailedEmail($this->getOnepage()->getQuote(), $e->getMessage());            $result['success']  = false;            $result['error']    = true;            $result['error_messages'] = $this->__('There was an error processing your order. Please contact us or try again later.');        }//        $this->getOnepage()->getQuote()->save();        /**         * when there is redirect to third party, we don't want to save order yet.         * we will save the order in return action.         *///        跳转到第三方支付不清空购物车        if (isset($redirectUrl)) {            $result['redirect'] = $redirectUrl;        }else{            $this->getOnepage()->getQuote()->save();        }        $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));    }

支付成功清空购物车

\web\app\code\core\Mage\Checkout\controllers\OnepageController.php

    public function successAction()    {        $session = $this->getOnepage()->getCheckout();        if (!$session->getLastSuccessQuoteId()) {            $this->_redirect('checkout/cart');            return;        }        $lastQuoteId = $session->getLastQuoteId();        $lastOrderId = $session->getLastOrderId();        $lastRecurringProfiles = $session->getLastRecurringProfileIds();        if (!$lastQuoteId || (!$lastOrderId && empty($lastRecurringProfiles))) {            $this->_redirect('checkout/cart');            return;        }        $this->update_customer_points();        $this->earnpointswithmakepurchase();        $points =  Mage::getSingleton('customer/session')->getApplyPoints();        if($points)        {            $this->spendpoints($points);        }//清空购物车        $this->getOnepage()->getQuote()->save();        $session->clear();        $this->loadLayout();        $this->_initLayoutMessages('checkout/session');        Mage::dispatchEvent('checkout_onepage_controller_success_action', array('order_ids' => array($lastOrderId)));        $this->renderLayout();    }



阅读全文
0 0
原创粉丝点击