diff --git a/initializers/initializers.go b/initializers/initializers.go index 09e2be7..636dbbd 100644 --- a/initializers/initializers.go +++ b/initializers/initializers.go @@ -20,6 +20,7 @@ func initializePages() { Pages["checkout"] = Page{"/checkout", "templates/checkout.html", map[string]interface{}{}, CheckoutView} Pages["purchasements"] = Page{"/purchasements", "templates/purchasements.html", map[string]interface{}{}, PurchasementsView} Pages["paymentDone"] = Page{"/paymentDone", "templates/paymentDone.html", map[string]interface{}{}, PaymentDoneView} + Pages["purchasement"] = Page{"/purchasement", "templates/purchasement.html", map[string]interface{}{}, PurchasementView} } func insertCategories() { @@ -57,11 +58,11 @@ func initializeProducts() { func initializePurchasements() { var rows *sql.Rows = DbSelect("Purchasement", "id, priceTotal, firstName, lastName, paymentMethod, deliveryDate") var rowsProducts *sql.Rows = DbSelect("PurchasementProduct", "id, purchasementId, productId, quantity, priceTotal") - var products map[int][]CartProduct + products := make(map[int][]CartProduct) for rowsProducts.Next() { - var Pid, PpurchasementId, PproductId, Pquantity, PpriceTotal int - rows.Scan(&Pid, &PpurchasementId, &PproductId, &Pquantity, &PpriceTotal) - products[PpurchasementId] = append(products[PpurchasementId], CartProduct{GetProductById(PproductId), Pquantity, PpriceTotal}) + var pid, ppurchasementId, pproductId, pquantity, ppriceTotal int + rowsProducts.Scan(&pid, &ppurchasementId, &pproductId, &pquantity, &ppriceTotal) + products[ppurchasementId] = append(products[ppurchasementId], CartProduct{GetProductById(pproductId), pquantity, ppriceTotal}) } for rows.Next() { var purchasementproducts []CartProduct @@ -70,6 +71,7 @@ func initializePurchasements() { rows.Scan(&id, &priceTotal, &firstName, &lastName, &paymentMethod, &deliveryDate) for i := range products[id]{ purchasementproducts = append(purchasementproducts, products[id][i]) + } Purchasements = append(Purchasements, Purchasement{id, purchasementproducts, priceTotal, firstName, lastName, paymentMethod, deliveryDate}) if id > LastPurchasementId { diff --git a/models/models.go b/models/models.go index 4f1d929..be63b2b 100644 --- a/models/models.go +++ b/models/models.go @@ -120,3 +120,14 @@ func GetProductById(id int) Product { } return product } + +func GetPurchasementById(id int) Purchasement { + var purchasement Purchasement + for i:= range Purchasements { + if Purchasements[i].Id == id { + purchasement = Purchasements[i] + break + } + } + return purchasement +} diff --git a/templates/purchasement.html b/templates/purchasement.html new file mode 100644 index 0000000..060ec1b --- /dev/null +++ b/templates/purchasement.html @@ -0,0 +1,24 @@ +{{define "content"}} +
Suma: {{ .purchasement.PriceTotal }} zł
+Kupujący: {{.purchasement.FirstName}} {{.purchasement.LastName}}
+Sposób płatności: {{if eq .purchasement.PaymentMethod 1}}Gotówka/ karta{{end}}{{if eq .purchasement.PaymentMethod 2}}Raty 0% na 24 mies.{{end}}
+Data dostawy: {{ .purchasement.DeliveryDate }}
+