Skip to content

Commit 5f9ee45

Browse files
fix: ensure expected order ID is correctly calculated and displayed in emails
1 parent 8bb2172 commit 5f9ee45

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

Model/SecondChanceRepository.php

Lines changed: 22 additions & 3 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,12 @@ public function getSecondChanceCollection($step, $store)
519523
continue;
520524
}
521525

526+
// 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+
}
531+
522532
// Send email
523533
$this->sendMail($order, $item, $step);
524534

@@ -566,8 +576,16 @@ public function sendMail($order, $secondChance, $step)
566576
'_scope_to_url' => true
567577
]);
568578

579+
// Get the expected order ID (should be pre-calculated and stored in last_order_id)
580+
$expectedOrderId = $secondChance->getLastOrderId();
581+
if (!$expectedOrderId) {
582+
$expectedOrderId = $this->setAvailableIncrementId($secondChance->getOrderId(), $order);
583+
}
584+
569585
$this->logging->addDebug('Second Chance email URL generated', [
570586
'order_id' => $order->getIncrementId(),
587+
'expected_order_id' => $expectedOrderId,
588+
'step' => $step,
571589
'store_id' => $store->getId(),
572590
'store_code' => $store->getCode(),
573591
'locale' => $store->getConfig('general/locale/code'),
@@ -600,6 +618,7 @@ public function sendMail($order, $secondChance, $step)
600618

601619
$templateVars = [
602620
'order' => $order,
621+
'expected_order_id' => $expectedOrderId ?: $order->getIncrementId(),
603622
'checkout_url' => $checkoutUrl,
604623
'store' => $store,
605624
'customer_name' => $order->getCustomerName(),

view/frontend/email/buckaroo_second_chance_first.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"var billing_address|raw":"Billing Address",
2424
"var shipping_address|raw":"Shipping Address",
2525
"var order.increment_id":"Order Id",
26+
"var expected_order_id":"Expected Order Id",
2627
"var payment_html|raw":"Payment Details",
2728
"var checkout_url":"Checkout URL",
2829
"var customer_name":"Customer Name",
@@ -48,7 +49,7 @@
4849
</tr>
4950
<tr class="email-summary">
5051
<td>
51-
<h1>{{trans 'Your Order <span class="no-link">#%increment_id</span>' increment_id=$order.increment_id |raw}}</h1>
52+
<h1>{{trans 'Your Order <span class="no-link">#%increment_id</span>' increment_id=$expected_order_id |raw}}</h1>
5253
<p>{{trans 'Order Total: %order_total' order_total=$order.formatPrice($order.getGrandTotal()) |raw}}</p>
5354
</td>
5455
</tr>

view/frontend/email/buckaroo_second_chance_second.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"var billing_address|raw":"Billing Address",
2424
"var shipping_address|raw":"Shipping Address",
2525
"var order.increment_id":"Order Id",
26+
"var expected_order_id":"Expected Order Id",
2627
"var payment_html|raw":"Payment Details",
2728
"var checkout_url":"Checkout URL",
2829
"var customer_name":"Customer Name",
@@ -48,7 +49,7 @@
4849
</tr>
4950
<tr class="email-summary">
5051
<td>
51-
<h1 style="color: #d43f00;">{{trans 'Final Notice - Order <span class="no-link">#%increment_id</span>' increment_id=$order.increment_id |raw}}</h1>
52+
<h1 style="color: #d43f00;">{{trans 'Final Notice - Order <span class="no-link">#%increment_id</span>' increment_id=$expected_order_id |raw}}</h1>
5253
<p style="font-size: 18px; color: #d43f00; font-weight: bold;">{{trans 'Order Total: %order_total' order_total=$order.formatPrice($order.getGrandTotal()) |raw}}</p>
5354
</td>
5455
</tr>

0 commit comments

Comments
 (0)