How to add stuff to shopping cart?

Hi guys i have these entity in my domain model, i want when i click “add to cart” to add something and show it to me how many stuff is in the cart and total price? So how that microflow is supposed to look? Is this domain model good? 
1 answers

In your datamodel the product (coffee) can only be added to 1 cart, as the association is coffee:cart is *:1.

To allow the coffee to be added to multiple carts and multiple coffees to a cart the association should read *:*

If you create a cart with a microflow and display a page with a dataview displaying the cart, you could add a grid with datasource is database showing all the coffee objects that can be added to the cart. Add a second dataview to the page showing the coffees over the association between coffee and cart. The with a microflow on the grid you can associate a selected coffee to the cart by setting the association to the cart and refreshing the cart object. The microflow will have the cart and selected coffee as input parameters.

Now you need to handle 2 things:

  1. prevent duplicates
  2. calculate the amount of items and the total price


To calculate the total price and number of items, retrieve the list of all items from the cart over the association and perform a count, set the count in the number of items attribute. Create a variable (decimal), loop over the retrieved list and change the variable to it’s value + the value of the iterator (the price of the product.

For the first item, retrieve the list of coffee objects that are associated to the cart. Perform a find list operation to see if the coffee was already added. This prevents the addition of duplicates, however you do not have an option to store the amount of duplicates for the same coffee object. In your domain model I suggest to add a new entity that holds the association to the coffee and the cart that has an option to indicate the amount of times an item has been added to the cart. Update the microflow that adds stuff to the cart. Then update the prevent duplicates part of the add microflow and perform the retrieve of the cart-items from the cart over association and calculate the total price and number of items added  then seems straightforward.

Hope I gave you some idea of what needs to be implemented.