public String getCart()

in online_bontique_demo/frontend/src/main/java/org/apache/dubbo/shop/frontend/FrontendController.java [87:136]


    public String getCart(Model model, String userId) throws ExecutionException, InterruptedException {
        model.addAttribute("is_cymbal_brand", false);
        model.addAttribute("show_currency", false);
        Cart cart = cartService.getCart("1");
        model.addAttribute("items", cart);
        List<CartItem> items = cart.getItems();

        Map<Product, Integer> productQuantityMap = new HashMap<>();


        List<String> productIds = new ArrayList<>();
        totalQuantity = 0;
       MoneyUtils.reset(totalCost);

        for (CartItem item : items) {
            totalQuantity += item.getQuantity();
            Product product = productCatalogService.getProduct(new GetProductRequest(item.getProductId()));
            productIds.add(item.getProductId());
            if (product != null) {
                productQuantityMap.put(product, item.getQuantity());
            }
        }

        for (Map.Entry<Product, Integer> entry : productQuantityMap.entrySet()) {
            totalCost = MoneyUtils.sum(totalCost, MoneyUtils.multiplySlow(entry.getKey().getPriceUsd(), entry.getValue()));
        }

        ListRecommendationsResponse recommendations = recommendationService.listRecommendations(new ListRecommendationsRequest("1", productIds));
        List<Product> products = new ArrayList<>();
        for (String productId : recommendations.getProductIds()) {
            products.add(productCatalogService.getProduct(new GetProductRequest(productId)));
        }
        model.addAttribute("recommendations", products);
        model.addAttribute("cart_size", totalQuantity);
        model.addAttribute("productQuantityMap", productQuantityMap);
        model.addAttribute("total_cost", totalCost);
        model.addAttribute("shipping_cost", shippingService.getQuote(new GetQuoteRequest(new Address(), items)));

        model.addAttribute("email", "someone@example.com");
        model.addAttribute("street_address", "1600 Amphitheatre Parkway");
        model.addAttribute("zip_code", "94043");
        model.addAttribute("city", "Mountain View");
        model.addAttribute("state", "CA");
        model.addAttribute("country", "United States");
        model.addAttribute("credit_card_number", "4432-8015-6152-0454");
        model.addAttribute("cvv", "123");
        // Add any other default values needed

        return "cart";
    }