Class: Order

Order()

new Order()

Class representing a customer order. Implements the Strategy Pattern for shipping cost calculation.

Source:

Classes

Order

Methods

addItem(item)

Adds an item to the order list.

Parameters:
Name Type Description
item Object

The item to add (expected to have price and quantity properties).

Source:

calculateTotal() → {number}

Calculates the total cost of the order items.

Source:
Returns:

The sum of all items (price * quantity).

Type
number

calculateTotalWithShipping() → {number}

Calculates the total cost including shipping. Uses the currently selected shipping strategy.

Source:
Returns:

The final total price.

Type
number

getEstimatedDeliveryDate() → {string}

Calculates the estimated delivery date (Creation Date + 1 days). This method uses the external 'date-fns' library.

Source:
Returns:

The estimated delivery date formatted as 'dd.MM.yyyy'.

Type
string

setShippingStrategy(strategy)

Sets the shipping strategy dynamically.

Parameters:
Name Type Description
strategy Object

A concrete implementation of the ShippingStrategy interface.

Source:
Example
order.setShippingStrategy(new NovaPoshtaStrategy());

updateStatus(newStatus) → {boolean}

Updates the status of the order.

Parameters:
Name Type Description
newStatus string

The new status ('pending', 'shipped', or 'delivered').

Source:
Returns:

True if the status was updated successfully.

Type
boolean