diff --git a/controllers/cartItemController.go b/controllers/cartItemController.go index 8ff1f0f..88fba99 100644 --- a/controllers/cartItemController.go +++ b/controllers/cartItemController.go @@ -147,14 +147,20 @@ func (rc *cartItemController) NewOrderFromForm(ctx *gin.Context) (models.Order, token := GenerateToken() email := ctx.PostForm("email") comment := ctx.PostForm("comment") + firstName := ctx.PostForm("firstName") + lastName := ctx.PostForm("lastName") + address := ctx.PostForm("address") + postalCode := ctx.PostForm("postalCode") + city := ctx.PostForm("city") + country := ctx.PostForm("country") shippingStr := ctx.PostForm("shippingMethod") - address, err := rc.NewAddressFromForm(ctx) - if shippingStr != "pickup" { - if err != nil { - return models.Order{}, fmt.Errorf("Invalid address information.") - } - } + //address, err := rc.NewAddressFromForm(ctx) + //if shippingStr != "pickup" { + // if err != nil { + // return models.Order{}, fmt.Errorf("Invalid address information.") + // } + //} var shipping models.Shipping for _, shippingMethod := range GetShippingMethods() { @@ -168,6 +174,8 @@ func (rc *cartItemController) NewOrderFromForm(ctx *gin.Context) (models.Order, } cartItems, err := repositories.CartItems.GetAllBySession(sessionId) + fmt.Println(sessionId) + fmt.Println(cartItems) if err != nil { return models.Order{}, err @@ -179,8 +187,13 @@ func (rc *cartItemController) NewOrderFromForm(ctx *gin.Context) (models.Order, Token: token, Email: email, Comment: comment, + FirstName: firstName, + LastName: lastName, Address: address, - Shipping: shipping, + PostalCode: postalCode, + City: city, + Country: country, + Shipping: shipping.Id, CartItems: cartItems, } @@ -363,13 +376,33 @@ func (rc *cartItemController) CheckoutHandler(c *gin.Context) { return } + + var shipping models.Shipping + for _, shippingMethod := range GetShippingMethods() { + if shippingMethod.Id == order.Shipping { + shipping = shippingMethod + } + } + + priceProducts := 0.0 + for _, cartItem := range order.CartItems { + priceProducts += (float64(cartItem.Quantity) * cartItem.ItemVariant.Price) + } + + priceTotal := priceProducts + shipping.Price + data := CreateSessionData(c, gin.H{ "error": "", "success": "", "order": order, + "askAddress": (order.Shipping != "pickup"), "isPreview": true, + "shipping": shipping, + "priceProducts": fmt.Sprintf("%.2f", priceProducts), //round 2 decimals + "priceTotal": fmt.Sprintf("%.2f", priceTotal), //round 2 decimals }) + fmt.Println(order) c.HTML(http.StatusOK, "order.html", data) } diff --git a/models/cart.go b/models/cart.go index 06f809f..4bfc04b 100644 --- a/models/cart.go +++ b/models/cart.go @@ -37,9 +37,14 @@ type Order struct { Token string `json:"token" binding:"required" gorm:"not null"` Email string `json:"email"` Comment string `json:"comment"` - Address AddressInfo `json:"addressinfo"` - Shipping Shipping `json:"shipping"` - CartItems []CartItem `json:"cartitems"` + FirstName string `json:"firstname"` + LastName string `json:"lastname"` + Address string `json:"address"` + PostalCode string `json:"postalcode"` + City string `json:"city"` + Country string `json:"country"` + Shipping string `json:"shipping"` + CartItems []CartItem `json:"cartitems" gorm:"foreignKey:OrderID"` } type CartItem struct { @@ -50,5 +55,5 @@ type CartItem struct { ItemVariantId uint ItemVariant ItemVariant `json:"itemvariant" gorm:"foreignKey:ItemVariantId"` //gorm one2one Quantity int `json:"quantity" binding:"required"` - OrderId uint + OrderID uint } diff --git a/repositories/cartItemRepository.go b/repositories/cartItemRepository.go index 8439785..39d3d16 100644 --- a/repositories/cartItemRepository.go +++ b/repositories/cartItemRepository.go @@ -63,7 +63,7 @@ func (t *GORMCartItemRepository) GetById(id string) (models.CartItem, error) { func (r *GORMCartItemRepository) GetAllBySession(sessionId string) ([]models.CartItem, error) { var cartItems []models.CartItem - result := r.DB.Preload("ShopItem").Where("session_id = ?", sessionId).Find(&cartItems) + result := r.DB.Preload("ShopItem").Preload("ItemVariant").Where("session_id = ?", sessionId).Find(&cartItems) return cartItems, result.Error diff --git a/static/output.css b/static/output.css index 28f6c8b..4f280d1 100644 --- a/static/output.css +++ b/static/output.css @@ -107,7 +107,7 @@ } /* -! tailwindcss v3.4.16 | MIT License | https://tailwindcss.com +! tailwindcss v3.4.17 | MIT License | https://tailwindcss.com */ /* @@ -566,6 +566,14 @@ video { border-width: 0; } +.invisible { + visibility: hidden; +} + +.fixed { + position: fixed; +} + .absolute { position: absolute; } @@ -587,6 +595,26 @@ video { right: 0px; } +.left-0 { + left: 0px; +} + +.top-0 { + top: 0px; +} + +.z-10 { + z-index: 10; +} + +.z-20 { + z-index: 20; +} + +.z-50 { + z-index: 50; +} + .col-span-12 { grid-column: span 12 / span 12; } @@ -670,14 +698,42 @@ video { margin-top: 1.5rem; } +.-me-0\.5 { + margin-inline-end: -0.125rem; +} + +.me-2 { + margin-inline-end: 0.5rem; +} + +.ms-2 { + margin-inline-start: 0.5rem; +} + +.ms-auto { + margin-inline-start: auto; +} + .block { display: block; } +.inline-block { + display: inline-block; +} + .flex { display: flex; } +.inline-flex { + display: inline-flex; +} + +.table { + display: table; +} + .grid { display: grid; } @@ -718,6 +774,22 @@ video { height: 100%; } +.h-3 { + height: 0.75rem; +} + +.h-\[calc\(100\%-1rem\)\] { + height: calc(100% - 1rem); +} + +.h-auto { + height: auto; +} + +.max-h-full { + max-height: 100%; +} + .min-h-full { min-height: 100%; } @@ -746,6 +818,18 @@ video { width: 100%; } +.w-3 { + width: 0.75rem; +} + +.w-56 { + width: 14rem; +} + +.w-8 { + width: 2rem; +} + .max-w-2xl { max-width: 42rem; } @@ -762,6 +846,18 @@ video { max-width: 28rem; } +.max-w-3xl { + max-width: 48rem; +} + +.max-w-lg { + max-width: 32rem; +} + +.max-w-screen-xl { + max-width: 1280px; +} + .flex-1 { flex: 1 1 0%; } @@ -786,10 +882,18 @@ video { grid-template-columns: repeat(12, minmax(0, 1fr)); } +.grid-cols-2 { + grid-template-columns: repeat(2, minmax(0, 1fr)); +} + .flex-col { flex-direction: column; } +.items-start { + align-items: flex-start; +} + .items-center { align-items: center; } @@ -810,6 +914,14 @@ video { gap: 1.25rem; } +.gap-1 { + gap: 0.25rem; +} + +.gap-2 { + gap: 0.5rem; +} + .gap-x-6 { -moz-column-gap: 1.5rem; column-gap: 1.5rem; @@ -847,6 +959,44 @@ video { margin-bottom: calc(1.5rem * var(--tw-space-y-reverse)); } +.space-y-4 > :not([hidden]) ~ :not([hidden]) { + --tw-space-y-reverse: 0; + margin-top: calc(1rem * calc(1 - var(--tw-space-y-reverse))); + margin-bottom: calc(1rem * var(--tw-space-y-reverse)); +} + +.divide-y > :not([hidden]) ~ :not([hidden]) { + --tw-divide-y-reverse: 0; + border-top-width: calc(1px * calc(1 - var(--tw-divide-y-reverse))); + border-bottom-width: calc(1px * var(--tw-divide-y-reverse)); +} + +.divide-gray-100 > :not([hidden]) ~ :not([hidden]) { + --tw-divide-opacity: 1; + border-color: rgb(243 244 246 / var(--tw-divide-opacity, 1)); +} + +.divide-gray-200 > :not([hidden]) ~ :not([hidden]) { + --tw-divide-opacity: 1; + border-color: rgb(229 231 235 / var(--tw-divide-opacity, 1)); +} + +.overflow-x-auto { + overflow-x: auto; +} + +.overflow-y-auto { + overflow-y: auto; +} + +.overflow-x-hidden { + overflow-x: hidden; +} + +.whitespace-nowrap { + white-space: nowrap; +} + .rounded { border-radius: 0.25rem; } @@ -876,6 +1026,21 @@ video { border-bottom-left-radius: 0.375rem; } +.rounded-e-lg { + border-start-end-radius: 0.5rem; + border-end-end-radius: 0.5rem; +} + +.rounded-s-lg { + border-start-start-radius: 0.5rem; + border-end-start-radius: 0.5rem; +} + +.rounded-t { + border-top-left-radius: 0.25rem; + border-top-right-radius: 0.25rem; +} + .border { border-width: 1px; } @@ -888,6 +1053,14 @@ video { border-bottom-width: 1px; } +.border-s-0 { + border-inline-start-width: 0px; +} + +.border-t { + border-top-width: 1px; +} + .border-dashed { border-style: dashed; } @@ -967,6 +1140,10 @@ video { background-color: rgb(255 255 255 / var(--tw-bg-opacity, 1)); } +.bg-transparent { + background-color: transparent; +} + .fill-red-50 { fill: #fef2f2; } @@ -1051,6 +1228,16 @@ video { padding-bottom: 2rem; } +.px-5 { + padding-left: 1.25rem; + padding-right: 1.25rem; +} + +.py-2\.5 { + padding-top: 0.625rem; + padding-bottom: 0.625rem; +} + .pb-3 { padding-bottom: 0.75rem; } @@ -1075,6 +1262,14 @@ video { padding-top: 1.25rem; } +.pt-4 { + padding-top: 1rem; +} + +.text-left { + text-align: left; +} + .text-center { text-align: center; } @@ -1133,6 +1328,11 @@ video { line-height: 1rem; } +.text-xl { + font-size: 1.25rem; + line-height: 1.75rem; +} + .font-bold { font-weight: 700; } @@ -1225,12 +1425,36 @@ video { color: rgb(255 255 255 / var(--tw-text-opacity, 1)); } +.text-gray-400 { + --tw-text-opacity: 1; + color: rgb(156 163 175 / var(--tw-text-opacity, 1)); +} + +.underline { + text-decoration-line: underline; +} + +.antialiased { + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +.opacity-0 { + opacity: 0; +} + .shadow-sm { --tw-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); --tw-shadow-colored: 0 1px 2px 0 var(--tw-shadow-color); box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow); } +.shadow { + --tw-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1); + --tw-shadow-colored: 0 1px 3px 0 var(--tw-shadow-color), 0 1px 2px -1px var(--tw-shadow-color); + box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow); +} + .shadow-transparent { --tw-shadow-color: transparent; --tw-shadow: var(--tw-shadow-colored); @@ -1252,16 +1476,30 @@ video { outline-color: #d1d5db; } +.filter { + filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow); +} + .transition-all { transition-property: all; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); transition-duration: 150ms; } +.transition-opacity { + transition-property: opacity; + transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); + transition-duration: 150ms; +} + .duration-500 { transition-duration: 500ms; } +.duration-300 { + transition-duration: 300ms; +} + .placeholder\:text-gray-400::-moz-placeholder { --tw-text-opacity: 1; color: rgb(156 163 175 / var(--tw-text-opacity, 1)); @@ -1350,6 +1588,16 @@ video { background-color: rgb(127 29 29 / var(--tw-bg-opacity, 1)); } +.hover\:bg-gray-100:hover { + --tw-bg-opacity: 1; + background-color: rgb(243 244 246 / var(--tw-bg-opacity, 1)); +} + +.hover\:bg-gray-200:hover { + --tw-bg-opacity: 1; + background-color: rgb(229 231 235 / var(--tw-bg-opacity, 1)); +} + .hover\:text-indigo-500:hover { --tw-text-opacity: 1; color: rgb(99 102 241 / var(--tw-text-opacity, 1)); @@ -1360,11 +1608,28 @@ video { color: rgb(255 255 255 / var(--tw-text-opacity, 1)); } +.hover\:text-gray-900:hover { + --tw-text-opacity: 1; + color: rgb(17 24 39 / var(--tw-text-opacity, 1)); +} + +.hover\:underline:hover { + text-decoration-line: underline; +} + +.hover\:no-underline:hover { + text-decoration-line: none; +} + .hover\:shadow-gray-200:hover { --tw-shadow-color: #e5e7eb; --tw-shadow: var(--tw-shadow-colored); } +.focus\:z-10:focus { + z-index: 10; +} + .focus\:border-blue-500:focus { --tw-border-opacity: 1; border-color: rgb(59 130 246 / var(--tw-border-opacity, 1)); @@ -1397,11 +1662,28 @@ video { box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000); } +.focus\:ring-2:focus { + --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color); + --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color); + box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000); +} + +.focus\:ring-4:focus { + --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color); + --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(4px + var(--tw-ring-offset-width)) var(--tw-ring-color); + box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000); +} + .focus\:ring-blue-500:focus { --tw-ring-opacity: 1; --tw-ring-color: rgb(59 130 246 / var(--tw-ring-opacity, 1)); } +.focus\:ring-gray-100:focus { + --tw-ring-opacity: 1; + --tw-ring-color: rgb(243 244 246 / var(--tw-ring-opacity, 1)); +} + .focus-visible\:outline:focus-visible { outline-style: solid; } @@ -1468,6 +1750,10 @@ video { inset: auto; } + .sm\:col-span-2 { + grid-column: span 2 / span 2; + } + .sm\:mx-auto { margin-left: auto; margin-right: auto; @@ -1477,10 +1763,22 @@ video { margin-left: 1.5rem; } + .sm\:mt-0 { + margin-top: 0px; + } + + .sm\:mt-8 { + margin-top: 2rem; + } + .sm\:block { display: block; } + .sm\:flex { + display: flex; + } + .sm\:hidden { display: none; } @@ -1497,6 +1795,10 @@ video { grid-template-columns: repeat(2, minmax(0, 1fr)); } + .sm\:items-center { + align-items: center; + } + .sm\:px-6 { padding-left: 1.5rem; padding-right: 1.5rem; @@ -1520,13 +1822,30 @@ video { font-size: 0.875rem; line-height: 1.5rem; } + + .sm\:text-2xl { + font-size: 1.5rem; + line-height: 2rem; + } } @media (min-width: 768px) { + .md\:inset-0 { + inset: 0px; + } + + .md\:w-\[384px\] { + width: 384px; + } + .md\:flex-1 { flex: 1 1 0%; } + .md\:table-fixed { + table-layout: fixed; + } + .md\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } @@ -1539,10 +1858,23 @@ video { align-items: center; } + .md\:p-5 { + padding: 1.25rem; + } + .md\:px-5 { padding-left: 1.25rem; padding-right: 1.25rem; } + + .md\:py-16 { + padding-top: 4rem; + padding-bottom: 4rem; + } + + .md\:pt-5 { + padding-top: 1.25rem; + } } @media (min-width: 1024px) { @@ -1608,12 +1940,47 @@ video { } } +@media (min-width: 1536px) { + .\32xl\:px-0 { + padding-left: 0px; + padding-right: 0px; + } +} + @media (prefers-color-scheme: dark) { + .dark\:block { + display: block; + } + + .dark\:hidden { + display: none; + } + + .dark\:divide-gray-800 > :not([hidden]) ~ :not([hidden]) { + --tw-divide-opacity: 1; + border-color: rgb(31 41 55 / var(--tw-divide-opacity, 1)); + } + .dark\:border-gray-600 { --tw-border-opacity: 1; border-color: rgb(75 85 99 / var(--tw-border-opacity, 1)); } + .dark\:border-gray-700 { + --tw-border-opacity: 1; + border-color: rgb(55 65 81 / var(--tw-border-opacity, 1)); + } + + .dark\:border-gray-800 { + --tw-border-opacity: 1; + border-color: rgb(31 41 55 / var(--tw-border-opacity, 1)); + } + + .dark\:border-s-gray-700 { + --tw-border-opacity: 1; + border-inline-start-color: rgb(55 65 81 / var(--tw-border-opacity, 1)); + } + .dark\:bg-gray-600 { --tw-bg-opacity: 1; background-color: rgb(75 85 99 / var(--tw-bg-opacity, 1)); @@ -1634,6 +2001,11 @@ video { background-color: rgb(220 38 38 / var(--tw-bg-opacity, 1)); } + .dark\:bg-gray-900 { + --tw-bg-opacity: 1; + background-color: rgb(17 24 39 / var(--tw-bg-opacity, 1)); + } + .dark\:text-gray-300 { --tw-text-opacity: 1; color: rgb(209 213 219 / var(--tw-text-opacity, 1)); @@ -1649,6 +2021,21 @@ video { color: rgb(255 255 255 / var(--tw-text-opacity, 1)); } + .dark\:text-gray-200 { + --tw-text-opacity: 1; + color: rgb(229 231 235 / var(--tw-text-opacity, 1)); + } + + .dark\:text-gray-400 { + --tw-text-opacity: 1; + color: rgb(156 163 175 / var(--tw-text-opacity, 1)); + } + + .dark\:text-gray-500 { + --tw-text-opacity: 1; + color: rgb(107 114 128 / var(--tw-text-opacity, 1)); + } + .dark\:placeholder-gray-400::-moz-placeholder { --tw-placeholder-opacity: 1; color: rgb(156 163 175 / var(--tw-placeholder-opacity, 1)); @@ -1659,6 +2046,20 @@ video { color: rgb(156 163 175 / var(--tw-placeholder-opacity, 1)); } + .dark\:ring-offset-gray-800 { + --tw-ring-offset-color: #1f2937; + } + + .dark\:placeholder\:text-gray-400::-moz-placeholder { + --tw-text-opacity: 1; + color: rgb(156 163 175 / var(--tw-text-opacity, 1)); + } + + .dark\:placeholder\:text-gray-400::placeholder { + --tw-text-opacity: 1; + color: rgb(156 163 175 / var(--tw-text-opacity, 1)); + } + .dark\:hover\:bg-gray-600:hover { --tw-bg-opacity: 1; background-color: rgb(75 85 99 / var(--tw-bg-opacity, 1)); @@ -1669,6 +2070,11 @@ video { background-color: rgb(55 65 81 / var(--tw-bg-opacity, 1)); } + .dark\:hover\:text-white:hover { + --tw-text-opacity: 1; + color: rgb(255 255 255 / var(--tw-text-opacity, 1)); + } + .dark\:focus\:border-blue-500:focus { --tw-border-opacity: 1; border-color: rgb(59 130 246 / var(--tw-border-opacity, 1)); @@ -1678,4 +2084,9 @@ video { --tw-ring-opacity: 1; --tw-ring-color: rgb(59 130 246 / var(--tw-ring-opacity, 1)); } + + .dark\:focus\:ring-gray-700:focus { + --tw-ring-opacity: 1; + --tw-ring-color: rgb(55 65 81 / var(--tw-ring-opacity, 1)); + } } diff --git a/views/checkout.html b/views/checkout.html index a05914b..19858e9 100644 --- a/views/checkout.html +++ b/views/checkout.html @@ -8,20 +8,20 @@