locked
Strategy for Shopping Cart (.Net Core 3.1 MVC) RRS feed

  • Question

  • User-686951522 posted

    Hi. I'm very new coding, so the most practical & easy solution will be fine for my by now.

    I'm doing a very vanilla net core 3.1 mvc academic project and I need to implement a shopping cart.

    My involved Models are:

    • Order, that contains a collection of
    • LineOrder which is linked with one
    • Instrument (an Instrument can be linked to many LineOrders on differents Orders).

    My Uses Cases are 2:

    • In the Homepage you can "Add to Cart" an Instrument, which has to be added to cart with the quantity of 1 & default attributes.
    • In the Instrument/Details you can select different product attributes and the quantity of items and then "Add to Cart".

    In both cases I suppose I have to use ajax requests.

    If the user is authenticated the cart has to be loaded (If the purchase isn't completed). I guess I will need some init rutine to load or create the cart.

    On the navbar I have a counter that has to show the nº of items in the cart.

    I see at least 3 differents aproaches but I don't know which one could I use( I accept new ones):

    1. Cart logic inside Order/Details Controller & custom methods(add,remove to cart, load etc). A cart would be an Order with Status property as "Cart" until payment is made whose Status changes to "processing".
    2. Cart logic on dedicated CartController. I would only  use a CartDetails View, but I would make POST request to it's methods.
    3. Cart Class(that you injects at required place) works with Order, LineOrders & Instrument Models and I don't know if use Interface like CartService. (very few experience with that).

    I remember that I don't have so much experience (I messed up beyond scaffolded Model > Controller > View) and the simplest and closest solution to the vanilla project, will be fine for me. 

    Thanks in advance.

    Wednesday, June 3, 2020 8:29 PM

All replies

  • User2078676645 posted

    Hi,

    If I were to make a choice, I would choose the third option. Adding the goods to the shopping cart with instrument, the shopping cart will record every information of the goods (product name, price, quantity, etc.), generate an order after the user buys, in the cart class only design the attributes that need to be recorded in the shopping cart, in the CartService can handle the corresponding method (home page shows the number of goods in the shopping cart, handle the purchase business, etc.), and CartController is responsible for handling user requests and system response.

    Regards,

    Evern

    Thursday, June 4, 2020 2:02 AM