B
B
Bogdan Khvalko2021-07-02 00:21:37
PHP
Bogdan Khvalko, 2021-07-02 00:21:37

How to detect changes for items in an order?

Internet shop. There is an order and goods in it. We click on editing and we can change the number of products, their sizes, add and remove. Data is saved at the click of a button. The data comes in the form of an array

$_POST
[
    ['id' => 2, 'count' => 4, 'size' => 'X'],
    ['id' => 2, 'count' => 3, 'size' => 'XL'],
    ['id' => 7, 'count' => 1, 'size' => 'X'],
    ['id' => 5, 'count' => 2, 'size' => 'S'],
    ['id' => 5, 'count' => 2, 'size' => 'S'],
    ['id' => 9, 'count' => 1, 'size' => 'M'],
]


We also have those products that were originally in the order. We get them from the base. The format is similar.
It is necessary to determine the changes for each product, and write them down, for example, in a log. (in fact, you need to conduct a monetary transaction for each product) What would you do in a similar situation. Delete and overwrite is not an option since all changes for each product are important to me.

60de31df6515f640252177.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Akina, 2021-07-02
@Akina

How would you act in a similar situation.

Yes, as usual when storing timeline. First of all, we set up rights and prohibit updating and deleting. Entries can only be added. The second - we enter the automatically assigned field of the time stamp of the creation of the order version. And, in fact, everything.
To obtain the status of an order at any point in time (the current state or in the past), we use one simple query. The same - if you need to get the difference between the current and previous states. Window functions do this on a count of "times".
And no logs are needed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question