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"}} +

Szczegóły zamówienia nr {{.purchasement.Id}}

+
+

Produkt

+

Ilość

+

Łącznie

+
+ {{range $.purchasement.Products}} +
+
+ {{ .Product.Name }} +
+
+
{{ .Quantity }}
+
{{ .PriceTotal }} zł
+
+ {{end}} +
+

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

+
+{{end}} diff --git a/templates/purchasements.html b/templates/purchasements.html index c3dfc15..197b70e 100644 --- a/templates/purchasements.html +++ b/templates/purchasements.html @@ -13,7 +13,7 @@
{{.FirstName}} {{.LastName}}
{{.PriceTotal}} zł
{{if eq .PaymentMethod 1}}Gotówka/ karta{{end}}{{if eq .PaymentMethod 2}}Raty 0% na 24 mies.{{end}}
-
+
{{end}} diff --git a/views/views.go b/views/views.go index 88dc193..6274a6a 100644 --- a/views/views.go +++ b/views/views.go @@ -114,3 +114,13 @@ func PurchasementsView(p Page, w http.ResponseWriter, r *http.Request) { } ExecuteView(w, r, p.Template, p.Data) } + +func PurchasementView(p Page, w http.ResponseWriter, r *http.Request) { + id, err := strconv.Atoi(r.URL.Query()["id"][0]) + if err == nil { + p.Data = map[string]interface{}{ + "purchasement": GetPurchasementById(id), + } + } + ExecuteView(w, r, p.Template, p.Data) +}