Changes between Version 1 and Version 2 of UseCase007


Ignore:
Timestamp:
05/13/26 12:07:45 (2 weeks ago)
Author:
232012
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • UseCase007

    v1 v2  
    1515{{{#!div style="text-align: justify; width: 100%;"
    1616
    17 1. User selects a specific {{{Product}}} and chooses the option to add it to {{{Order}}}.
     171. User selects a specific Product and chooses the option to add it to Order.
    1818
    19 2. System checks the current {{{stock}}} level of the product in the {{{Product}}} table to ensure availability.
     192. System checks the current stock level of the product in the Product table to ensure availability.
    2020
    21 3. System retrieves the current {{{price}}} of the product to establish the {{{price_at_purchase}}} for the transaction.
     21{{{#!div style="margin-left: 20px;"
     22{{{
     23SELECT stock, price
     24FROM Product
     25WHERE product_id = @selected_product_id;
     26}}}
     27}}}
    2228
    23 4. System creates or identifies an active {{{Order}}} record associated with the consumer’s {{{user_id}}}.
     293. System retrieves the current price of the product to establish the price_at_purchase for the transaction.
    2430
    25 5. System creates a new entry in the {{{OrderItem}}} table, linking the {{{product_id}}} to the {{{order_id}}}.
     314. System creates or identifies an active Order record associated with the consumer’s user_id.
    2632
    27 6. System records the specific {{{quantity}}} requested by the {{{User}}} and saves the {{{price_at_purchase}}} to the {{{OrderItem}}} record.
     33{{{#!div style="margin-left: 20px;"
     34{{{
     35SELECT order_id
     36FROM `Order`
     37WHERE user_id = @authenticated_user_id AND status = 'Pending';
    2838
    29 7. System updates the user's view to reflect that the item has been added to their {{{Order}}} total.
     39INSERT INTO `Order` (user_id, date_created, status, total_price)
     40VALUES (@authenticated_user_id, CURRENT_TIMESTAMP, 'Pending', 0.00);
    3041}}}
     42}}}
     43
     445. System creates a new entry in the !OrderItem table, linking the product_id to the order_id.
     45
     466. System records the specific quantity requested by the User and saves the price_at_purchase to the OrderItem record.
     47
     48{{{#!div style="margin-left: 20px;"
     49{{{
     50INSERT INTO OrderItem (order_id, product_id, quantity, price_at_purchase)
     51VALUES (@active_order_id, @selected_product_id, @requested_quantity, @current_price)
     52ON DUPLICATE KEY UPDATE quantity = quantity + @requested_quantity;
     53}}}
     54}}}
     55
     567. System updates the user's view to reflect that the item has been added to their Order total.
     57
     58{{{#!div style="margin-left: 20px;"
     59{{{
     60SELECT SUM(quantity * price_at_purchase) AS new_total
     61FROM OrderItem
     62WHERE order_id = @active_order_id;
     63}}}
     64}}}
     65
     66}}}