app\code\core\Mage\Checkout\controllers\OnepageController.php
/**
* Create order action
*/
public function saveOrderAction()
{
if ($this->_expireAjax()) {
return;
}
$result = array();
try {
if ($requiredAgreements = Mage::helper('checkout')->getRequiredAgreementIds()) {
$postedAgreements = array_keys($this->getRequest()->getPost('agreement', array()));
if ($diff = array_diff($requiredAgreements, $postedAgreements)) {
$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;
}
}
if ($data = $this->getRequest()->getPost('payment', false)) {
$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();
if ($gotoSection = $this->getOnepage()->getCheckout()->getGotoSection()) {
$result['goto_section'] = $gotoSection;
$this->getOnepage()->getCheckout()->setGotoSection(null);
}
if ($updateSection = $this->getOnepage()->getCheckout()->getUpdateSection()) {
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;
// }
if (isset($redirectUrl)) {
$result['redirect'] = $redirectUrl;
}
else
{
$this->getOnepage()->getQuote()->save();
}
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
经测试,发现抛出异常
SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction
原因是你使用的InnoDB 表类型的时候,
默认参数:innodb_lock_wait_timeout设置锁等待的时间是50s,
因为有的锁等待超过了这个时间,所以抱错.
你可以把这个时间加长,或者优化存储过程,事务避免过长时间的等待.
my.ini文件:
#innodb_lock_wait_timeout = 50
-》
innodb_lock_wait_timeout = 500
重启mysql服务。
/**
* Send email id payment was failed
*
* @param Mage_Sales_Model_Quote $checkout
* @param string $message
* @param string $checkoutType
* @return Mage_Checkout_Helper_Data
*/
public function sendPaymentFailedEmail($checkout, $message, $checkoutType = 'onepage')
{
$translate = Mage::getSingleton('core/translate');
/* @var $translate Mage_Core_Model_Translate */
$translate->setTranslateInline(false);
$mailTemplate = Mage::getModel('core/email_template');
/* @var $mailTemplate Mage_Core_Model_Email_Template */
$template = Mage::getStoreConfig('checkout/payment_failed/template', $checkout->getStoreId());
$copyTo = $this->_getEmails('checkout/payment_failed/copy_to', $checkout->getStoreId());
$copyMethod = Mage::getStoreConfig('checkout/payment_failed/copy_method', $checkout->getStoreId());
if ($copyTo && $copyMethod == 'bcc') {
$mailTemplate->addBcc($copyTo);
}
$_reciever = Mage::getStoreConfig('checkout/payment_failed/reciever', $checkout->getStoreId());
$sendTo = array(
array(
'email' => Mage::getStoreConfig('trans_email/ident_'.$_reciever.'/email', $checkout->getStoreId()),
'name' => Mage::getStoreConfig('trans_email/ident_'.$_reciever.'/name', $checkout->getStoreId())
)
);
if ($copyTo && $copyMethod == 'copy') {
foreach ($copyTo as $email) {
$sendTo[] = array(
'email' => $email,
'name' => null
);
}
}
$shippingMethod = '';
if ($shippingInfo = $checkout->getShippingAddress()->getShippingMethod()) {
$data = explode('_', $shippingInfo);
$shippingMethod = $data[0];
}
$paymentMethod = '';
if ($paymentInfo = $checkout->getPayment()) {
$paymentMethod = $paymentInfo->getMethod();
}
$items = '';
foreach ($checkout->getAllVisibleItems() as $_item) {
/* @var $_item Mage_Sales_Model_Quote_Item */
$items .= $_item->getProduct()->getName() . ' x '. $_item->getQty() . ' '
. $checkout->getStoreCurrencyCode() . ' '
. $_item->getProduct()->getFinalPrice($_item->getQty()) . "\n";
}
$total = $checkout->getStoreCurrencyCode() . ' ' . $checkout->getGrandTotal();
foreach ($sendTo as $recipient) {
$mailTemplate->setDesignConfig(array('area'=>'frontend', 'store'=>$checkout->getStoreId()))
->sendTransactional(
$template,
Mage::getStoreConfig('checkout/payment_failed/identity', $checkout->getStoreId()),
$recipient['email'],
$recipient['name'],
array(
'reason' => $message,
'checkoutType' => $checkoutType,
'dateAndTime' => Mage::app()->getLocale()->date(),
'customer' => $checkout->getCustomerFirstname() . ' ' . $checkout->getCustomerLastname(),
'customerEmail' => $checkout->getCustomerEmail(),
'billingAddress' => $checkout->getBillingAddress(),
'shippingAddress' => $checkout->getShippingAddress(),
'shippingMethod' => Mage::getStoreConfig('carriers/'.$shippingMethod.'/title'),
'paymentMethod' => Mage::getStoreConfig('payment/'.$paymentMethod.'/title'),
'items' => nl2br($items),
'total' => $total
)
);
}
$translate->setTranslateInline(true);
return $this;
}
在