0

Is there a way to add the order# to a payment Transaction Failed email?

This is what I tried:

{* This is a comment block

Use vars: {{var var_name}}
*}<!--@subject Payment Transaction Failed Reminder @-->
<!--@vars
{"var reason":"Transaction Failed Reason",
"var checkoutType":"Checkout Type",
"var customerEmail":"Customer Email",
"var customer":"Customer Name",
"var items":"Shopping Cart Items",
"var total":"Total",
"var billingAddress.format('html')":"Billing Address",
"var shippingAddress.format('html')":"Shipping Address",
"var shippingMethod":"Shipping Method",
"var paymentMethod":"Payment Method",
"var dateAndTime":"Date and Time of Transaction"
"var order.increment_id":"order_id"}
@-->

<table>
    <thead>
        <tr>
            <th>Payment transaction failed.</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>
                <p>
                    <b>Order Number:</b><br />
                    {{var order_id}}
                </p>
                <p>
                    <b>Reason</b><br />
                    {{var reason}}
                </p>

            </td>
            <!-- snipped rest of template -->
        </tr>
    </tbody>
</table>

However, no order# came through...Even tried using the QUOTE reserved_order_id:

"var reserved_order_id":"order_id"

Still nothing.

2 Answers 2

2

you can do this easy In paypal payment if order payment becomes failed then it set revered order id null, so

goto copy

app/code/core/Mage/Checkout/Helper/Data.php

to

app/code/local/Mage/Checkout/Helper/Data.php

Here you will find the filler payment mail function sendPaymentFailedEmail().

add new parameters to mail to which will send order id and order increment id

and here $checkout give quote object you.

so i load order collection and filter by current quote id and sort by order id(entity_id) desc.

    $SalesCollection=Mage::getResourceModel('sales/order_collection')->addAttributeToSelect('*')
->addAttributeToFilter('quote_id',$checkout->getId())->addAttributeToSort('entity_id',DESC);

then get last order id of this quote.

$lastetOrderId=$SalesCollection->getFirstItem()->getId();
$lastetOrderIncrementId= $SalesCollection->getFirstItem()->getIncrementId();

and end this parameter in email template

'lastetorderid' => $lastetOrderId,
 'lastetorderincrementid' => $lastetOrderIncrementId,

and on payment failed mail html template get this params by

var lastetorderid
var lastetorderincrementid

and this code

...

"var lastetorderid":"Order id",
"var lastetorderincrementid":"order increment",

after

"var shippingAddress.format('html')":"Shipping Address",
5
+50

You don't get an order id in the payment failed e-mail because the order object is not created yet and the order id is not reserved for the quote.
if the error that triggers the payment failed email happens after the order is saved you will get an order id. But the chance of this happening is close to 0.

The order id is reserved in the order saving process. In Mage_Sales_Model_Service_Quote::submitOrder() there is this $quote->reserveOrderId();.

I don't know why you would need an order id in the payment failed template because there will be no order if that happens. So your number will be useless, but if you really need it here is what you can do.

You need to rewrite the method Mage_Checkout_Helper_Data::sendPaymentFailedEmail and reserve the order id if it's not already reserved before the e-mail is sent.
for that create a module.
Lets call it Easylife_Checkout.
You will need the following files:

app/etc/modules/Easylife_Checkout.xml - the declaration file

<?xml version="1.0"?>
<config>
    <modules>
        <Easylife_Checkout>
            <codePool>local</codePool>
            <active>true</active>
            <depends>
                <Mage_Checkout /><!-- depends on the checkout module -->
            </depends>
        </Easylife_Checkout>
    </modules>
</config>

app/code/local/Easylife/Checkout/etc/config.xml - the configuration file

<?xml version="1.0"?>
<config>
    <modules>
        <Easylife_Checkout>
            <version>1.0.0</version>
        </Easylife_Checkout>
    </modules>
    <global>
        <helpers>
            <checkout>
                <rewrite>
                    <data>Easylife_Checkout_Helper_Data</data><!-- rewrite the chekcout helper -->
                </rewrite>
            </checkout>
        </helpers>
    </global>
</config>

app/code/local/Easylife/Checkout/Helper/Data.php - the rewritten helper

<?php  
class Easylife_Checkout_Helper_Data extends Mage_Checkout_Helper_Data {
    public function sendPaymentFailedEmail($checkout, $message, $checkoutType = 'onepage') {
        $reservedOrderId = $checkout->getReservedOrderId();
        if (!$reservedOrderId) {
             $checkout->reserveOrderId();
        }
        return parent::sendPaymentFailedEmail($checkout, $message, $checkoutType);
    }
}
2
  • I don't know why you would need an order id in the payment failed template because there will be no order if that happens I really forgot about that. I guess I'll just drop it.
    – MB34
    Sep 10, 2014 at 13:58
  • @MB34. What do you mean you'll drop it? after all the time I spent writing this answer... :). Just kidding. I would drop it also.
    – Marius
    Sep 10, 2014 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.