Opencart订单历史notify字段设置:支付失败/取消时邮件含交易详情
Hey there, no worries at all—we all start somewhere with OpenCart! Let's get this sorted out for you.
From what you've described, the root issue is that when a payment is cancelled or fails, the corresponding order_history record has notify set to 0, so its transaction details aren't included in the customer's email. Here's how to fix this:
Step 1: Locate where addOrderHistory is called for failed/cancelled payments
First, you'll need to find the code in your payment gateway extension that handles failed or cancelled transactions. This is usually stored in:/catalog/controller/payment/[your_payment_gateway].php
Look for sections where the payment is marked as failed or cancelled—you'll spot a call to $this->model_checkout_order->addOrderHistory(). It might look something like this:
$this->model_checkout_order->addOrderHistory($order_id, $failed_order_status_id, $transaction_details_comment, false);
Step 2: Update the $notify parameter to true
The fourth parameter in that call is $notify—right now it's set to false (which translates to 0 in the order_history table). Change it to true:
$this->model_checkout_order->addOrderHistory($order_id, $failed_order_status_id, $transaction_details_comment, true);
This ensures that the order_history record for the failed/cancelled payment will have notify = 1, so its transaction details will be pulled into the customer's email.
Step 3: (Optional) Fallback fix in order.php
If you can't track down the exact call in your payment extension, you can adjust the addOrderHistory method in /catalog/model/checkout/order.php to force $notify = true when the order status matches a failed/cancelled state.
Find the area near the if ($comment && $notify) { section you mentioned, and add a check for your specific failed/cancelled order status IDs:
// Add this right before the existing if statement $failed_status_ids = array(3, 5); // Replace these with your actual failed/cancelled status IDs if (in_array($order_status_id, $failed_status_ids)) { $notify = true; } if ($comment && $notify) { // Existing code logic here }
Note: Be sure to replace 3, 5 with the actual order status IDs that map to cancelled or failed payments in your OpenCart setup.
Final Checks
- Always back up your files before making changes to avoid accidental issues!
- Test a failed/cancelled payment flow to confirm the email now includes the missing bank transaction details.
内容的提问来源于stack exchange,提问作者Milind

