1

I am practicing designing an eCommerce application and I realized that if I want to display a particular product I have to do so using a unique identifier such as the product id.

I noticed a drawback. If a user bookmarks that product with the URL of lets say example.com/product/<productId> or adds it to the cart and somewhere down the line that product is deleted from the database, the users bookmark will be useless because that productId no longer exists and if that item was previously in the cart that will also be useless.

Can someone please suggest a way to solve this problem? Thanks.

3

A product should never be deleted from the database. Use a flag indicating if the product is active or inactive.

When the user navigates to an inactive product through a bookmark or a cart, display some of the details of the product and a large message saying that this product is not available anymore. Below this message list alternative products that can be used to replace the inactive product.

  • 2
    @Flashspeedlife And, of course, inactive (but not simply "out of stock") products would not show up in a normal search (but you might have an option to include them, so users without a bookmark, but who had bought the product, can look up the details). If for some reason you must delete entries from the database, references to such products would produce a "This product no longer exists (or you have used an invalid product code)" message (though the clumsiness of that phrasing is another reason not to delete "dead" product lines). – TripeHound Aug 23 '17 at 9:32
  • @DesignerAnalyst Thank you for that piece of knowledge :). Is there ever an appropriate time when a product should or can be deleted from the database by an admin for example? – FlashspeedIfe Aug 23 '17 at 21:18
  • @FlashspeedIfe it should never be deleted. I do not see any reason why you should delete it, disk space and performance is no longer a problem. – DesignerAnalyst Aug 24 '17 at 6:51
  • @FlashspeedIfe Even if you are never going to provide an item again, apart from keeping a record of its existence for the reasons you're asking about (keeping links "alive" to some degree) you may still want to retain stuff like sales-data/profitability to inform decisions about stocking new, similar items. The potential space/performance gains by deleting are virtually zero and are very unlikely to exceed the potential "business" gains from keeping the data. – TripeHound Aug 24 '17 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.