我們知道Magento程序在客戶下單付款成功或是失敗都會清空掉購物車,
來看看場景
如果我們有這樣一個需求如下
當客戶付款失敗, 我們會跳到支付頁面提示支付失敗的原因,並讓客戶選擇其他的支付方式,要實現這個需求的前提是購物車未清空.
修改,找到支付模塊的saveOrderAction() 這裏根據你的一頁支付插件而定,這裏我們以Firecheckout爲例
找到/app/code/local/TM/FireCheckout/controllers/IndexController.php
$quote->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;
}
更新後的代碼
//$quote->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{
$quote->save();
}
Magento提交訂單會跳轉到支付結果頁面,我們需要將failure.phtml的內容修改成如下:
找到app/design/frontend/主題/default/template/checkout/onepage/failure.phtml
<?php if ($this->getRealOrderId()) : ?><p><?php echo $this->__('Order #') . $this->getRealOrderId() ?></p><?php endif ?>
<?php if ($error = $this->getErrorMessage()) : ?><p><?php echo $error ?></p><?php endif ?>
<?php
$order_id = $this->getRealOrderId();
header("Location: https://你的域名/firecheckout/?order_id=$order_id");
?>
在Checkout頁面我們提示信用卡支付信息
找到/app/design/frontend/base/default/template/tm/firecheckout/checkout.phtml
添加如下代碼
<?php if($_GET['order_id']):?>
<p style="color:red; height:25px;line-height:25px;">SORRY,TRANSACTION FAILURRE, order number: <?php echo $_GET['order_id'];?>, please choose other payment methods: PayPal or Western Union.</p>
<?php endif;?>
真正有需要的朋友可以去測試。。。