Here you are creating a list of carts, but it has no cart objects in it. Taking the sum of an empty list will always lead to an empty total.
In addition, I would still recommend building up your domain model differently using line items instead of just products and carts so you can reuse products.
Imagine you have your domain model set up like this:
-----------
Order
Date
Status
...
-----------
Orderline
Quantity
LinePrice
.......
-------------
Product
Name
Price
......
-------------
There are several moments to do this, but what you'll basically want to do is:
Hi Muhammad,
Can you share your domain model?
I assume you will need to have a microflow which will retrieve all products and prices and then sum everything and put that value in an attribute to be shown on the page.
Can you explain in more detail what is the issue you are facing?
BR,
Inês Fragoeiro
hey, yes see my screenshots below for better understanding, this is my cart page;
triggerd the microflow from the add to cart button
the mircoflow itself
Hi Muhammed,
If I understand you in the right way, Here are some insights that may help you:
Data Model:
Page Design:
Microflow for Adding Products to Cart:
Dynamic Total Price Calculation:
Update Total Price on Changes:
Display Total Price:
Here's a simplified example of what the microflow logic might look like:
Microflow:
Add To Cart:
1. Retrieve Cart based on user session or user ID.
2. Retrieve or create CartItem for the selected product.
3. Update CartItem quantity based on user input.
4. Update CartItem price based on the Product entity.
5. Update Cart total price by summing up all CartItems.
Microflow:
Calculate Tota lPrice:
1. Retrieve Cart based on user session or user ID.
2. Retrieve all CartItems associated with the Cart.
3. Calculate the total price by summing up (quantity * price) for each CartItem.
4. Update the Cart entity with the new total price.
** Kindly accept my answer if I assist you in solving your problem.