Updating items after purchasement works properly from now
This commit is contained in:
parent
625bf0d728
commit
cf7a70e145
5
db/db.go
5
db/db.go
@ -31,3 +31,8 @@ func DbSelect(table, columns string) *sql.Rows {
|
|||||||
rows, _ := Database.Query("SELECT "+ columns +" FROM "+ table)
|
rows, _ := Database.Query("SELECT "+ columns +" FROM "+ table)
|
||||||
return rows
|
return rows
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DbUpdate(table, column, columnValue, conditionValue string) {
|
||||||
|
statement, _ := Database.Prepare("UPDATE "+ table + " SET " + column + " = "+ columnValue + " WHERE id = " + conditionValue)
|
||||||
|
statement.Exec()
|
||||||
|
}
|
||||||
|
@ -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 +"'")
|
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 {
|
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) + "'")
|
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.Products = nil
|
||||||
ShoppingCart.Calculate()
|
ShoppingCart.Calculate()
|
||||||
|
|
||||||
}
|
}
|
||||||
http.Redirect(w, r, "/purchasements", http.StatusSeeOther)
|
http.Redirect(w, r, "/purchasements", http.StatusSeeOther)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user