From cf7a70e145ca62d6ceae2815cc0a0754e1aeb685 Mon Sep 17 00:00:00 2001 From: mikgor Date: Sun, 28 Oct 2018 16:27:12 +0100 Subject: [PATCH] Updating items after purchasement works properly from now --- db/db.go | 5 +++++ views/views.go | 2 ++ 2 files changed, 7 insertions(+) diff --git a/db/db.go b/db/db.go index 12036bd..67ea415 100644 --- a/db/db.go +++ b/db/db.go @@ -31,3 +31,8 @@ func DbSelect(table, columns string) *sql.Rows { rows, _ := Database.Query("SELECT "+ columns +" FROM "+ table) return rows } + +func DbUpdate(table, column, columnValue, conditionValue string) { + statement, _ := Database.Prepare("UPDATE "+ table + " SET " + column + " = "+ columnValue + " WHERE id = " + conditionValue) + statement.Exec() +} diff --git a/views/views.go b/views/views.go index 6274a6a..28ca65a 100644 --- a/views/views.go +++ b/views/views.go @@ -101,9 +101,11 @@ func PaymentDoneView(p Page, w http.ResponseWriter, r *http.Request) { DbInsert("Purchasement", "priceTotal, firstName, lastName, paymentMethod, deliveryDate", "'" +strconv.Itoa(purchasement.PriceTotal) +"','"+ purchasement.FirstName + "','" + purchasement.LastName + "','" + strconv.Itoa(purchasement.PaymentMethod) + "','" + purchasement.DeliveryDate +"'") for i:= range purchasement.Products { DbInsert("PurchasementProduct", "purchasementId, productId, quantity, priceTotal", "'" +strconv.Itoa(LastPurchasementId) + "','" + strconv.Itoa(purchasement.Products[i].Product.Id) + "','" + strconv.Itoa(purchasement.Products[i].Quantity) + "','" + strconv.Itoa(purchasement.Products[i].PriceTotal) + "'") + DbUpdate("Product", "quantity", strconv.Itoa(purchasement.Products[i].Product.Quantity), strconv.Itoa(purchasement.Products[i].Product.Id)) } ShoppingCart.Products = nil ShoppingCart.Calculate() + } http.Redirect(w, r, "/purchasements", http.StatusSeeOther) }