-
Get References
- Select and store references to DOM elements such as the shopping cart, close button, product list, cart list, and other relevant components.
-
Define Products
- Create a list of product objects containing details such as ID, name, image, price, and category.
-
Variables for Cart Management
- Set up variables to manage cart items (
listCards
) and button states (addedButtons
).
- Set up variables to manage cart items (
- Display Products
- Call the
initApp
function to display the initial list of products on the page.
- Call the
-
Create Product Elements
- Iterate through the list of products and create HTML elements to display each product.
-
Update Button States
- Check if the product is already in the cart and update the button's text and style accordingly.
- Filter Logic
- Based on the selected category, filter the list of products and update the displayed items accordingly.
- Button Event Listener
- Attach event listeners to category buttons to handle category selection and filter products.
-
Cart Item Check
- Check if the product is already in the cart or if it needs to be added.
-
Update Button State
- Change the button text and style to indicate the product has been added.
-
Update Cart Items
- Add the product to the cart or update its quantity if it's already present.
-
Reload Cart
- Refresh the cart display with the updated cart items.
-
Calculate Totals
- Compute total price and item count for the cart.
-
Update Cart Display
- Update the cart display with item details and total values.
-
Display Average Price
- Calculate and display the average price of items in the cart.
-
Update Cart Item Quantity
- Adjust the quantity of a cart item or remove it if the quantity is zero.
-
Reload Cart
- Refresh the cart display to reflect changes.
-
Sort Logic
- Sort the cart items based on price in ascending or descending order.
-
Reload Cart
- Update the cart display with the sorted items.
-
Reset Cart
- Clear all items from the cart and reset button states.
-
Reinitialize Products
- Refresh the product list to ensure buttons are correctly displayed.
-
Show Notification
- Display a notification indicating that the order is booked.
-
Clear Cart After Delay
- Hide the notification and clear the cart after a brief delay.
- Sort and Clear Actions
- Attach event listeners to sorting and clearing buttons to handle respective actions.