Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why represent shopping carts and order invoices differently in a domain model?

I've built some shopping cart systems in the past, but I always designed them such that the final order invoice is just a shopping cart that has been marked as "purchased". All the logic for adding/removing/changing items in a cart is also the logic for the order. All data is stored in the same tables in the database. But it seems this is not the proper way to design an e-commerce site.. Can someone explain the benefit of separating the shopping cart from invoices in the domain model?

It seems to me this would lead to a lot of duplicated code, an extra set of tables in the database, and make it harder to maintain in the event the system need to start accommodating more complicated orders (like specifying selected options for an item which may or may not change the price/availability/shipping time of the order). I'm assuming I just haven't seen the light, as every book and other example I see seems to separate these two seemingly similar concerns -- but I can't find any explanation as to the benefit of doing such! It's also the case in the systems that I design that changes are often made after the initial order is confirmed. It's not uncommon for items to be removed, replaced, or added afterwards (but prior to fulfillment).

like image 511
Todd Avatar asked May 05 '10 17:05

Todd


People also ask

Which data structure is used in shopping cart?

Conceptual Data Model In this example, the model is captured using an Entity-Relationship Diagram (ERD) that documents entity types, relationship types, attribute types, and cardinality and key constraints. The conceptual data model for shopping cart data features users, items and shopping carts.

What is the purpose of a shopping cart in ecommerce?

An ecommerce shopping cart is a type of software that allows customers to purchase items from your shop or store a list of the items they wish to purchase in the future. There are two main types of ecommerce shopping carts: Hosted/self-hosted shopping cart.

What is one of the advantages of using shopping cart software?

Another important benefit of shopping cart software is being able to collect payments in a hassle-free way, as it gives you all processing features you need to charge customers without asking them to abandon the platform.

What does a virtual shopping cart do for the customer who is shopping on a website?

A shopping cart is an essential element of an e-commerce site. This online and virtual platform that allows visitors to make purchases online. When your clients' checkout, the cart keeps track of all items added during their site visit. It also calculates taxes, shipping fees, and other payment details.


1 Answers

I was just about to argue that the difference would be good at least to keep it so that an invoice is not changeable, only to read your remark that in fact in your case invoices tend to change? I'd say at that stage they are still something like an 'order' and not actually an invoice. One of the reasons to make them separate items might be that your shopping cart will have references to products that are subject to change while you don't want your invoices to reference products that might change (leading to a different product being described on reviewing the invoice compared to the date/time the invoice was created).

By using interfaces and/or inheritance you should be able to program the shared functions only once, but still keep invoices and shopping carts separate.

like image 122
Simon Groenewolt Avatar answered Oct 17 '22 03:10

Simon Groenewolt