Updating items after purchasement works properly from now

This commit is contained in:
mikgor 2018-10-28 16:27:12 +01:00
parent 625bf0d728
commit cf7a70e145
2 changed files with 7 additions and 0 deletions

View File

@ -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()
}

View File

@ -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)
}