Skip to content

Commit 6ec3742

Browse files
committed
Resolves smartstore#713 Display gift card remaining amount in frontend order details and order messages
1 parent 02ac0a7 commit 6ec3742

6 files changed

Lines changed: 38 additions & 18 deletions

File tree

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
* Product filter: Specification attributes are sorted by display order rather than alphabetically by name
9292
* #856 Don't route topics which are excluded from sitemap
9393
* #851 Replace reCAPTCHA with "I'm not a robot" CAPTCHA
94+
* #713 Display gift card remaining amount in frontend order details and order messages
9495

9596
### Bugfixes
9697
* #523 Redirecting to payment provider performed by core instead of plugin

src/Libraries/SmartStore.Services/Messages/MessageTokenProvider.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,12 @@ protected virtual string ProductListToHtmlTable(Order order, Language language)
507507
string giftCardText = String.Format(_localizationService.GetResource("Messages.Order.GiftCardInfo", language.Id), HttpUtility.HtmlEncode(gcuh.GiftCard.GiftCardCouponCode));
508508
string giftCardAmount = _priceFormatter.FormatPrice(-(_currencyService.ConvertCurrency(gcuh.UsedValue, order.CurrencyRate)), true, order.CustomerCurrencyCode, false, language);
509509

510-
sb.AppendLine(string.Format("<tr style=\"text-align:right;\"><td>&nbsp;</td><td colspan=\"2\" style=\"padding:8px;border-top:1px solid #ddd;\"><strong>{0}</strong></td> <td style=\"padding:8px;border-top:1px solid #ddd;\">{1}</td></tr>", giftCardText, giftCardAmount));
510+
var remaining = _currencyService.ConvertCurrency(gcuh.GiftCard.GetGiftCardRemainingAmount(), order.CurrencyRate);
511+
var remainingFormatted = _priceFormatter.FormatPrice(remaining, true, false);
512+
var remainingText = _localizationService.GetResource("ShoppingCart.Totals.GiftCardInfo.Remaining", language.Id).FormatInvariant(remainingFormatted);
513+
514+
sb.AppendLine(string.Format("<tr style=\"text-align:right;\"><td>&nbsp;</td><td colspan=\"2\" style=\"padding:8px;border-top:1px solid #ddd;\"><strong>{0}</strong><br />{1}</td> <td style=\"padding:8px;border-top:1px solid #ddd;\">{2}</td></tr>",
515+
giftCardText, remainingText, giftCardAmount));
511516
}
512517

513518
//reward points
@@ -914,14 +919,18 @@ public virtual void AddReturnRequestTokens(IList<Token> tokens, ReturnRequest re
914919

915920
public virtual void AddGiftCardTokens(IList<Token> tokens, GiftCard giftCard)
916921
{
917-
tokens.Add(new Token("GiftCard.SenderName", giftCard.SenderName));
922+
var order = giftCard.PurchasedWithOrderItem.Order;
923+
var remainingAmount = _currencyService.ConvertCurrency(giftCard.GetGiftCardRemainingAmount(), order.CurrencyRate);
924+
925+
tokens.Add(new Token("GiftCard.SenderName", giftCard.SenderName));
918926
tokens.Add(new Token("GiftCard.SenderEmail", giftCard.SenderEmail));
919927
tokens.Add(new Token("GiftCard.RecipientName", giftCard.RecipientName));
920928
tokens.Add(new Token("GiftCard.RecipientEmail", giftCard.RecipientEmail));
921929
tokens.Add(new Token("GiftCard.Amount", _priceFormatter.FormatPrice(giftCard.Amount, true, false)));
922-
tokens.Add(new Token("GiftCard.CouponCode", giftCard.GiftCardCouponCode));
930+
tokens.Add(new Token("GiftCard.RemainingAmount", _priceFormatter.FormatPrice(remainingAmount, true, false)));
931+
tokens.Add(new Token("GiftCard.CouponCode", giftCard.GiftCardCouponCode));
923932

924-
var giftCardMesage = !String.IsNullOrWhiteSpace(giftCard.Message) ?
933+
var giftCardMesage = !String.IsNullOrWhiteSpace(giftCard.Message) ?
925934
HtmlUtils.FormatText(giftCard.Message, false, true, false, false, false, false) : "";
926935

927936
tokens.Add(new Token("GiftCard.Message", giftCardMesage, true));
@@ -1177,8 +1186,9 @@ public virtual string[] GetListOfAllowedTokens()
11771186
"%GiftCard.SenderEmail%",
11781187
"%GiftCard.RecipientName%",
11791188
"%GiftCard.RecipientEmail%",
1180-
"%GiftCard.Amount%",
1181-
"%GiftCard.CouponCode%",
1189+
"%GiftCard.Amount%",
1190+
"%GiftCard.RemainingAmount%",
1191+
"%GiftCard.CouponCode%",
11821192
"%GiftCard.Message%",
11831193
"%Customer.Email%",
11841194
"%Customer.Username%",

src/Presentation/SmartStore.Web/Controllers/OrderController.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,18 @@ protected OrderDetailsModel PrepareOrderDetailsModel(Order order)
291291
//gift cards
292292
foreach (var gcuh in order.GiftCardUsageHistory)
293293
{
294-
model.GiftCards.Add(new OrderDetailsModel.GiftCard
295-
{
296-
CouponCode = gcuh.GiftCard.GiftCardCouponCode,
294+
var remainingAmountBase = gcuh.GiftCard.GetGiftCardRemainingAmount();
295+
var remainingAmount = _currencyService.ConvertCurrency(remainingAmountBase, order.CurrencyRate);
296+
297+
var gcModel = new OrderDetailsModel.GiftCard
298+
{
299+
CouponCode = gcuh.GiftCard.GiftCardCouponCode,
297300
Amount = _priceFormatter.FormatPrice(-(_currencyService.ConvertCurrency(gcuh.UsedValue, order.CurrencyRate)), true, order.CustomerCurrencyCode, false, language),
298-
});
299-
}
301+
Remaining = _priceFormatter.FormatPrice(remainingAmount, true, false)
302+
};
303+
304+
model.GiftCards.Add(gcModel);
305+
}
300306

301307
//reward points
302308
if (order.RedeemedRewardPointsEntry != null)

src/Presentation/SmartStore.Web/Models/Order/OrderDetailsModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ public partial class GiftCard : ModelBase
126126
{
127127
public string CouponCode { get; set; }
128128
public string Amount { get; set; }
129-
}
129+
public string Remaining { get; set; }
130+
}
130131

131132
public partial class OrderNote : ModelBase
132133
{

src/Presentation/SmartStore.Web/Views/Order/Details.Mobile.cshtml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,9 @@
439439
{
440440
<tr>
441441
<td class="cart-total-left">
442-
<strong>
443-
@string.Format(T("Order.GiftCardInfo").Text, gc.CouponCode):</strong>
442+
<strong>@string.Format(T("Order.GiftCardInfo").Text, gc.CouponCode):</strong>
443+
<br />
444+
<span class="nobr">@string.Format(T("ShoppingCart.Totals.GiftCardInfo.Remaining").Text, gc.Remaining)</span>
444445
</td>
445446
<td class="cart-total-right">
446447
<span class="nobr">

src/Presentation/SmartStore.Web/Views/Order/Details.cshtml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -532,17 +532,18 @@
532532
{
533533
<tr>
534534
<td class="cart-total-left">
535-
<strong>
536-
@string.Format(T("Order.GiftCardInfo").Text, gc.CouponCode):</strong>
535+
<strong>@string.Format(T("Order.GiftCardInfo").Text, gc.CouponCode):</strong>
536+
<br />
537+
<span class="nobr">@string.Format(T("ShoppingCart.Totals.GiftCardInfo.Remaining").Text, gc.Remaining)</span>
537538
</td>
538539
<td class="cart-total-right">
539540
<span class="nobr">
540541
@gc.Amount
541542
</span>
542543
</td>
543544
</tr>
544-
}
545-
}
545+
}
546+
}
546547
@if (Model.RedeemedRewardPoints > 0)
547548
{
548549
<tr>

0 commit comments

Comments
 (0)