Add purchasement view, bug fix

This commit is contained in:
mikgor 2018-10-28 12:32:15 +01:00
parent 934983574e
commit 625bf0d728
5 changed files with 52 additions and 5 deletions

View File

@ -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 {

View File

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

View File

@ -0,0 +1,24 @@
{{define "content"}}
<h1>Szczegóły zamówienia nr {{.purchasement.Id}}</h1>
<div class="cartItem">
<div class="cartItemColumn"><h3>Produkt</h3></div>
<div class="cartItemColumn"><h3>Ilość</h3></div>
<div class="cartItemColumn"><h3>Łącznie</h3></div>
</div>
{{range $.purchasement.Products}}
<div class="cartItem">
<div class="cartItemColumn">
<a href="/product?id={{ .Product.Id }}"><b>{{ .Product.Name }}</b>
<div class="cartItemIcon" style="background-image: url({{ .Product.ImgUrl }});"></div></a>
</div>
<div class="cartItemColumn">{{ .Quantity }}</div>
<div class="cartItemColumn">{{ .PriceTotal }} zł</div>
</div>
{{end}}
<div class="checkoutPayment">
<p>Suma: {{ .purchasement.PriceTotal }} zł</p>
<p>Kupujący: {{.purchasement.FirstName}} {{.purchasement.LastName}}</p>
<p>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}}</p>
<p>Data dostawy: {{ .purchasement.DeliveryDate }}</p>
</div>
{{end}}

View File

@ -13,7 +13,7 @@
<div class="cartItemColumn">{{.FirstName}} {{.LastName}}</div>
<div class="cartItemColumn">{{.PriceTotal}} zł</div>
<div class="cartItemColumn">{{if eq .PaymentMethod 1}}Gotówka/ karta{{end}}{{if eq .PaymentMethod 2}}Raty 0% na 24 mies.{{end}}</div>
<div class="cartItemColumn"><a href="/purchasement?id=1"><input type="button" value="Szczegóły" style="margin-bottom: 6px; background-color: #007de8;"></a></div>
<div class="cartItemColumn"><a href="/purchasement?id={{.Id}}"><input type="button" value="Szczegóły" style="margin-bottom: 6px; background-color: #007de8;"></a></div>
</div>
{{end}}

View File

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