Skip to content

Commit 7626e3f

Browse files
docs: Generate docs for source changes
1 parent 4063eff commit 7626e3f

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

docs/docs/reference/typescript-api/entities/order-line.mdx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class OrderLine extends VendureEntity implements HasCustomFields {
8484
proratedLinePriceWithTax: number
8585
proratedLineTax: number
8686
addAdjustment(adjustment: Adjustment) => ;
87+
setQuantityRescalingAdjustments(newQuantity: number) => ;
8788
clearAdjustments(type?: AdjustmentType) => ;
8889
}
8990
```
@@ -324,6 +325,18 @@ The `proratedLinePrice` including tax.
324325
<MemberInfo kind="method" type={`(adjustment: Adjustment) => `} />
325326

326327

328+
### setQuantityRescalingAdjustments
329+
330+
<MemberInfo kind="method" type={`(newQuantity: number) => `} />
331+
332+
Sets this line's quantity to `newQuantity`, rescaling its `PROMOTION`-type adjustments to
333+
match. Used where a quantity reduction bypasses `OrderCalculator` recalculation (see
334+
`OrderModifier.cancelOrderByOrderLines()`), to preserve the invariant that `PROMOTION`
335+
amounts are stored scaled to the current quantity.
336+
337+
A `newQuantity` of 0 sets the quantity but leaves the adjustments untouched: the getters
338+
short-circuit on an empty line either way, so scaling them to zero would only erase the
339+
record of the discount that had applied, which plugins and accounting exports read back.
327340
### clearAdjustments
328341

329342
<MemberInfo kind="method" type={`(type?: AdjustmentType) => `} />
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
title: "RescaleOrderLinePromotionAdjustments"
3+
generated: true
4+
---
5+
<GenerationInfo sourceFile="packages/core/src/migration-utils/v3_8_orderline_promotion_rescale.ts" sourceLine="156" packageName="@vendure/core" since="3.8.0" />
6+
7+
Rescales `PROMOTION`-type `Adjustment`s on `order_line` rows that were partially
8+
cancelled by a pre-#5127 `cancelOrderByOrderLines()`, which reduced `quantity`
9+
without rescaling `adjustments`. Reading those rows with the fixed `OrderLine`
10+
getters (which divide a `PROMOTION` adjustment by the *current* `quantity`,
11+
instead of `orderPlacedQuantity`) would otherwise inflate their discount.
12+
13+
`OrderModifier.modifyOrder()` ends in `applyPriceAdjustments()`, which recomputes the
14+
`PROMOTION` amounts for every line in the order, including lines not referenced by the
15+
`OrderModification`. For a subsequently-cancelled line, the stored basis is its current
16+
quantity plus the quantities in order-cancellation history after the order's latest
17+
`OrderModification`.
18+
19+
Some databases can store a modification and cancellation with the same timestamp. Their
20+
order is then unknowable from persisted data, so the helper throws before writing anything.
21+
Inspect those lines and pass `ambiguousOrderLineQuantityBases`: use the current quantity if
22+
the modification happened last, or the quantity before cancellation if cancellation happened
23+
last.
24+
25+
Call this from your migration's `up()` method - it needs no schema change, so it
26+
can run at any point in the migration.
27+
28+
```ts
29+
import { MigrationInterface, QueryRunner } from 'typeorm';
30+
import { rescaleOrderLinePromotionAdjustments } from '@vendure/core';
31+
32+
export class RescaleOrderLinePromotionAdjustments1234567890 implements MigrationInterface {
33+
public async up(queryRunner: QueryRunner): Promise<any> {
34+
await rescaleOrderLinePromotionAdjustments(queryRunner);
35+
}
36+
37+
public async down(queryRunner: QueryRunner): Promise<any> {
38+
// This is a one-way data migration - the pre-migration amounts are not recoverable.
39+
}
40+
}
41+
```
42+
43+
```ts title="Signature"
44+
function rescaleOrderLinePromotionAdjustments(queryRunner: QueryRunner, options: RescaleOrderLinePromotionAdjustmentsOptions = {}): Promise<void>
45+
```
46+
Parameters
47+
48+
### queryRunner
49+
50+
<MemberInfo kind="parameter" type={`QueryRunner`} />
51+
52+
### options
53+
54+
<MemberInfo kind="parameter" type={`RescaleOrderLinePromotionAdjustmentsOptions`} />
55+

0 commit comments

Comments
 (0)