Add Product to shopping cart

0
We are creating an application where it's needed to add something to a shopping cart. We have created three entities, product, shoppingcart, shoppingcart_products. To make the products visible, we have created an listview with entity product. The listview represent the name, image and the description of the product. Below all the information we have created an action button with the caption "Add to cart". What is the best way to make the button interact with the shoppingcart? We have very low, to none experience with Mendix yet. Since we just started this as a schoolproject. Thanks in advance!
asked
2 answers
1

I assume that your product entity is more or less a specification of a type of product and that the shoppingcart_products represents a instance of 'product' in your cart?

In the above described scenario you could opt to create a X number of ShoppingCart_products for the number of products selected. When you make an association between Shoppingcart & Shoppingcart_Product (one to many) in your domain model. You can then fill this association in the microflow underneath your action button with the available shoppingcart object. (provided you have already made a shoppingcart object for the current user)

answered
0

I would consider changing your domain model to add Product_templates, and add a quantity field to your Product entity.  The reason for this is so that, when the price of your product changes, you do not want this change to affect all of your historical records - you need to de-normalize the data structure to retain historical data.

From your shopping cart form, either display or open a display of Product_templates to choose from, and when one is selected create a matching Product record, linked to your shopping cart entity, containing the current unit cost, etc.  Allow the user to increment the quantity if they wish and recalculate the line item price (on change or before commit microflows).

answered