支付失败不清空购物车
2017-06-20 14:56
375 查看
app\code\local\Lotusbreath\Checkout\Model\Service\Checkout.php
app\code\core\Mage\Checkout\controllers\OnepageController.php
支付成功清空购物车
\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();
}
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();
}
相关文章推荐
- magento 付款失败之后购物车被清空的解决方法
- 支付宝SDK唤起H5页面支付第一次成功,之后再尝试失败问题
- ASP.NET 2.0打造购物车和支付系统之二
- 除了清空购物车,阿里年会的技术也超霸气!
- Ruby on rails开发从头来(windows)(十)-清空购物车和格式化金额
- 多语言网店的产品详细页面跳转到购物车页面出现产品添加到购物车失败的问题的解决!!
- 修改一句代码 实现购物车退出不清空[转载+修改]
- 微信公账号支付:签名验证失败的解决办法
- 支付宝电脑网站支付,回调时签名验证失败
- 支付宝支付接口返回到第3方站点后程序对支付宝来源检验失败原因分析
- 除了清空购物车_阿里年会的技术也超霸气!
- ASP.NET 2.0打造购物车和支付系统之二
- asp.net购物车,订单以及模拟支付宝支付(一)---购物车表及添加购物车流程
- WebView启动支付宝客户端支付失败
- 多语言网店的产品详细页面跳转到购物车页面出现产品添加到购物车失败的问题的解决!!
- 谈一谈APP支付失败的处理
- ##iOS中的微信支付 支付验证签名失败
- WebView启动支付宝客户端支付失败的解决办法
- 微信扫码支付回调验签失败,请教大神解答
- 除了清空购物车,阿里年会的技术也超霸气!