Constructor
new Variation(variationId, productId, name, priceAdjustmentopt, isAvailableopt, attributesopt, stockopt, preparationTimeopt, isDefaultopt)
Creates a new Variation instance.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
variationId |
string | Unique identifier for the variation. | ||
productId |
string | Associated product ID. | ||
name |
string | Name of the variation (e.g., Large, Extra Spicy). | ||
priceAdjustment |
number |
<optional> |
0 | Additional price (+/-) for this variation. |
isAvailable |
boolean |
<optional> |
true | Availability status of the variation. |
attributes |
object |
<optional> |
{} | Custom attributes for the variation (e.g., size, spice level). |
stock |
number |
<optional> |
0 | Stock quantity for the variation. |
preparationTime |
number |
<optional> |
0 | Additional preparation time in minutes. |
isDefault |
boolean |
<optional> |
false | Marks if this variation is the default option. |
- Source:
Methods
adjustStock(quantity)
Adjusts the stock quantity by a specified amount.
Parameters:
| Name | Type | Description |
|---|---|---|
quantity |
number | The amount to adjust stock by (positive or negative). |
- Source:
getFinalPrice(basePrice) → {number}
Calculates the final price based on a base price and the variation's price adjustment.
Parameters:
| Name | Type | Description |
|---|---|---|
basePrice |
number | The base price of the product. |
- Source:
Returns:
The final price after applying the variation's price adjustment.
- Type
- number
toggleAvailability()
Toggles the availability status of the variation.
- Source:
updateDetails(name, priceAdjustment, isAvailable, attributes, stock, preparationTime, isDefault)
Updates the details of the variation.
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | New name for the variation. |
priceAdjustment |
number | New price adjustment value. |
isAvailable |
boolean | New availability status. |
attributes |
object | Updated custom attributes. |
stock |
number | Updated stock quantity. |
preparationTime |
number | Updated preparation time in minutes. |
isDefault |
boolean | Updated default status. |
- Source: