Skip to content

Commit 37e26fe

Browse files
Merge pull request #1415 from buckaroo-it/BP-5029-Second-chance-order-ID-s-don-t-end-on-1-or-2-anymore
Bp 5029 second chance order id s don t end on 1 or 2 anymore
2 parents 8bb2172 + 7d9612b commit 37e26fe

File tree

4 files changed

+77
-47
lines changed

4 files changed

+77
-47
lines changed

Model/SecondChanceRepository.php

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,11 @@ public function getSecondChanceByToken($token)
415415
// Recreate quote with Second Chance suffix
416416
$order = $this->orderFactory->create()->loadByIncrementId($secondChance->getOrderId());
417417
if ($order->getId()) {
418-
// Find available increment ID with suffix (e.g., orderId-1, orderId-2, etc.)
419-
$newOrderId = $this->setAvailableIncrementId($secondChance->getOrderId(), $order);
418+
$newOrderId = $secondChance->getLastOrderId();
419+
420+
if (!$newOrderId) {
421+
$newOrderId = $this->setAvailableIncrementId($secondChance->getOrderId(), $order);
422+
}
420423

421424
// Recreate the quote
422425
$quote = $this->quoteRecreate->duplicate($order);
@@ -428,7 +431,8 @@ public function getSecondChanceByToken($token)
428431
$this->logging->addDebug('Second Chance: Order ID suffix applied to new quote', [
429432
'quote_id' => $quote->getId(),
430433
'reserved_order_id' => $newOrderId,
431-
'original_order_id' => $secondChance->getOrderId()
434+
'original_order_id' => $secondChance->getOrderId(),
435+
'was_pre_calculated' => !empty($secondChance->getLastOrderId())
432436
]);
433437
}
434438
}
@@ -519,6 +523,16 @@ public function getSecondChanceCollection($step, $store)
519523
continue;
520524
}
521525

526+
// Calculate and store the expected order ID before sending email
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);
535+
522536
// Send email
523537
$this->sendMail($order, $item, $step);
524538

@@ -566,8 +580,16 @@ public function sendMail($order, $secondChance, $step)
566580
'_scope_to_url' => true
567581
]);
568582

583+
// Get the expected order ID (should be pre-calculated and stored in last_order_id)
584+
$expectedOrderId = $secondChance->getLastOrderId();
585+
if (!$expectedOrderId) {
586+
$expectedOrderId = $this->setAvailableIncrementId($secondChance->getOrderId(), $order);
587+
}
588+
569589
$this->logging->addDebug('Second Chance email URL generated', [
570590
'order_id' => $order->getIncrementId(),
591+
'expected_order_id' => $expectedOrderId,
592+
'step' => $step,
571593
'store_id' => $store->getId(),
572594
'store_code' => $store->getCode(),
573595
'locale' => $store->getConfig('general/locale/code'),
@@ -592,21 +614,34 @@ public function sendMail($order, $secondChance, $step)
592614
'email' => $senderEmail,
593615
];
594616

595-
// Prepare template variables
617+
// Prepare template variables (matching original SecondChance module)
596618
try {
597619
$paymentHtml = $this->getPaymentHtml($order);
598620
$billingAddress = $this->getFormattedBillingAddress($order);
599621
$shippingAddress = $this->getFormattedShippingAddress($order);
600622

601623
$templateVars = [
602624
'order' => $order,
625+
'order_id' => $order->getId(),
626+
'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
603633
'checkout_url' => $checkoutUrl,
604634
'store' => $store,
635+
'created_at_formatted' => $order->getCreatedAtFormatted(2),
636+
'secondChanceToken' => $secondChance->getToken(),
605637
'customer_name' => $order->getCustomerName(),
606638
'customer_email' => $order->getCustomerEmail(),
607-
'payment_html' => $paymentHtml,
608-
'billing_address' => $billingAddress,
609-
'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+
]
610645
];
611646
} catch (Exception $e) {
612647
$this->logging->addError('Error preparing template variables: ' . $e->getMessage());
Lines changed: 11 additions & 0 deletions
Loading

view/frontend/email/buckaroo_second_chance_first.html

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +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",
26+
"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",
2629
"var payment_html|raw":"Payment Details",
2730
"var checkout_url":"Checkout URL",
2831
"var customer_name":"Customer Name",
29-
"var customer_email":"Customer Email"
32+
"var customer_email":"Customer Email",
33+
"var order.getShippingDescription":"Shipping Description"
3034
} @-->
3135

3236
{{template config_path="design/email/header_template"}}
@@ -48,7 +52,7 @@
4852
</tr>
4953
<tr class="email-summary">
5054
<td>
51-
<h1>{{trans 'Your Order <span class="no-link">#%increment_id</span>' increment_id=$order.increment_id |raw}}</h1>
55+
<h1>{{trans 'Your Order <span class="no-link">#%increment_id</span>' increment_id=$expected_order_id |raw}}</h1>
5256
<p>{{trans 'Order Total: %order_total' order_total=$order.formatPrice($order.getGrandTotal()) |raw}}</p>
5357
</td>
5458
</tr>
@@ -58,12 +62,12 @@ <h1>{{trans 'Your Order <span class="no-link">#%increment_id</span>' increment_i
5862
<tr>
5963
<td class="address-details">
6064
<h3>{{trans "Billing Information"}}</h3>
61-
<p>{{var billing_address|raw}}</p>
65+
<p>{{var formattedBillingAddress|raw}}</p>
6266
</td>
63-
{{depend shipping_address}}
67+
{{depend order_data.is_not_virtual}}
6468
<td class="address-details">
6569
<h3>{{trans "Shipping Information"}}</h3>
66-
<p>{{var shipping_address|raw}}</p>
70+
<p>{{var formattedShippingAddress|raw}}</p>
6771
</td>
6872
{{/depend}}
6973
</tr>
@@ -87,19 +91,7 @@ <h3>{{trans "Shipping Method"}}</h3>
8791
</a>
8892
</div>
8993

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

view/frontend/email/buckaroo_second_chance_second.html

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +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",
26+
"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",
2629
"var payment_html|raw":"Payment Details",
2730
"var checkout_url":"Checkout URL",
2831
"var customer_name":"Customer Name",
29-
"var customer_email":"Customer Email"
32+
"var customer_email":"Customer Email",
33+
"var order.getShippingDescription":"Shipping Description"
3034
} @-->
3135

3236
{{template config_path="design/email/header_template"}}
@@ -48,7 +52,7 @@
4852
</tr>
4953
<tr class="email-summary">
5054
<td>
51-
<h1 style="color: #d43f00;">{{trans 'Final Notice - Order <span class="no-link">#%increment_id</span>' increment_id=$order.increment_id |raw}}</h1>
55+
<h1 style="color: #d43f00;">{{trans 'Final Notice - Order <span class="no-link">#%increment_id</span>' increment_id=$expected_order_id |raw}}</h1>
5256
<p style="font-size: 18px; color: #d43f00; font-weight: bold;">{{trans 'Order Total: %order_total' order_total=$order.formatPrice($order.getGrandTotal()) |raw}}</p>
5357
</td>
5458
</tr>
@@ -58,12 +62,12 @@ <h1 style="color: #d43f00;">{{trans 'Final Notice - Order <span class="no-link">
5862
<tr>
5963
<td class="address-details">
6064
<h3>{{trans "Billing Information"}}</h3>
61-
<p>{{var billing_address|raw}}</p>
65+
<p>{{var formattedBillingAddress|raw}}</p>
6266
</td>
63-
{{depend shipping_address}}
67+
{{depend order_data.is_not_virtual}}
6468
<td class="address-details">
6569
<h3>{{trans "Shipping Information"}}</h3>
66-
<p>{{var shipping_address|raw}}</p>
70+
<p>{{var formattedShippingAddress|raw}}</p>
6771
</td>
6872
{{/depend}}
6973
</tr>
@@ -90,19 +94,7 @@ <h3>{{trans "Shipping Method"}}</h3>
9094
</a>
9195
</div>
9296

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

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

0 commit comments

Comments
 (0)