diff --git a/controllers/shopItemController.go b/controllers/shopItemController.go index 76973e9..5f019ed 100644 --- a/controllers/shopItemController.go +++ b/controllers/shopItemController.go @@ -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) diff --git a/views/edititem.html b/views/edititem.html index a078ab0..5a5fc37 100644 --- a/views/edititem.html +++ b/views/edititem.html @@ -75,7 +75,7 @@