wip checkout
This commit is contained in:
@@ -20,6 +20,7 @@ type CartItemController interface {
|
|||||||
AddItemHandler(*gin.Context)
|
AddItemHandler(*gin.Context)
|
||||||
DeleteItemHandler(*gin.Context)
|
DeleteItemHandler(*gin.Context)
|
||||||
EditItemHandler(*gin.Context)
|
EditItemHandler(*gin.Context)
|
||||||
|
CheckoutView(*gin.Context)
|
||||||
}
|
}
|
||||||
|
|
||||||
type cartItemController struct {}
|
type cartItemController struct {}
|
||||||
@@ -134,10 +135,16 @@ func (rc *cartItemController) CartItemView(c *gin.Context) {
|
|||||||
c.HTML(http.StatusBadRequest, "cart.html", gin.H{ "data": gin.H{ "error": err } })
|
c.HTML(http.StatusBadRequest, "cart.html", gin.H{ "data": gin.H{ "error": err } })
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("CARTITEMS: %v\n", cartItems)
|
priceTotal := 0.0
|
||||||
|
for _, cartItem := range cartItems {
|
||||||
|
priceTotal += (float64(cartItem.Quantity) * cartItem.ShopItem.Price)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("PRICE TOTAL", priceTotal)
|
||||||
|
|
||||||
data := CreateSessionData(c, gin.H{
|
data := CreateSessionData(c, gin.H{
|
||||||
"cartItems": cartItems,
|
"cartItems": cartItems,
|
||||||
|
"priceTotal": fmt.Sprintf("%.2f", priceTotal), //round 2 decimals
|
||||||
})
|
})
|
||||||
|
|
||||||
c.HTML(http.StatusOK, "cart.html", data)
|
c.HTML(http.StatusOK, "cart.html", data)
|
||||||
@@ -187,7 +194,6 @@ func (rc *cartItemController) EditItemHandler(c *gin.Context) {
|
|||||||
cartItem, err := repositories.CartItems.GetById(cartItemId)
|
cartItem, err := repositories.CartItems.GetById(cartItemId)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("BLAA")
|
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
rc.CartItemView(c)
|
rc.CartItemView(c)
|
||||||
return
|
return
|
||||||
@@ -210,9 +216,12 @@ func (rc *cartItemController) EditItemHandler(c *gin.Context) {
|
|||||||
_, err = repositories.CartItems.Update(cartItem)
|
_, err = repositories.CartItems.Update(cartItem)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("BLUB")
|
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
rc.CartItemView(c)
|
rc.CartItemView(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (rc *cartItemController) CheckoutView(c *gin.Context) {
|
||||||
|
c.HTML(http.StatusOK, "checkout.html", gin.H{})
|
||||||
|
}
|
||||||
|
|||||||
1
main.go
1
main.go
@@ -89,6 +89,7 @@ func main() {
|
|||||||
viewRoutes.POST("/cart", cartItemController.AddItemHandler)
|
viewRoutes.POST("/cart", cartItemController.AddItemHandler)
|
||||||
viewRoutes.POST("/cart/delete", cartItemController.DeleteItemHandler)
|
viewRoutes.POST("/cart/delete", cartItemController.DeleteItemHandler)
|
||||||
viewRoutes.POST("/cart/edit", cartItemController.EditItemHandler)
|
viewRoutes.POST("/cart/edit", cartItemController.EditItemHandler)
|
||||||
|
viewRoutes.GET("/checkout", cartItemController.CheckoutView)
|
||||||
|
|
||||||
//write middleware that redirects to homescreen on register/login/reset for logged in users
|
//write middleware that redirects to homescreen on register/login/reset for logged in users
|
||||||
viewRoutes.GET("/login", userController.LoginView)
|
viewRoutes.GET("/login", userController.LoginView)
|
||||||
|
|||||||
@@ -847,10 +847,6 @@ video {
|
|||||||
margin-bottom: calc(1.5rem * var(--tw-space-y-reverse));
|
margin-bottom: calc(1.5rem * var(--tw-space-y-reverse));
|
||||||
}
|
}
|
||||||
|
|
||||||
.whitespace-nowrap {
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
.rounded {
|
.rounded {
|
||||||
border-radius: 0.25rem;
|
border-radius: 0.25rem;
|
||||||
}
|
}
|
||||||
@@ -946,11 +942,6 @@ video {
|
|||||||
background-color: rgb(22 163 74 / var(--tw-bg-opacity, 1));
|
background-color: rgb(22 163 74 / var(--tw-bg-opacity, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
.bg-indigo-50 {
|
|
||||||
--tw-bg-opacity: 1;
|
|
||||||
background-color: rgb(238 242 255 / var(--tw-bg-opacity, 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
.bg-indigo-600 {
|
.bg-indigo-600 {
|
||||||
--tw-bg-opacity: 1;
|
--tw-bg-opacity: 1;
|
||||||
background-color: rgb(79 70 229 / var(--tw-bg-opacity, 1));
|
background-color: rgb(79 70 229 / var(--tw-bg-opacity, 1));
|
||||||
@@ -1040,11 +1031,6 @@ video {
|
|||||||
padding-bottom: 0.5rem;
|
padding-bottom: 0.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.py-2\.5 {
|
|
||||||
padding-top: 0.625rem;
|
|
||||||
padding-bottom: 0.625rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.py-24 {
|
.py-24 {
|
||||||
padding-top: 6rem;
|
padding-top: 6rem;
|
||||||
padding-bottom: 6rem;
|
padding-bottom: 6rem;
|
||||||
@@ -1339,11 +1325,6 @@ video {
|
|||||||
background-color: rgb(21 128 61 / var(--tw-bg-opacity, 1));
|
background-color: rgb(21 128 61 / var(--tw-bg-opacity, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
.hover\:bg-indigo-100:hover {
|
|
||||||
--tw-bg-opacity: 1;
|
|
||||||
background-color: rgb(224 231 255 / var(--tw-bg-opacity, 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
.hover\:bg-indigo-500:hover {
|
.hover\:bg-indigo-500:hover {
|
||||||
--tw-bg-opacity: 1;
|
--tw-bg-opacity: 1;
|
||||||
background-color: rgb(99 102 241 / var(--tw-bg-opacity, 1));
|
background-color: rgb(99 102 241 / var(--tw-bg-opacity, 1));
|
||||||
|
|||||||
@@ -31,9 +31,9 @@
|
|||||||
<p class="font-normal text-base leading-7 text-gray-500 mb-6">
|
<p class="font-normal text-base leading-7 text-gray-500 mb-6">
|
||||||
{{ .ShopItem.Abstract }}
|
{{ .ShopItem.Abstract }}
|
||||||
</p>
|
</p>
|
||||||
|
<form action="/cart/edit" method="POST">
|
||||||
<div class="flex justify-between items-center">
|
<div class="flex justify-between items-center">
|
||||||
<div class="flex items-center gap-4">
|
<div class="flex items-center gap-4">
|
||||||
<form action="/cart/edit" method="POST">
|
|
||||||
<input type="hidden" id="{{ .ID }}" name="id" value="{{ .ID }}">
|
<input type="hidden" id="{{ .ID }}" name="id" value="{{ .ID }}">
|
||||||
<button type="submit" name="action" value="decrease"
|
<button type="submit" name="action" value="decrease"
|
||||||
class="group rounded-[50px] border border-gray-200 shadow-sm shadow-transparent p-2.5 flex items-center justify-center bg-white transition-all duration-500 hover:shadow-gray-200 hover:bg-gray-50 hover:border-gray-300 focus-within:outline-gray-300">
|
class="group rounded-[50px] border border-gray-200 shadow-sm shadow-transparent p-2.5 flex items-center justify-center bg-white transition-all duration-500 hover:shadow-gray-200 hover:bg-gray-50 hover:border-gray-300 focus-within:outline-gray-300">
|
||||||
@@ -54,11 +54,11 @@
|
|||||||
stroke-linecap="round" stroke-linejoin="round" />
|
stroke-linecap="round" stroke-linejoin="round" />
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
|
</div>
|
||||||
|
<h6 class="text-indigo-600 font-manrope font-bold text-2xl leading-9 text-right">{{ .Quantity}} x {{ .ShopItem.Price }}€</h6>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<h6 class="text-indigo-600 font-manrope font-bold text-2xl leading-9 text-right">{{ .ShopItem.Price }}€</h6>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
@@ -69,18 +69,13 @@
|
|||||||
<h5 class="text-gray-900 font-manrope font-semibold text-2xl leading-9 w-full max-md:text-center max-md:mb-4">Subtotal</h5>
|
<h5 class="text-gray-900 font-manrope font-semibold text-2xl leading-9 w-full max-md:text-center max-md:mb-4">Subtotal</h5>
|
||||||
|
|
||||||
<div class="flex items-center justify-between gap-5 ">
|
<div class="flex items-center justify-between gap-5 ">
|
||||||
<button
|
<h6 class="font-manrope font-bold text-3xl lead-10 text-indigo-600">{{ .data.priceTotal }}€</h6>
|
||||||
class="rounded-full py-2.5 px-3 bg-indigo-50 text-indigo-600 font-semibold text-xs text-center whitespace-nowrap transition-all duration-500 hover:bg-indigo-100">Promo
|
|
||||||
Code?</button>
|
|
||||||
<h6 class="font-manrope font-bold text-3xl lead-10 text-indigo-600">$440</h6>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="max-lg:max-w-lg max-lg:mx-auto">
|
<div class="max-lg:max-w-lg max-lg:mx-auto">
|
||||||
<p class="font-normal text-base leading-7 text-gray-500 text-center mb-5 mt-6">Shipping taxes, and discounts
|
<p class="font-normal text-base leading-7 text-gray-500 text-center mb-5 mt-6">Shipping calculated at checkout</p>
|
||||||
calculated
|
<a href="/checkout"
|
||||||
at checkout</p>
|
class="rounded-full py-4 px-6 bg-indigo-600 text-white font-semibold text-lg w-full text-center transition-all duration-500 hover:bg-indigo-700 ">Checkout</a>
|
||||||
<button
|
|
||||||
class="rounded-full py-4 px-6 bg-indigo-600 text-white font-semibold text-lg w-full text-center transition-all duration-500 hover:bg-indigo-700 ">Checkout</button>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
101
views/checkout.html
Normal file
101
views/checkout.html
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
{{ template "header.html" . }}
|
||||||
|
|
||||||
|
<div class="flex min-h-full flex-col justify-center px-6 py-12 lg:px-8">
|
||||||
|
<div class="sm:mx-auto sm:w-full sm:max-w-sm">
|
||||||
|
<img class="mx-auto h-10 w-auto" src="/static/img/circlea.png" alt="Your Company">
|
||||||
|
<h2 class="mt-10 text-center text-2xl/9 font-bold tracking-tight text-gray-900">Checkout</h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="mt-10 sm:mx-auto sm:w-full sm:max-w-sm">
|
||||||
|
<form class="space-y-6" action="#" method="POST" enctype="multipart/form-data">
|
||||||
|
<div>
|
||||||
|
<label for="name" class="block text-sm/6 font-medium text-gray-900">First Name</label>
|
||||||
|
<div class="mt-2">
|
||||||
|
<input type="text" name="firstname" id="firstname" required class="block w-full rounded-md bg-white px-3 py-1.5 text-base text-gray-900 outline outline-1 -outline-offset-1 outline-gray-300 placeholder:text-gray-400 focus:outline focus:outline-2 focus:-outline-offset-2 focus:outline-indigo-600 sm:text-sm/6">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="lastname" class="block text-sm/6 font-medium text-gray-900">Last Name</label>
|
||||||
|
<div class="mt-2">
|
||||||
|
<input type="text" name="lastname" id="lastname" required class="block w-full rounded-md bg-white px-3 py-1.5 text-base text-gray-900 outline outline-1 -outline-offset-1 outline-gray-300 placeholder:text-gray-400 focus:outline focus:outline-2 focus:-outline-offset-2 focus:outline-indigo-600 sm:text-sm/6">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="Address" class="block text-sm/6 font-medium text-gray-900">Streetname and Number</label>
|
||||||
|
<div class="mt-2">
|
||||||
|
<input type="text" name="address" id="address" required class="block w-full rounded-md bg-white px-3 py-1.5 text-base text-gray-900 outline outline-1 -outline-offset-1 outline-gray-300 placeholder:text-gray-400 focus:outline focus:outline-2 focus:-outline-offset-2 focus:outline-indigo-600 sm:text-sm/6">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="lastname" class="block text-sm/6 font-medium text-gray-900">Postal Code</label>
|
||||||
|
<div class="mt-2">
|
||||||
|
<input type="text" name="lastname" id="lastname" required class="block w-full rounded-md bg-white px-3 py-1.5 text-base text-gray-900 outline outline-1 -outline-offset-1 outline-gray-300 placeholder:text-gray-400 focus:outline focus:outline-2 focus:-outline-offset-2 focus:outline-indigo-600 sm:text-sm/6">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="lastname" class="block text-sm/6 font-medium text-gray-900">City</label>
|
||||||
|
<div class="mt-2">
|
||||||
|
<input type="text" name="lastname" id="lastname" required class="block w-full rounded-md bg-white px-3 py-1.5 text-base text-gray-900 outline outline-1 -outline-offset-1 outline-gray-300 placeholder:text-gray-400 focus:outline focus:outline-2 focus:-outline-offset-2 focus:outline-indigo-600 sm:text-sm/6">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="lastname" class="block text-sm/6 font-medium text-gray-900">Country</label>
|
||||||
|
<div class="mt-2">
|
||||||
|
<input type="text" name="lastname" id="lastname" required class="block w-full rounded-md bg-white px-3 py-1.5 text-base text-gray-900 outline outline-1 -outline-offset-1 outline-gray-300 placeholder:text-gray-400 focus:outline focus:outline-2 focus:-outline-offset-2 focus:outline-indigo-600 sm:text-sm/6">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="lastname" class="block text-sm/6 font-medium text-gray-900">E-Mail</label>
|
||||||
|
<div class="mt-2">
|
||||||
|
<input type="text" name="lastname" id="lastname" required class="block w-full rounded-md bg-white px-3 py-1.5 text-base text-gray-900 outline outline-1 -outline-offset-1 outline-gray-300 placeholder:text-gray-400 focus:outline focus:outline-2 focus:-outline-offset-2 focus:outline-indigo-600 sm:text-sm/6">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="description" class="block text-sm/6 font-medium text-gray-900" for="passwordConfirmation">Comment</label>
|
||||||
|
<textarea id="description" name="description" type="textarea" class="block w-full px-4 py-2 mt-2 text-gray-700 bg-white border border-gray-300 rounded-md dark:bg-gray-800 dark:text-gray-300 dark:border-gray-600 focus:border-blue-500 dark:focus:border-blue-500 focus:outline-none focus:ring"></textarea>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-4">
|
||||||
|
<label class="block text-sm/6 text-gray-900">Shipping</label>
|
||||||
|
<div class="space-y-2">
|
||||||
|
<label class="flex text-sm/6 items-center">
|
||||||
|
<input type="checkbox" class="form-checkbox h-4 w-4 text-gray-900" value="{{ .ID }}" name="shipping">
|
||||||
|
<span class="ml-2 text-sm/6 text-gray-900">Germany</span>
|
||||||
|
<input type="checkbox" class="form-checkbox h-4 w-4 text-gray-900" value="{{ .ID }}" name="shipping">
|
||||||
|
<span class="ml-2 text-sm/6 text-gray-900">International</span>
|
||||||
|
<input type="checkbox" class="form-checkbox h-4 w-4 text-gray-900" value="{{ .ID }}" name="shipping">
|
||||||
|
<span class="ml-2 text-sm/6 text-gray-900">Pickup</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p class="mt-10 text-center text-sm/6 text-red-500">
|
||||||
|
{{ .data.error }}
|
||||||
|
</p>
|
||||||
|
<p class="mt-10 text-center text-sm/6 text-green-500">
|
||||||
|
{{ .data.success }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<button type="submit" class="flex w-full justify-center rounded-md bg-indigo-600 px-3 py-1.5 text-sm/6 font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600">Preview Order</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
{{ template "footer.html" . }}
|
||||||
Reference in New Issue
Block a user