Skip to content

Commit 3215998

Browse files
fix: update expected order ID format for second chance emails and improve template variables
1 parent 5f9ee45 commit 3215998

File tree

3 files changed

+44
-46
lines changed

3 files changed

+44
-46
lines changed

Model/SecondChanceRepository.php

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -524,10 +524,14 @@ public function getSecondChanceCollection($step, $store)
524524
}
525525

526526
// Calculate and store the expected order ID before sending email
527-
$expectedOrderId = $this->setAvailableIncrementId($item->getOrderId(), $order);
528-
if ($expectedOrderId) {
529-
$item->setLastOrderId($expectedOrderId);
530-
}
527+
// For step 1: Always use -1 suffix (first reminder)
528+
// For step 2: Always use -2 suffix (second reminder)
529+
// This makes it easy for customer support to identify which email led to the order
530+
$suffix = ($step == 1) ? '-1' : '-2';
531+
$expectedOrderId = $item->getOrderId() . $suffix;
532+
533+
// Store it so when customer clicks, we use the same ID
534+
$item->setLastOrderId($expectedOrderId);
531535

532536
// Send email
533537
$this->sendMail($order, $item, $step);
@@ -610,22 +614,34 @@ public function sendMail($order, $secondChance, $step)
610614
'email' => $senderEmail,
611615
];
612616

613-
// Prepare template variables
617+
// Prepare template variables (matching original SecondChance module)
614618
try {
615619
$paymentHtml = $this->getPaymentHtml($order);
616620
$billingAddress = $this->getFormattedBillingAddress($order);
617621
$shippingAddress = $this->getFormattedShippingAddress($order);
618622

619623
$templateVars = [
620624
'order' => $order,
625+
'order_id' => $order->getId(),
621626
'expected_order_id' => $expectedOrderId ?: $order->getIncrementId(),
627+
'billing' => $order->getBillingAddress(),
628+
'payment_html' => $paymentHtml,
629+
'formattedBillingAddress' => $billingAddress,
630+
'formattedShippingAddress' => $shippingAddress,
631+
'billing_address' => $billingAddress, // Keep for backward compatibility
632+
'shipping_address' => $shippingAddress, // Keep for backward compatibility
622633
'checkout_url' => $checkoutUrl,
623634
'store' => $store,
635+
'created_at_formatted' => $order->getCreatedAtFormatted(2),
636+
'secondChanceToken' => $secondChance->getToken(),
624637
'customer_name' => $order->getCustomerName(),
625638
'customer_email' => $order->getCustomerEmail(),
626-
'payment_html' => $paymentHtml,
627-
'billing_address' => $billingAddress,
628-
'shipping_address' => $shippingAddress,
639+
'order_data' => [
640+
'customer_name' => $order->getCustomerName(),
641+
'is_not_virtual' => $order->getIsNotVirtual(),
642+
'email_customer_note' => $order->getEmailCustomerNote(),
643+
'frontend_status_label' => $order->getFrontendStatusLabel()
644+
]
629645
];
630646
} catch (Exception $e) {
631647
$this->logging->addError('Error preparing template variables: ' . $e->getMessage());

view/frontend/email/buckaroo_second_chance_first.html

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@
2020
-->
2121
<!--@subject {{trans "Complete your order - %store_name" store_name=$store.getFrontendName()}} @-->
2222
<!--@vars {
23-
"var billing_address|raw":"Billing Address",
24-
"var shipping_address|raw":"Shipping Address",
23+
"var formattedBillingAddress|raw":"Billing Address",
24+
"var formattedShippingAddress|raw":"Shipping Address",
2525
"var order.increment_id":"Order Id",
2626
"var expected_order_id":"Expected Order Id",
27+
"var order_data.email_customer_note|escape|nl2br":"Email Order Note",
28+
"layout handle=\"sales_email_order_items\" order_id=$order_id area=\"frontend\"":"Order Items Grid",
2729
"var payment_html|raw":"Payment Details",
2830
"var checkout_url":"Checkout URL",
2931
"var customer_name":"Customer Name",
30-
"var customer_email":"Customer Email"
32+
"var customer_email":"Customer Email",
33+
"var order.getShippingDescription":"Shipping Description"
3134
} @-->
3235

3336
{{template config_path="design/email/header_template"}}
@@ -59,12 +62,12 @@ <h1>{{trans 'Your Order <span class="no-link">#%increment_id</span>' increment_i
5962
<tr>
6063
<td class="address-details">
6164
<h3>{{trans "Billing Information"}}</h3>
62-
<p>{{var billing_address|raw}}</p>
65+
<p>{{var formattedBillingAddress|raw}}</p>
6366
</td>
64-
{{depend shipping_address}}
67+
{{depend order_data.is_not_virtual}}
6568
<td class="address-details">
6669
<h3>{{trans "Shipping Information"}}</h3>
67-
<p>{{var shipping_address|raw}}</p>
70+
<p>{{var formattedShippingAddress|raw}}</p>
6871
</td>
6972
{{/depend}}
7073
</tr>
@@ -88,19 +91,7 @@ <h3>{{trans "Shipping Method"}}</h3>
8891
</a>
8992
</div>
9093

91-
<table class="order-items">
92-
<thead>
93-
<tr>
94-
<th>{{trans "Product"}}</th>
95-
<th>{{trans "SKU"}}</th>
96-
<th>{{trans "Qty"}}</th>
97-
<th>{{trans "Price"}}</th>
98-
</tr>
99-
</thead>
100-
<tbody>
101-
{{layout handle="sales_email_order_items" order=$order area="frontend"}}
102-
</tbody>
103-
</table>
94+
{{layout handle="sales_email_order_items" order_id=$order_id area="frontend"}}
10495
</td>
10596
</tr>
10697
</table>

view/frontend/email/buckaroo_second_chance_second.html

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@
2020
-->
2121
<!--@subject {{trans "Last chance to complete your order - %store_name" store_name=$store.getFrontendName()}} @-->
2222
<!--@vars {
23-
"var billing_address|raw":"Billing Address",
24-
"var shipping_address|raw":"Shipping Address",
23+
"var formattedBillingAddress|raw":"Billing Address",
24+
"var formattedShippingAddress|raw":"Shipping Address",
2525
"var order.increment_id":"Order Id",
2626
"var expected_order_id":"Expected Order Id",
27+
"var order_data.email_customer_note|escape|nl2br":"Email Order Note",
28+
"layout handle=\"sales_email_order_items\" order_id=$order_id area=\"frontend\"":"Order Items Grid",
2729
"var payment_html|raw":"Payment Details",
2830
"var checkout_url":"Checkout URL",
2931
"var customer_name":"Customer Name",
30-
"var customer_email":"Customer Email"
32+
"var customer_email":"Customer Email",
33+
"var order.getShippingDescription":"Shipping Description"
3134
} @-->
3235

3336
{{template config_path="design/email/header_template"}}
@@ -59,12 +62,12 @@ <h1 style="color: #d43f00;">{{trans 'Final Notice - Order <span class="no-link">
5962
<tr>
6063
<td class="address-details">
6164
<h3>{{trans "Billing Information"}}</h3>
62-
<p>{{var billing_address|raw}}</p>
65+
<p>{{var formattedBillingAddress|raw}}</p>
6366
</td>
64-
{{depend shipping_address}}
67+
{{depend order_data.is_not_virtual}}
6568
<td class="address-details">
6669
<h3>{{trans "Shipping Information"}}</h3>
67-
<p>{{var shipping_address|raw}}</p>
70+
<p>{{var formattedShippingAddress|raw}}</p>
6871
</td>
6972
{{/depend}}
7073
</tr>
@@ -91,19 +94,7 @@ <h3>{{trans "Shipping Method"}}</h3>
9194
</a>
9295
</div>
9396

94-
<table class="order-items">
95-
<thead>
96-
<tr>
97-
<th>{{trans "Product"}}</th>
98-
<th>{{trans "SKU"}}</th>
99-
<th>{{trans "Qty"}}</th>
100-
<th>{{trans "Price"}}</th>
101-
</tr>
102-
</thead>
103-
<tbody>
104-
{{layout handle="sales_email_order_items" order=$order area="frontend"}}
105-
</tbody>
106-
</table>
97+
{{layout handle="sales_email_order_items" order_id=$order_id area="frontend"}}
10798

10899
<div style="margin-top: 30px; padding: 15px; background-color: #f5f5f5; border-left: 4px solid #1979c3;">
109100
<p style="margin: 0; font-style: italic;">

0 commit comments

Comments
 (0)