clean-jsdoc-theme TypeDoc APIv0.0.0

Product

Source: Product.ts:230

Product class implementation

Remarks

Provides a complete product model with utility methods for price calculations, stock management, and data transformation.

Example

CODE
const product = new Product({
  id: 'prod-123',
  sku: 'WIDGET-001',
  name: 'Super Widget',
  shortDescription: 'The best widget ever made',
  description: '## Features\n- Durable\n- Lightweight\n- Eco-friendly',
  category: ProductCategory.Electronics,
  tags: ['widget', 'gadget', 'popular'],
  price: { amount: 2999, currency: 'USD' },
  availability: AvailabilityStatus.InStock,
  stockQuantity: 100,
  images: ['https://example.com/widget.jpg'],
  variants: [],
  averageRating: 4.5,
  reviewCount: 42,
  createdAt: new Date(),
  updatedAt: new Date(),
  isFeatured: true,
  isActive: true
})

console.log(product.getFormattedPrice()) // "$29.99"

Constructors

new Product(data: IProduct): Product

Parameters

Returns

Product

Implements


Properties

availability: AvailabilityStatus

Implementation of availability

Current availability status

averageRating: number

Implementation of averageRating

Average rating (1-5)

category: ProductCategory

Implementation of category

Product category

createdAt: Date

Implementation of createdAt

Product creation date

description: string

Implementation of description

Full product description (supports markdown)

dimensions: Dimensions

Implementation of dimensions

Product dimensions and weight

id: string

Implementation of id

Unique product identifier

images: string[]

Implementation of images

Product images URLs

isActive: boolean

Implementation of isActive

Whether product is active/visible

isFeatured: boolean

Implementation of isFeatured

Whether product is featured

name: string

Implementation of name

Product name

price: Price

Implementation of price

Price information

reviewCount: number

Implementation of reviewCount

Total number of reviews

shortDescription: string

Implementation of shortDescription

Short description (max 200 chars)

sku: string

Implementation of sku

Product SKU (Stock Keeping Unit)

stockQuantity: number

Implementation of stockQuantity

Current stock quantity

tags: string[]

Implementation of tags

Product tags for searching

updatedAt: Date

Implementation of updatedAt

Last update date

variants: ProductVariant<string>[]

Implementation of variants

Product variants (colors, sizes, etc.)

Methods

canPurchase(): boolean

Checks if the product is available for purchase

Returns

  • boolean — True if product can be purchased

getDiscountAmount(): number

Calculates the discount amount

Returns

  • number — Discount amount in smallest currency unit, or 0 if no discount

getFormattedPrice(locale: string): string

Formats the price for display

Parameters

  • locale (string, default: "'en-US'") — Locale for formatting (default: 'en-US')

Returns

  • string — Formatted price string

Example

CODE
product.getFormattedPrice() // "$29.99"
product.getFormattedPrice('de-DE') // "29,99 €"

getTotalPrice(variantId?: string): number

Calculates total price for a variant

Parameters

  • variantId (string, optional) — Optional variant ID

Returns

  • number — Total price amount including variant adjustment

getVariant< T = string, >( variantId: string, ): ProductVariant<T> | undefined

Gets a specific variant by ID

Type Parameters

  • T = string — Variant value type

Parameters

  • variantId (string) — The variant identifier

Returns

  • ProductVariant<T> | undefined — The variant or undefined if not found

updateStock(quantity: number): this

Updates stock quantity and availability status

Parameters

  • quantity (number) — New stock quantity

Returns

  • this — The updated product instance

Example

CODE
product.updateStock(5) // Sets to low stock
product.updateStock(0) // Sets to out of stock