PoS: Custom buy button text per product

Closes #2232.
This commit is contained in:
Dennis Reimann
2021-02-18 10:54:06 +01:00
parent b30aa968b0
commit 757c087afd
5 changed files with 20 additions and 5 deletions

View File

@@ -17,6 +17,7 @@ namespace BTCPayServer.Models.AppViewModels
public ItemPrice Price { get; set; }
public string Title { get; set; }
public bool Custom { get; set; }
public string BuyButtonText { get; set; }
public int? Inventory { get; set; } = null;
public string[] PaymentMethods { get; set; }
}

View File

@@ -321,9 +321,9 @@ namespace BTCPayServer.Services.Apps
Formatted = Currencies.FormatCurrency(cc.Value.Value, currency)
}).Single(),
Custom = c.GetDetailString("custom") == "true",
BuyButtonText = c.GetDetailString("buyButtonText"),
Inventory = string.IsNullOrEmpty(c.GetDetailString("inventory")) ? (int?)null : int.Parse(c.GetDetailString("inventory"), CultureInfo.InvariantCulture),
PaymentMethods = c.GetDetailStringList("payment_methods")
})
.ToArray();
}

View File

@@ -113,6 +113,12 @@
<input type="text" required pattern="[^\*#]+" class="form-control mb-2" v-model="editingItem.id" ref="txtId"/>
</div>
</div>
<div class="form-row">
<div class="col">
<label>Buy Button Text</label>
<input type="text" class="form-control mb-2" v-model="editingItem.buyButtonText" ref="txtBuyButtonText"/>
</div>
</div>
</div>
</div>
<div class="modal-footer">
@@ -185,7 +191,7 @@ $(function() {
var line = lines[kl],
product = line.split("\n"),
id, price, title, description, image = null,
custom, inventory=null, paymentMethods = [];
custom, buyButtonText, inventory=null, paymentMethods = [];
var goingThroughMethods = false;
for (var kp in product) {
@@ -215,6 +221,9 @@ $(function() {
if (productProperty.indexOf('custom:') !== -1) {
custom = productProperty.replace('custom:', '').trim();
}
if (productProperty.indexOf('buyButtonText:') !== -1) {
buyButtonText = productProperty.replace('buyButtonText:', '').trim();
}
if (productProperty.indexOf('inventory:') !== -1) {
inventory = parseInt(productProperty.replace('inventory:', '').trim(),10);
}
@@ -232,6 +241,7 @@ $(function() {
image: image || null,
description: description || '',
custom: custom === "true",
buyButtonText: buyButtonText,
inventory: isNaN(inventory)? null: inventory,
paymentMethods: paymentMethods
});
@@ -250,6 +260,7 @@ $(function() {
image = product.image,
description = product.description,
custom = product.custom,
buyButtonText = product.buyButtonText,
inventory = product.inventory,
paymentMethods = product.paymentMethods;
@@ -269,6 +280,9 @@ $(function() {
if (custom != null) {
template += ' custom: ' + custom + '\n';
}
if (buyButtonText != null && buyButtonText.length > 0) {
template += ' buyButtonText: ' + buyButtonText + '\n';
}
if(paymentMethods != null && paymentMethods.length > 0){
template+= ' payment_methods:\n';
for (var method of paymentMethods){

View File

@@ -65,7 +65,7 @@
</th>
</tr>
}
@if (@Model.ShowDiscount)
@if (Model.ShowDiscount)
{
<tr>
<th colspan="5" class="border-top-0">
@@ -253,7 +253,7 @@
</div>
<div class="card-footer pt-0 bg-transparent border-0">
<span class="text-muted small">@Model.ButtonText.Replace("{0}",item.Price.Formatted).Replace("{Price}",item.Price.Formatted)</span>
<span class="text-muted small">@((item.BuyButtonText ?? Model.ButtonText).Replace("{0}",item.Price.Formatted).Replace("{Price}",item.Price.Formatted))</span>
@if (item.Inventory.HasValue)
{

View File

@@ -59,7 +59,7 @@
{
<form method="post" asp-controller="AppsPublic" asp-action="ViewPointOfSale" asp-route-appId="@Model.AppId" asp-antiforgery="false">
<button type="submit" name="choiceKey" class="js-add-cart btn btn-primary" value="@item.Id">
@Model.ButtonText.Replace("{0}",item.Price.Formatted).Replace("{Price}",item.Price.Formatted)
@((item.BuyButtonText ?? Model.ButtonText).Replace("{0}",item.Price.Formatted).Replace("{Price}",item.Price.Formatted))
</button>
</form>
}