diff --git a/initializers/initializers.go b/initializers/initializers.go index 606860d..0c6f526 100644 --- a/initializers/initializers.go +++ b/initializers/initializers.go @@ -13,6 +13,7 @@ func initializePages() { Pages["product"] = Page{"/product", "templates/product.html", map[string]interface{}{}, ProductView} Pages["cart"] = Page{"/cart", "templates/cart.html", map[string]interface{}{}, CartView} Pages["addToCart"] = Page{"/addToCart", "templates/addToCart.html", map[string]interface{}{}, AddToCartView} + Pages["removeFromCart"] = Page{"/removeFromCart", "templates/removeFromCart.html", map[string]interface{}{}, RemoveFromCartView} } func initializeData() { diff --git a/static/css/style.css b/static/css/style.css index 0463904..713a9af 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -160,7 +160,7 @@ input[type="button"] { } .cartItemColumn { - width: 25%; + width: 20%; margin: auto; } @@ -173,3 +173,8 @@ input[type="button"] { background-repeat: no-repeat; margin: auto; } + +.productUnavailable { + color: red; + font-size: 20px; +} diff --git a/templates/cart.html b/templates/cart.html index 9b01919..99f772d 100644 --- a/templates/cart.html +++ b/templates/cart.html @@ -1,10 +1,16 @@ {{define "content"}} +

Koszyk

Produkt

Cena za szt.

Ilość

Łącznie

+
{{range $.cart.Products}}
@@ -15,7 +21,8 @@
{{ .Product.Price }} zł
{{ .Quantity }}
{{ .PriceTotal }} zł
+
{{end}} - {{ .cart.PriceTotal }} zł + Wartość koszyka: {{ .cart.PriceTotal }} zł {{end}} diff --git a/templates/category.html b/templates/category.html index a7ffe92..7e18a50 100644 --- a/templates/category.html +++ b/templates/category.html @@ -3,6 +3,9 @@ {{range $.products}}
+ {{if le .Quantity 0}} +
Produkt niedostępny
+ {{end}}
{{ .Name }}
diff --git a/templates/product.html b/templates/product.html index 1623e73..eed99da 100644 --- a/templates/product.html +++ b/templates/product.html @@ -14,10 +14,16 @@ function buy() {
{{.product.Description}}

+ {{if gt .product.Quantity 0}}
Ilość sztuk:
Dostępna Ilość: {{.product.Quantity}}

+ {{end}}
Cena: {{.product.Price}} zł

+ {{if gt .product.Quantity 0}} + {{else}} +
Produkt niedostępny
+ {{end}}
diff --git a/templates/removeFromCart.html b/templates/removeFromCart.html new file mode 100644 index 0000000..e69de29 diff --git a/views/views.go b/views/views.go index f4353cc..f344bf0 100644 --- a/views/views.go +++ b/views/views.go @@ -66,3 +66,20 @@ func AddToCartView(p Page, w http.ResponseWriter, r *http.Request) { } ExecuteView(w, r, "templates/cart.html", p.Data) } + +func RemoveFromCartView(p Page, w http.ResponseWriter, r *http.Request) { + id, err := strconv.Atoi(r.URL.Query()["id"][0]) + if err == nil { + for i:= range ShoppingCart.Products { + if id == ShoppingCart.Products[i].Product.Id { + prod := GetProductById(id) + prod.Quantity += ShoppingCart.Products[i].Quantity + prod.Save() + ShoppingCart.Products = append(ShoppingCart.Products[:i], ShoppingCart.Products[i+1:]...) + break + } + } + ShoppingCart.Calculate() + } + ExecuteView(w, r, "templates/cart.html", p.Data) +}