Local Storage JavaScript Code Documentation

Function: formatNumberTo_N_Digits

Formats a number to a specified number of digits, padding with '0' if necessary.


/**
 * Formats a number to a specified number of digits, padding with '0' if necessary.
 * @param {number} number - The number to be formatted.
 * @param {number} N - The desired number of digits.
 * @returns {string} - The formatted number.
 */
function formatNumberTo_N_Digits(number, N) {
    return number.toString().padStart(N, "0");
}
        

Function: LS_cart_count

Retrieves the total count of cart_items in local storage.


/**
 * Retrieves the total count of cart_items in local storage.
 * @returns {number} - The total count of cart_items.
 */
function LS_cart_count() {
    // ... Function code ...
}
        

Function: LS_cart_map

Processes all cart_item entries from local storage and returns a Map object sorted by key.


/**
 * Processes all cart_item entries from local storage and returns a Map object sorted by key.
 * @returns {Map} - The sorted cart_item entries.
 */
function LS_cart_map() {
    // ... Function code ...
}
        

Function: LS_clear_items

Removes all keys with "cart_item" from local storage, excluding necessary entries.


/**
 * Removes all keys with "cart_item" from local storage, excluding necessary entries.
 */
function LS_clear_items() {
    // ... Function code ...
}
        

Function: update_cart_map

Resets local storage entries starting with "cart_item" and adds new entries given new_cart_map type: Map().


/**
 * Resets local storage entries starting with "cart_item" and
 * adds new entries given new_cart_map type: Map().
 * @param {Map} new_cart_map - The new cart_map to be stored in local storage.
 */
function update_cart_map(new_cart_map = new Map()) {
    // ... Function code ...
}
        

Function: checkIfItemExistsInCart

Given item_id, returns key or null if not found in current local storage map.


/**
 * Given item_id, returns key or null if not found in current local storage map.
 * @param {string} item_id - The item_id to search for.
 * @returns {string|null} - The key associated with the item_id or null if not found.
 */
function checkIfItemExistsInCart(item_id) {
    // ... Function code ...
}
        

Function: calc_total_cart_price

Calculates the total price of items in the cart_map.


/**
 * Calculates the total price of items in the cart_map.
 * @returns {number} - The total price of items in the cart_map.
 */
function calc_total_cart_price() {
    // ... Function code ...
}
        

Function: LS_add_item

Adds a new item to the cart in local storage or increments quantity if the item already exists.


/**
 * Adds a new item to the cart in local storage or increments quantity if the item already exists.
 * @param {number} id - The item ID.
 * @param {number} price - The item price.
 * @param {string} description - The item description.
 * @param {string} common_name - The common name of the item.
 */
function LS_add_item(id, price, description, common_name) {
    // ... Function code ...
}
        

Function: LS_remove_item

Decrements or removes an item from the cart in local storage based on quantity.


/**
 * Decrements or removes an item from the cart in local storage based on quantity.
 * @param {number} id - The item ID.
 * @param {number} price - The item price.
 * @param {string} common_name - The common name of the item.
 */
function LS_remove_item(id, price, common_name) {
    // ... Function code ...
}
        

Function: cart_appendOrderItem

Creates and appends an order item to the order-container in the DOM.


/**
 * Creates and appends an order item to the order-container in the DOM.
 * @param {string} item_quantity - The quantity of the item.
 * @param {string} item_price - The price of the item.
 * @param {string} descr - The description of the item.
 * @param {string} common_name - The common name of the item.
 * @param {string} item_id - The ID of the item.
 */
function cart_appendOrderItem(item_quantity, item_price, descr, common_name, item_id) {
    // ... Function code ...
}
        

Function: populateCartItems

Loads the DOM with cart_items from local storage based on the sorted map from LS_cart_map().


/**
 * Loads the DOM with cart_items from local storage based on the sorted map from LS_cart_map().
 */
function populateCartItems() {
    // ... Function code ...
}
        

Function: LS_pay

Processes items in the cart_map, sends order details to the server, clears items, and updates the DOM.


/**
 * Processes items in the cart_map, sends order details to the server, clears items, and updates the DOM.
 */
function LS_pay() {
    // ... Function code ...
}
        

Function: remove_all_orderItems

Removes all orderItems from the DOM.


/**
 * Removes all orderItems from the DOM.
 */
function remove_all_orderItems() {
    // ... Function code ...
}
        

Function: clear_cartButton

Clears all cart_items from local storage and updates the DOM.


/**
 * Clears all cart_items from local storage and updates the DOM.
 */
function clear_cartButton() {
    // ... Function code ...
}
        

Function: check_emptyCart

Checks if the cart is empty and prevents checkout if true.


/**
 * Checks if the cart is empty and prevents checkout if true.
 * @param {Event} event - The event triggering the check.
 */
function check_emptyCart(event) {
    // ... Function code ...
}
        

Function: check_emptyCart_checkout

Checks if the cart is empty and prevents checkout if true.


/**
 * Checks if the cart is empty and prevents checkout if true.
 * @param {Event} event - The event triggering the check.
 */
function check_emptyCart_checkout(event) {
    // ... Function code ...
}
        

Function: orderCart

Checks if the cart is empty and redirects to the order_online page.


/**
 * Checks if the cart is empty and redirects to the order_online page.
 * @param {Event} event - The event triggering the check.
 */
function orderCart(event) {
    // ... Function code ...
}
        

Function: showAlert

Shows a favorite order alert.


/**
 * Shows a favorite order alert.
 */
function showAlert() {
    // ... Function code ...
}
        

Function: closeAlert

Closes the favorite order alert.


/**
 * Closes the favorite order alert.
 */
function closeAlert() {
    // ... Function code ...
}
        

Function: selectFavorite

Updates the favorite status in the DB and toggles button behavior.


/**
 * Updates the favorite status in the DB and toggles button behavior.
 * @param {string} order_id - The ID of the order.
 * @param {string} is_favorited - The current favorite status.
 */
function selectFavorite(order_id, is_favorited) {
    // ... Function code ...
}
        

Function: orderAndFavCart

Orders the cart, updates favorite, and redirects to order_online page.


/**