Implementing the shopping cart functionality on the client side

To fulfill the Register step of the ERDA strategy, we will register the /shopping-cart  route and its associated handler function, ShoppingCartHandler, inside the registerRoutes function found in the client/client.go source file:

r.Handle("/shopping-cart", handlers.ShoppingCartHandler(env))

Remember that this route will kick-in when a user access the shopping cart by clicking on the shopping cart icon in the navigation bar. Upon clicking the shopping cart icon, the ShoppingCartHandler function will be called.

Let's take a look at the ShoppingCartHandler function:

func ShoppingCartHandler(env *common.Env) isokit.Handler {
return isokit.HandlerFunc(func(ctx context.Context) {
renderShoppingCartItems(env)
})
}

The main purpose of this function is to call the renderShoppingCartItems function to render the shopping cart on the client side. We have consolidated the logic to render the shopping cart and its contents in the renderShoppingCartItems function so that the shopping cart page can be re-rendered as the user removes items from the shopping cart.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.181.57