prefil prices on edititem
All checks were successful
Go / build (push) Successful in 12m32s

This commit is contained in:
2025-04-16 02:10:11 +02:00
parent 68c8654bf3
commit 861343b338
2 changed files with 45 additions and 14 deletions

View File

@@ -472,11 +472,25 @@ func (rc *shopItemController) EditItemView(c *gin.Context) {
c.HTML(http.StatusBadRequest, "error.html", gin.H{"error": err})
}
priceBW := ""
priceColored := ""
for _, variant := range shopItem.Variants {
if variant.Name == "B/W" {
priceBW = fmt.Sprintf("%.2f", variant.Price)
}
if variant.Name == "Colored" {
priceColored = fmt.Sprintf("%.2f", variant.Price)
}
}
data := CreateSessionData(c, gin.H{
"error": "",
"success": "",
"shopItem": shopItem,
"tags": tags,
"error": "",
"success": "",
"shopItem": shopItem,
"tags": tags,
"priceBW": priceBW,
"priceColored": priceColored,
})
c.HTML(http.StatusOK, "edititem.html", data)
@@ -525,13 +539,28 @@ func (rc *shopItemController) EditItemHandler(c *gin.Context) {
return
}
priceBW := ""
priceColored := ""
for _, variant := range newShopItem.Variants {
if variant.Name == "B/W" {
priceBW = fmt.Sprintf("%.2f", variant.Price)
}
if variant.Name == "Colored" {
priceColored = fmt.Sprintf("%.2f", variant.Price)
}
}
_, err = repositories.ShopItems.Update(newShopItem)
if err != nil {
data := CreateSessionData(c, gin.H{
"error": err,
"success": "",
"shopItem": newShopItem,
"tags": tags,
"error": err,
"success": "",
"shopItem": newShopItem,
"tags": tags,
"priceBW": priceBW,
"priceColored": priceColored,
})
c.HTML(http.StatusOK, "edititem.html", data)
@@ -539,10 +568,12 @@ func (rc *shopItemController) EditItemHandler(c *gin.Context) {
}
data := CreateSessionData(c, gin.H{
"error": "",
"success": fmt.Sprintf("Item '%s' Updated", newShopItem.Name),
"shopItem": newShopItem,
"tags": tags,
"error": "",
"success": fmt.Sprintf("Item '%s' Updated", newShopItem.Name),
"shopItem": newShopItem,
"tags": tags,
"priceBW": priceBW,
"priceColored": priceColored,
})
c.HTML(http.StatusOK, "edititem.html", data)