work on checkout
This commit is contained in:
@@ -21,6 +21,7 @@ type CartItemController interface {
|
||||
DeleteItemHandler(*gin.Context)
|
||||
EditItemHandler(*gin.Context)
|
||||
CheckoutView(*gin.Context)
|
||||
CheckoutHandler(*gin.Context)
|
||||
}
|
||||
|
||||
type cartItemController struct {}
|
||||
@@ -29,6 +30,15 @@ func NewCartItemController() CartItemController {
|
||||
return &cartItemController{}
|
||||
}
|
||||
|
||||
|
||||
func GetShippingMethods() []models.Shipping {
|
||||
return []models.Shipping{
|
||||
{ Id: "germany", Name: "Germany (DHL)", Price: 3.99 },
|
||||
{ Id: "international", Name: "International (DHL)", Price: 5.99 },
|
||||
{ Id: "pickup", Name: "Pickup", Price: 0.00 },
|
||||
}
|
||||
}
|
||||
|
||||
func generateSessionId() string {
|
||||
bytes := make([]byte, 16) // 16 bytes = 128 bits
|
||||
_, err := rand.Read(bytes)
|
||||
@@ -151,6 +161,7 @@ func (rc *cartItemController) CartItemView(c *gin.Context) {
|
||||
data := CreateSessionData(c, gin.H{
|
||||
"cartItems": cartItems,
|
||||
"priceTotal": fmt.Sprintf("%.2f", priceTotal), //round 2 decimals
|
||||
"shipping": GetShippingMethods(),
|
||||
})
|
||||
|
||||
c.HTML(http.StatusOK, "cart.html", data)
|
||||
@@ -229,5 +240,14 @@ func (rc *cartItemController) EditItemHandler(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (rc *cartItemController) CheckoutView(c *gin.Context) {
|
||||
c.HTML(http.StatusOK, "checkout.html", gin.H{})
|
||||
shippingMethod := c.Query("shippingMethod")
|
||||
|
||||
c.HTML(http.StatusOK, "checkout.html", gin.H{
|
||||
"askAddress": (shippingMethod != "pickup"),
|
||||
"shippingMethod": shippingMethod,
|
||||
})
|
||||
}
|
||||
|
||||
func (rc *cartItemController) CheckoutHandler(*gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
@@ -126,8 +126,6 @@ func (rc *shopItemController) NewShopItemFromForm(ctx *gin.Context) (models.Shop
|
||||
})
|
||||
}
|
||||
|
||||
// Convert the price string to float64
|
||||
|
||||
shopItem := models.ShopItem{
|
||||
Name: name,
|
||||
Abstract: abstract,
|
||||
@@ -151,7 +149,6 @@ func (rc *shopItemController) NewShopItemFromForm(ctx *gin.Context) (models.Shop
|
||||
}
|
||||
|
||||
return shopItem, nil
|
||||
//return services.ShopItems.NewShopItem(name, abstract, description, price, tagIds)
|
||||
}
|
||||
|
||||
func (rc *shopItemController) GetBasePrice(variants []models.ItemVariant) float64 {
|
||||
|
||||
Reference in New Issue
Block a user