Answer the question
In order to leave comments, you need to log in
How to make shopping carts for large online stores?
Tell me how to properly design an application (an online store with a huge database of goods).
There are for example 10k+ products (20 categories).
How to organize everything correctly? What should the database look like and how to handle all these items?
A SPA is planned on react, so the question of loading data is of interest.
It is not an option to load 10k products in one array per client and store it in the store.
And how to handle the cart. In fact, only the id of the goods should be stored in the basket, and then the necessary information about the goods for rendering and placing an order should be dynamically loaded somehow. It will not work just to go over the entire array of goods in search of the necessary (added to the basket) goods.
In general, tell me how everything is organized in such applications
Answer the question
In order to leave comments, you need to log in
Very funny thread.
It is immediately clear that almost none of the advisers have ever worked with a real online store.
Because the first thing that every young online store developer discovers is that people sometimes buy more than one piece of each product .
The second thing that a young developer of large online stores discovers for himself (other, of course, young developers do not) is that goods come at discounted prices . Which should also be recorded in the basket and order.
Well, the third, already specifically for the author of the question, and not only for all young writers of large online stores - first, before starting to write large online stores, you should study the primer on web development. And discover that any online store, even a small one, has a back-end . In which, in general, the whole logic of working with goods, orders and a basket is implemented. And which has nothing to do with "SPA on the react". And to write that, you need to learn the basics of databases, SQL and some kind of server-side programming language. Well, about 20 more disciplines.
Each action has its own model for the cart
Cardid
Item id
Item image
Item count
Item price
Total
Discount
No matter how many items you have there
There is a table of goods, each product has a product_id
There is an order table, it has order_id, user_id, date, something else there.
There is a many-to-many relationship table, like order_has_product, for example
order_id | product_id | qty
When you need all the items from the cart, you do something like this
select id, title, description from products where product_id in (
select product_id from order_has_product where order_id = 42
)
-- ну или с джоином, вложенный написал просто для наглядности
It’s not an option to load 10k products in one arrayCertainly not an option. Store them in the database on the back. And 10k, this is not a big store, in a big store there will be thousands of CATEGORIES of goods.
You can’t just go over the entire array of products in the search ...Of course, you don't have to run. Read about indexes .
Categories tables : id, name,
parentId (if there are not many of them, you can load all at once)
products : id, name, categoryId (load in parts, either by pagination or dynamic loading when scrolling, there are table components for react that dynamically load themselves )
cart : userId, productId, quantity (when loading, load the number of items to display it in the header of the site, when opening the cart, load from the server all information with the name, prices and something else, can be stored in LocalStorage for unregistered users)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question