Order
Order
An Order is created whenever a Customer adds an item to the cart. It contains all the information required to fulfill an order: which ProductVariants in what quantities; the shipping address and price; any applicable promotions; payments etc.
An Order exists in a well-defined state according to the OrderState type. A state machine is used to govern the transition from one state to another.
Signature
class Order extends VendureEntity implements ChannelAware, HasCustomFields {
constructor(input?: DeepPartial<Order>)
@Column('varchar', { default: OrderType.Regular }) @Column('varchar', { default: OrderType.Regular })
type: OrderType;
@OneToMany(type => Order, sellerOrder => sellerOrder.aggregateOrder) @OneToMany(type => Order, sellerOrder => sellerOrder.aggregateOrder)
sellerOrders: Order[];
@Index() @ManyToOne(type => Order, aggregateOrder => aggregateOrder.sellerOrders) @Index()
@ManyToOne(type => Order, aggregateOrder => aggregateOrder.sellerOrders)
aggregateOrder?: Order;
@EntityId({ nullable: true }) @EntityId({ nullable: true })
aggregateOrderId?: ID;
@Column() @Index({ unique: true }) @Column()
@Index({ unique: true })
code: string;
@Column('varchar') @Column('varchar') state: OrderState;
@Column({ default: true }) @Column({ default: true })
active: boolean;
@Column({ nullable: true }) @Column({ nullable: true })
orderPlacedAt?: Date;
@Index() @ManyToOne(type => Customer) @Index()
@ManyToOne(type => Customer)
customer?: Customer;
@EntityId({ nullable: true }) @EntityId({ nullable: true })
customerId?: ID;
@OneToMany(type => OrderLine, line => line.order) @OneToMany(type => OrderLine, line => line.order)
lines: OrderLine[];
@OneToMany(type => Surcharge, surcharge => surcharge.order) @OneToMany(type => Surcharge, surcharge => surcharge.order)
surcharges: Surcharge[];
@Column('simple-array') @Column('simple-array')
couponCodes: string[];
@ManyToMany(type => Promotion) @JoinTable() @ManyToMany(type => Promotion)
@JoinTable()
promotions: Promotion[];
@Column('simple-json') @Column('simple-json') shippingAddress: OrderAddress;
@Column('simple-json') @Column('simple-json') billingAddress: OrderAddress;
@OneToMany(type => Payment, payment => payment.order) @OneToMany(type => Payment, payment => payment.order)
payments: Payment[];
@ManyToMany(type => Fulfillment) @JoinTable() @ManyToMany(type => Fulfillment)
@JoinTable()
fulfillments: Fulfillment[];
@Column('varchar') @Column('varchar')
currencyCode: CurrencyCode;
@Column(type => CustomOrderFields) @Column(type => CustomOrderFields)
customFields: CustomOrderFields;
@EntityId({ nullable: true }) @EntityId({ nullable: true })
taxZoneId?: ID;
@ManyToMany(type => Channel) @JoinTable() @ManyToMany(type => Channel)
@JoinTable()
channels: Channel[];
@OneToMany(type => OrderModification, modification => modification.order) @OneToMany(type => OrderModification, modification => modification.order)
modifications: OrderModification[];
@Money() @Money()
subTotal: number;
@Money() @Money()
subTotalWithTax: number;
@OneToMany(type => ShippingLine, shippingLine => shippingLine.order) @OneToMany(type => ShippingLine, shippingLine => shippingLine.order)
shippingLines: ShippingLine[];
@Money({ default: 0 }) @Money({ default: 0 })
shipping: number;
@Money({ default: 0 }) @Money({ default: 0 })
shippingWithTax: number;
@Calculated({ relations: ['lines', 'shippingLines'] }) discounts: Discount[]
@Calculated({
query: qb =>
qb
.leftJoin(
qb1 => {
return qb1
.from(Order, 'order')
.select('order.shipping + order.subTotal', 'total')
.addSelect('order.id', 'oid');
},
't1',
't1.oid = order.id',
)
.addSelect('t1.total', 'total'),
expression: 'total',
}) total: number
@Calculated({
query: qb =>
qb
.leftJoin(
qb1 => {
return qb1
.from(Order, 'order')
.select('order.shippingWithTax + order.subTotalWithTax', 'twt')
.addSelect('order.id', 'oid');
},
't1',
't1.oid = order.id',
)
.addSelect('t1.twt', 'twt'),
expression: 'twt',
}) totalWithTax: number
@Calculated({
relations: ['lines'],
query: qb => {
qb.leftJoin(
qb1 => {
return qb1
.from(Order, 'order')
.select('SUM(lines.quantity)', 'qty')
.addSelect('order.id', 'oid')
.leftJoin('order.lines', 'lines')
.groupBy('order.id');
},
't1',
't1.oid = order.id',
).addSelect('t1.qty', 'qty');
},
expression: 'qty',
}) totalQuantity: number
@Calculated({ relations: ['lines'] }) taxSummary: OrderTaxSummary[]
}
Extends
Implements
- ChannelAware
- HasCustomFields
Members
constructor
method
type:
(input?: DeepPartial<Order>) => Order
type
property
type:
OrderType
sellerOrders
property
type:
Order[]
aggregateOrder
property
type:
Order
aggregateOrderId
property
type:
ID
code
property
type:
string
A unique code for the Order, generated according to the
OrderCodeStrategy. This should be used as an order reference
for Customers, rather than the Order’s id.
state
property
type:
OrderState
active
property
type:
boolean
Whether the Order is considered “active”, meaning that the
Customer can still make changes to it and has not yet completed
the checkout process.
This is governed by the OrderPlacedStrategy.
orderPlacedAt
property
type:
Date
The date & time that the Order was placed, i.e. the Customer
completed the checkout and the Order is no longer “active”.
This is governed by the OrderPlacedStrategy.
customer
property
type:
Customer
customerId
property
type:
ID
lines
property
type:
OrderLine[]
surcharges
property
type:
Surcharge[]
Surcharges are arbitrary modifications to the Order total which are neither
ProductVariants nor discounts resulting from applied Promotions. For example,
one-off discounts based on customer interaction, or surcharges based on payment
methods.
couponCodes
property
type:
string[]
An array of all coupon codes applied to the Order.
promotions
property
type:
Promotion[]
Promotions applied to the order. Only gets populated after the payment process has completed,
i.e. the Order is no longer active.
shippingAddress
property
type:
OrderAddress
billingAddress
property
type:
OrderAddress
payments
property
type:
Payment[]
fulfillments
property
type:
Fulfillment[]
currencyCode
property
type:
CurrencyCode
customFields
property
type:
CustomOrderFields
taxZoneId
property
type:
ID
channels
property
type:
Channel[]
modifications
property
type:
OrderModification[]
subTotal
property
type:
number
The subTotal is the total of all OrderLines in the Order. This figure also includes any Order-level
discounts which have been prorated (proportionally distributed) amongst the OrderItems.
To get a total of all OrderLines which does not account for prorated discounts, use the
sum of OrderLine’s
discountedLinePrice
values.
subTotalWithTax
property
type:
number
Same as subTotal, but inclusive of tax.
shippingLines
property
type:
ShippingLine[]
The shipping charges applied to this order.
shipping
property
type:
number
The total of all the
shippingLines
.
shippingWithTax
property
type:
number
discounts
property
type:
Discount[]
total
property
type:
number
Equal to
subTotal
plus shipping
totalWithTax
property
type:
number
The final payable amount. Equal to
subTotalWithTax
plus shippingWithTax
.
totalQuantity
property
type:
number
taxSummary
property
type:
OrderTaxSummary[]
A summary of the taxes being applied to this Order.