Filter unavailable items in controller

This commit is contained in:
Umar Bolatov
2021-09-12 21:45:30 -07:00
committed by Andrew Camilleri
parent c267cf0e9c
commit 2dcd7db797
3 changed files with 6 additions and 9 deletions

View File

@@ -92,7 +92,7 @@ namespace BTCPayServer.Controllers
Prefixed = new[] { 0, 2 }.Contains(numberFormatInfo.CurrencyPositivePattern), Prefixed = new[] { 0, 2 }.Contains(numberFormatInfo.CurrencyPositivePattern),
SymbolSpace = new[] { 2, 3 }.Contains(numberFormatInfo.CurrencyPositivePattern) SymbolSpace = new[] { 2, 3 }.Contains(numberFormatInfo.CurrencyPositivePattern)
}, },
Items = _AppService.Parse(settings.Template, settings.Currency), Items = _AppService.Parse(settings.Template, settings.Currency, true),
ButtonText = settings.ButtonText, ButtonText = settings.ButtonText,
CustomButtonText = settings.CustomButtonText, CustomButtonText = settings.CustomButtonText,
CustomTipText = settings.CustomTipText, CustomTipText = settings.CustomTipText,
@@ -141,7 +141,7 @@ namespace BTCPayServer.Controllers
ViewPointOfSaleViewModel.Item choice = null; ViewPointOfSaleViewModel.Item choice = null;
if (!string.IsNullOrEmpty(choiceKey)) if (!string.IsNullOrEmpty(choiceKey))
{ {
var choices = _AppService.Parse(settings.Template, settings.Currency); var choices = _AppService.Parse(settings.Template, settings.Currency, true);
choice = choices.FirstOrDefault(c => c.Id == choiceKey); choice = choices.FirstOrDefault(c => c.Id == choiceKey);
if (choice == null) if (choice == null)
return NotFound(); return NotFound();
@@ -177,7 +177,7 @@ namespace BTCPayServer.Controllers
AppService.TryParsePosCartItems(posData, out var cartItems)) AppService.TryParsePosCartItems(posData, out var cartItems))
{ {
var choices = _AppService.Parse(settings.Template, settings.Currency); var choices = _AppService.Parse(settings.Template, settings.Currency, true);
foreach (var cartItem in cartItems) foreach (var cartItem in cartItems)
{ {
var itemChoice = choices.FirstOrDefault(c => c.Id == cartItem.Key); var itemChoice = choices.FirstOrDefault(c => c.Id == cartItem.Key);
@@ -314,7 +314,7 @@ namespace BTCPayServer.Controllers
ViewPointOfSaleViewModel.Item choice = null; ViewPointOfSaleViewModel.Item choice = null;
if (!string.IsNullOrEmpty(request.ChoiceKey)) if (!string.IsNullOrEmpty(request.ChoiceKey))
{ {
var choices = _AppService.Parse(settings.PerksTemplate, settings.TargetCurrency); var choices = _AppService.Parse(settings.PerksTemplate, settings.TargetCurrency, true);
choice = choices.FirstOrDefault(c => c.Id == request.ChoiceKey); choice = choices.FirstOrDefault(c => c.Id == request.ChoiceKey);
if (choice == null) if (choice == null)
return NotFound("Incorrect option provided"); return NotFound("Incorrect option provided");

View File

@@ -311,7 +311,7 @@ namespace BTCPayServer.Services.Apps
var serializer = new SerializerBuilder().Build(); var serializer = new SerializerBuilder().Build();
return serializer.Serialize(mappingNode); return serializer.Serialize(mappingNode);
} }
public ViewPointOfSaleViewModel.Item[] Parse(string template, string currency) public ViewPointOfSaleViewModel.Item[] Parse(string template, string currency, bool filterUnavailable = false)
{ {
if (string.IsNullOrWhiteSpace(template)) if (string.IsNullOrWhiteSpace(template))
return Array.Empty<ViewPointOfSaleViewModel.Item>(); return Array.Empty<ViewPointOfSaleViewModel.Item>();
@@ -341,6 +341,7 @@ namespace BTCPayServer.Services.Apps
PaymentMethods = c.GetDetailStringList("payment_methods"), PaymentMethods = c.GetDetailStringList("payment_methods"),
Unavailable = c.GetDetailString("unavailable") == "true" Unavailable = c.GetDetailString("unavailable") == "true"
}) })
.Where(c => filterUnavailable ? !c.Unavailable : true)
.ToArray(); .ToArray();
} }

View File

@@ -26,10 +26,6 @@
: item.BuyButtonText) : item.BuyButtonText)
.Replace("{0}",item.Price.Formatted) .Replace("{0}",item.Price.Formatted)
.Replace("{Price}",item.Price.Formatted); .Replace("{Price}",item.Price.Formatted);
@if (item.Unavailable) {
continue;
}
<div class="card px-0" data-id="@x"> <div class="card px-0" data-id="@x">
@if (!String.IsNullOrWhiteSpace(item.Image)) @if (!String.IsNullOrWhiteSpace(item.Image))
{ {