Ejemplo n.º 1
0
func (env handlersCtx) GetServiceProviders(w http.ResponseWriter, r *http.Request) {
	session, _ := env.HandlerContext.GetCookieStore().Get(r, "holzrepublic-session")
	var user *models.UserRow
	if session.Values["user"] != nil {
		user = session.Values["user"].(*models.UserRow)
	}
	var order *vm.OrderDto
	if session.Values["order"] != nil {
		order = session.Values["order"].(*vm.OrderDto)
	}
	products, err := env.HandlerContext.GetDatastore().AllProducts()

	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	data := struct {
		CurrentUser             *models.UserRow
		Products                []*models.ProductRow
		ShoppingCartItemsNumber int
	}{
		user,
		products,
		orderService.GetItemsCount(order),
	}
	env.HandlerContext.GetRenderer().HTML(w, http.StatusOK, "products", data)
}
Ejemplo n.º 2
0
func (env handlersCtx) getShoppingCartItemsCount(r *http.Request) int {
	var order = env.getOrder(r)
	return orderService.GetItemsCount(order)
}