M
M
mewithoutyou2019-05-12 19:46:16
MongoDB
mewithoutyou, 2019-05-12 19:46:16

How to store data about orders whose products can be deleted?

I want to understand how to store order data in a cafe if the products can be deleted.
For example, an order is stored in the database as a similar structure (we use MongoDB).

{
  "id": 1,
  "name": "Client",
  "phone": "79000000000",
  "address": "Address",
  "comment": "Client comment",
  "products": [
    {
      "id": 1,
      "quantity": 1,
      "variation_id": 2
    },
    {
      "id": 3,
      "quantity": 2
    }
  ]
}

Say, when opening a customer order, we simply make a selection by product id and display information. But what if the position or its variation has been deleted (as an example, seasonal menus every 3-4 months, and so on). What are the practices here? To transfer such positions to a separate collection? But then the request will not look so smooth - it will be necessary to search for the id of the goods that were not found in active positions and request from another collection ...
I see options:
1) Either replace the position deletion by changing the status to Inactive and do not delete anywhere, and on the site, filtering simply by the parameter active: true (for example);
2) Or store in the information about the order and the name of the positions and their variations.
Moreover, it seems to me that I will have to do a mixed version of these two, because I still need to somehow store the prices of goods at the time of purchase, plus the applied discounts, if any.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alex-1917, 2019-05-19
@mewithoutyou

1. Store at least the SALES price in the order. Or where else to store it?
2. Products are not deleted, a status has been invented for this. (in general, you need to delete rows in the database as little as possible, you definitely do not have a project of the MVIDEO level, overhead costs will be fractions of%%.)
3. In 80% of box stores, a complete inventory is stored in the order - the product itself, price, parameters, quantity in.
Take a close look at your project - it's unlikely that you have 300 million products and 10,000 orders every day ...
Keep everything in order.

D
Dmitry Shitskov, 2019-05-12
@Zarom

replace position deletion by changing status to Inactive and do not delete anywhere

The correct decision
PS Not very (not at all) a suitable task for a non-relational database.

E
Egor Zhivagin, 2019-05-13
@Krasnodar_etc

Why not put full information about the product (including prices, ...) at the time of placing the order instead of id?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question