Product custom options are customizable options of a product that the user selects in order to add the product to the cart with its own desired option values.
All product types supports custom options.
- The custom options are modeled as a field in the
Product model following this specification:
| Metadata |
Value |
| name |
customOptions |
| required |
false |
| type |
CustomOptionMap |
CustomOptionMap {
[code: string]: CustomOption // optionCode-spec mapping
}
CustomOption {
type: string one of ['boolean', 'number', 'string'], // type of the option
required: boolean, // option is required
valued: boolean, // option has a price
default: boolean | number | string // default value for the option when it is empty
}
- When the user adds a product to the cart she/he can specify values for any of the custom options. The behavior will depend on the specification of each option, and it is detailed in this table:
| Option is specified by user |
Option has a default value |
Option is required |
Spec |
| No |
No |
No |
Item added without value for the option |
| No |
No |
Yes |
Item cannot be added to the cart |
| No |
Yes |
* |
Item added with default value |
| Yes |
* |
* |
Item added with specified value |
- The custom options prices are modeled as a field in the
FixedItemPrice model following this specification:
| Metadata |
Value |
| name |
customOptions |
| required |
false |
| type |
CustomOptionMap |
CustomOptionMap {
[code: string]: number // optionCode-price mapping
}
- The custom options in the cart are modeled as a field in the
CartItem model following this specification:
| Metadata |
Value |
| name |
customOptions |
| required |
false |
| type |
CustomOptionMap |
CustomOptionMap {
[code: string]: CustomOption // optionCode-spec mapping
}
CustomOption {
value: boolean | number | string // default value for the option when it is empty
price: number // The option price. Can be absent in case of options without price.
}
- A new total is added to the cart items:
customOptions. It holds the addition of all custom option prices. It is added to the existing cart item subtotal.
- Add to Cart: Added item need to include specified options with values and prices when applies.
- Get Scoped Product: Get product with custom option prices.
- Get Scoped Produst List: Get products with custom option prices.