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 }) @Column({ type: Date, nullable: true })
deletedAt: Date | null;
name: LocaleString;
@Column({ default: true }) @Column({ default: true })
enabled: boolean;
@Column() @Column()
sku: string;
listPrice: number;
listPriceIncludesTax: boolean;
currencyCode: CurrencyCode;
@Calculated({
expression: 'productvariant_productVariantPrices.price',
}) price: number
@Calculated({
// Note: this works fine for sorting by priceWithTax, but filtering will return inaccurate
// results due to this expression not taking taxes into account. This is because the tax
// rate is calculated at run-time in the application layer based on the current context,
// and is unknown to the database.
expression: 'productvariant_productVariantPrices.price',
}) priceWithTax: number
taxRateApplied: TaxRate;
@Index() @ManyToOne(type => Asset, { onDelete: 'SET NULL' }) @Index()
@ManyToOne(type => Asset, { onDelete: 'SET NULL' })
featuredAsset: Asset;
@OneToMany(type => ProductVariantAsset, productVariantAsset => productVariantAsset.productVariant, {
onDelete: 'SET NULL',
}) @OneToMany(type => ProductVariantAsset, productVariantAsset => productVariantAsset.productVariant, {
onDelete: 'SET NULL',
})
assets: ProductVariantAsset[];
@Index() @ManyToOne(type => TaxCategory) @Index()
@ManyToOne(type => TaxCategory)
taxCategory: TaxCategory;
@OneToMany(type => ProductVariantPrice, price => price.variant, { eager: true }) @OneToMany(type => ProductVariantPrice, price => price.variant, { eager: true })
productVariantPrices: ProductVariantPrice[];
@OneToMany(type => ProductVariantTranslation, translation => translation.base, { eager: true }) @OneToMany(type => ProductVariantTranslation, translation => translation.base, { eager: true })
translations: Array<Translation<ProductVariant>>;
@Index() @ManyToOne(type => Product, product => product.variants) @Index()
@ManyToOne(type => Product, product => product.variants)
product: Product;
@EntityId({ nullable: true }) @EntityId({ nullable: true })
productId: ID;
@Column({ default: 0 }) @Column({ default: 0 })
outOfStockThreshold: number;
@Column({ default: true }) @Column({ default: true })
useGlobalOutOfStockThreshold: boolean;
@Column({ type: 'varchar', default: GlobalFlag.INHERIT }) @Column({ type: 'varchar', default: GlobalFlag.INHERIT })
trackInventory: GlobalFlag;
@OneToMany(type => StockLevel, stockLevel => stockLevel.productVariant) @OneToMany(type => StockLevel, stockLevel => stockLevel.productVariant)
stockLevels: StockLevel[];
@OneToMany(type => StockMovement, stockMovement => stockMovement.productVariant) @OneToMany(type => StockMovement, stockMovement => stockMovement.productVariant)
stockMovements: StockMovement[];
@ManyToMany(type => ProductOption) @JoinTable() @ManyToMany(type => ProductOption)
@JoinTable()
options: ProductOption[];
@ManyToMany(type => FacetValue) @JoinTable() @ManyToMany(type => FacetValue)
@JoinTable()
facetValues: FacetValue[];
@Column(type => CustomProductVariantFields) @Column(type => CustomProductVariantFields)
customFields: CustomProductVariantFields;
@ManyToMany(type => Collection, collection => collection.productVariants) @ManyToMany(type => Collection, collection => collection.productVariants)
collections: Collection[];
@ManyToMany(type => Channel) @JoinTable() @ManyToMany(type => Channel)
@JoinTable()
channels: Channel[];
}
Extends
Implements
- Translatable
- HasCustomFields
- SoftDeletable
- ChannelAware
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
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
stockLevels
property
type:
StockLevel[]
stockMovements
property
type:
StockMovement[]
options
property
type:
ProductOption[]
facetValues
property
type:
FacetValue[]
customFields
property
type:
CustomProductVariantFields
collections
property
type:
Collection[]
channels
property
type:
Channel[]