Order/Shopping cart fundamentals

0
Basically I am trying to make a simple system that involves a customer, order and product. I’ve made this domain model: This is what my product page looks like: Now I assume the way to add a product to an order is through a microflow. When I click add to cart I want to add the product to an order and when a users switches over to the order tab it shows a list of products added to their order. How would I go about making a microflow that does this. I’ve been searching through the academy but can’t quite find a suitable solution. My idea was to set the on click action of the “add to cart” button to call a microflow. Then in the microflow create a list with the products. Thanks in advance.    
asked
3 answers
2

Hi Benjamin,

you can indeed do this with a microflow button. But first you'll have to change your domain model a bit.

With your current domain model you won't be able to specify additional information regarding the order and the product, such as the amount of items someone wants to order of that product.

A general domain modeling 101 practice for Order and Product is to have an additional table inbetween Order and Product which is usually called OrderLine.

Here's an image from an older Mendix blog showing the domain model used.

With this domain model a customer can have multiple orders. An order can have multiple orderlines, and an orderline always refers to 1 product. So you can have an Order which has an orderline for Product “Spoon” with a quantity of 2. And an orderline for Product “Fork” with a quantity of 7.

The “Add to cart” button would first have to check if there's already an orderline created for this particular order and this particular Product. You can do this by retrieving the first OrderLine which has an association to the current order and which has an association to selected product. You should probably have these available as parameters already if your page has the Order as it's context object and the list of products in your listview.

If there isn't an OrderLine found, it needs to create it. Be sure to set both associations when creating the object.
Then you need to update the orderline object with the correct quantity of items (in this case a +1 for adding an item) and commit the orderline object.

You'll find a many of these kind of scenarios in the learnings. If i remember correctly there was a certain shopping cart learning available.

answered
0

Looking good but which payment gateway you are using?

answered
0

The state of my microflow:

answered