ProductVariant

ProductVariant

A ProductVariant represents a single stock keeping unit (SKU) in the store’s inventory. Whereas a Product is a “container” of variants, the variant itself holds the data on price, tax category etc. When one adds items to their cart, they are adding ProductVariants, not Products.

Signature

class ProductVariant extends VendureEntity implements Translatable, HasCustomFields, SoftDeletable, ChannelAware {
  constructor(input?: DeepPartial<ProductVariant>)
  @Column({ type: Date, nullable: true })
    deletedAt: Date | null;
  name: LocaleString;
  @Column({ default: true })
    enabled: boolean;
  @Column()
    sku: string;
  listPrice: number;
  listPriceIncludesTax: boolean;
  currencyCode: CurrencyCode;
  price: number
  priceWithTax: number
  taxRateApplied: TaxRate;
  @ManyToOne(type => Asset, { onDelete: 'SET NULL' })
    featuredAsset: Asset;
  @OneToMany(type => ProductVariantAsset, productVariantAsset => productVariantAsset.productVariant, {
        onDelete: 'SET NULL',
    })
    assets: ProductVariantAsset[];
  @ManyToOne(type => TaxCategory)
    taxCategory: TaxCategory;
  @OneToMany(type => ProductVariantPrice, price => price.variant, { eager: true })
    productVariantPrices: ProductVariantPrice[];
  @OneToMany(type => ProductVariantTranslation, translation => translation.base, { eager: true })
    translations: Array<Translation<ProductVariant>>;
  @ManyToOne(type => Product, product => product.variants)
    product: Product;
  @EntityId({ nullable: true })
    productId: ID;
  @Column({ default: 0 })
    stockOnHand: number;
  @Column({ default: 0 })
    stockAllocated: number;
  @Column({ default: 0 })
    outOfStockThreshold: number;
  @Column({ default: true })
    useGlobalOutOfStockThreshold: boolean;
  @Column({ type: 'varchar', default: GlobalFlag.INHERIT })
    trackInventory: GlobalFlag;
  @OneToMany(type => StockMovement, stockMovement => stockMovement.productVariant)
    stockMovements: StockMovement[];
  @ManyToMany(type => ProductOption)
    @JoinTable()
    options: ProductOption[];
  @ManyToMany(type => FacetValue)
    @JoinTable()
    facetValues: FacetValue[];
  @Column(type => CustomProductVariantFields)
    customFields: CustomProductVariantFields;
  @ManyToMany(type => Collection, collection => collection.productVariants)
    collections: Collection[];
  @ManyToMany(type => Channel)
    @JoinTable()
    channels: Channel[];
}

Extends

Implements

Members

constructor

method
type:
(input?: DeepPartial<ProductVariant>) => ProductVariant

deletedAt

property
type:
Date | null

name

property
type:
LocaleString

enabled

property
type:
boolean

sku

property
type:
string

listPrice

property
type:
number

listPriceIncludesTax

property
type:
boolean

currencyCode

property
type:
CurrencyCode

price

property
type:
number

priceWithTax

property
type:
number

taxRateApplied

property
type:
TaxRate

featuredAsset

property
type:
Asset

assets

property
type:
ProductVariantAsset[]

taxCategory

property
type:
TaxCategory

productVariantPrices

property
type:
ProductVariantPrice[]

translations

property
type:
Array<Translation<ProductVariant>>

product

property
type:
Product

productId

property
type:
ID

stockOnHand

property
type:
number

stockAllocated

property
type:
number

outOfStockThreshold

property
type:
number
Specifies the value of stockOnHand at which the ProductVariant is considered out of stock.

useGlobalOutOfStockThreshold

property
type:
boolean
When true, the outOfStockThreshold value will be taken from the GlobalSettings and the value set on this ProductVariant will be ignored.

trackInventory

property
type:
GlobalFlag

stockMovements

property
type:
StockMovement[]

options

property
type:
ProductOption[]

facetValues

property
type:
FacetValue[]

customFields

property
type:
CustomProductVariantFields

collections

property
type:
Collection[]

channels

property
type:
Channel[]