What is an order in e-commerce application and how to control it. How is it related with user cart?
I'm training to create my first Food ordering from catering establishments application. I created administrator and his ability to add, edit and delete catering establishments - canteens, cafes, bars etc. Also to add various menu types and dishes into it. To edit it and to delete it. I have also created cart for users to add dishes from menus., edit quantity or to removes products from cart.
But now I have to create an order. I kinda know what it is, but I don't know how exactly is it related with other entities. I know that each order should be for each user's cart at that exact time when he presses Checkout or order button. Then in the database there should be an order and all related information about the user and his ordered goods - dishes, quantities, price etc.
What is relation between order and cart. For example my cart entity is this:
Manager or admin should be able to confirm or cancel the order. I think for the order I will use enum with values such as
submitted, approved, withdrawn
21 Replies
Hey, @Tomasm21!
Please remember to
/close
this post once your question has been answered!I don't want to reveal User object information that contains password. I will have to use intermediate DTO.
But my main question is how to define an order.
With what entities it should be related and what is relation type and why?
I think that only with CartItem. But I'm not sure.
There can be many cart items in an order. So I guess relation should be one-to-many.
Or maybe in cart item there should be Many-to-one relation with Order class,
I'm not sure about it.
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
So it's different class then which has additional fields like its own id, date, status( enum which can be - submitted, approved, withdrawn) and all info from CartItem - products, user info. Is it additional class OrderDetails? Or in the same order class?
Then Order should not have any link to cart. But CartItemTransferDTO has all required data to make and Order
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
And then CartItemDAO entries for this user deleted.
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
User then sees not cart info, but an order
which looks different than Admin or manager
What is an order item? A class or a property(field) in CartItem?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
So order is a different class
entity
right?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
items: List<CartItem>
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
alright. thanks for info
checking message so the post would not be locked...
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
@Andrew Something is not right with my order that is created out of user's cart. The problem is that the database cannot create correct foreign key between Orders ID and Order Items entity field.
The column
ORDERS_ID
at Item
entity becomes null
. And I think that it should be equal to the Order id for which those items belong to. Look at the picture of the database:Something is not right. Maybe I defined entities properties JPA relations wrong. Check it out:
And the Item:
How to do entities relation correctly? Should it be one direction or two-directional relationship?
What are differences of these relations? And what kind of relationship I should use? Why?
I was doing JUnit tests for the
Orders
service methods. It turns out that it can create orders. And Order items from user's cart.
But when it is time to show order (GetMapping) then it returns Orders entity with empty items
set.
Obviously it happens because JPA cannot find foreign key of items field for its designated order. It is null.
Can you help me to solve this thing?Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
I provided you with all the necessary information to realize the problem. It only looks too large.
Post Closed
This post has been closed by <@312509109863710732>.