Why present shopping carts and order bills differently in the domain model?

In the past, I created some shopping cart systems, but I always designed them so that the final order account was just a shopping cart that was marked as “purchased”. All the logic for adding / removing / changing items in the cart is also the logic for ordering. All data is stored in the same tables in the database. But it seems that this is not the right way to create an e-commerce site. Can someone explain the advantage of the shopping cart branch from the invoices in the domain model?

It seems to me that this will lead to a large duplicated code, adding a set of tables in the database and complicate its maintenance if the system needs to start executing more complex orders (for example, specify the selected parameters for an item that may or may not change the price / availability / order delivery time). I assume that I just did not see the light, since each book and other example that I see seem to share these two seemingly similar problems - but I can not find any explanation in favor of this! This is also the case in the systems that I design that changes are often made after the initial order is confirmed. It is not uncommon for items to be removed, replaced, or added after (but before completion).

+4
source share
4 answers

I like to think of it as what happens in a real store where you have a cart with all the products, options, coupons and other information about what you would like to buy.

An order represents order information ... payment method, transaction information, etc. This is just an introduction "here is all the information about how I bought the basket." All the information you provide when you go into the registry and pay.

I believe this is an easy way to decide what is going on and provides a good model of what could be in real correlation.

0
source

In your scenario, I don't think you want to change the entry, but rather apply the changes to it. Thus, you will have records indicating the change in price. For example, if the key price has been changed from $ 10 to $ 15, you will need to add an entry indicating the price change + $ 5.

The whole point of separating records and duplication is to ensure that the data in the POS (point of sale) is the same as it is now. If this is not the case, then you can easily see what changes occurred with the price and when.

Say you posted a Widget B for $ 25 with a description, indicating that it has a Z-Dongle. You later hear from the manufacturer that he has an X-Dongle, not a Z-Dongle, and as a result, you need to lower the price. Meanwhile, when you needed to post and fix a bug, you had someone who bought this widget for $ 25.

Then this customer calls after detecting the absence of Z-Dongle and wants to return and receive a full refund. In addition, you now have a record showing that they bought the product with X-Dongle for $ 15 less than they originally paid. A customer service representative tells him that the PURE statement states that he has an X-Dongle - now what?

+2
source

I was just about to argue that the difference would be good, at least to keep it so that the invoice does not change, just to read your comment about the fact that in your case the invoices tend to change? I would say that at this stage they still look like an “order” rather than an invoice. One of the reasons to make them separate elements may be that your cart will have links to products that are subject to change, while you do not want your invoices to refer to products that may be subject to change (leading to that another product is described when considering an invoice compared to the date / time the invoice was created).

Using interfaces and / or inheritance, you should be able to program common functions only once, but at the same time save bills and carts separately.

+1
source

Given the conversion rate of performance and speed:

  • Storing data intensively can lead to a lot of deadlocks. Think about it: when customers insert goods into their carts or simply browse through the list of goods from their carts, our fulfillment staffs process the order, distribute assignments, etc. This can lead to a deadlock.

  • high concurrency, and a lower order conversion rate will worsen the situation.

0
source

Source: https://habr.com/ru/post/1308920/


All Articles