Postman collection
Orderlines Write

pixiAddOrderLine

Adds a new order line for an item to an existing order, calculates prices and discounts, and returns the new order line ID or validation errors.

Adds one order line (Orderlines row) to the order PixiOrderNr.

1. Normalisation

  • ItemKey = 0 is treated as NULL and ItemNrInt = '' as NULL.
  • An empty Date becomes the current date/time.
  • An empty Status becomes NEW.
  • A NULL UsePaymentStatus becomes 0 and a NULL LocationID becomes 001.

2. Validation All failed checks are collected, and each one adds an error row:

  • UsePaymentStatus = 1 together with a Status other than NEW is rejected.
  • Status must be one of NEW, ANG, HAL, FUT, STO, NLB.
  • If ItemNrInt is given, the item is looked up by ItemNrInt. The found key replaces ItemKey. If no item matches, an error is raised.
  • If no error has occurred so far, the item must have an entry in pixi.ItemCode.
  • A non-zero Discount (voucher amount) requires VoucherID.
  • If the order already has a line with a voucher, a different VoucherID is rejected. Only one voucher per order is allowed.

If any check fails, the error rows are returned and nothing is written.

3. Status from payment method With UsePaymentStatus = 1, the line status is taken from Payments.IniOrderStatus of the payment method of the order's billing address.

4. Can lines be added? pipiCanAddOrderlines checks whether the order still accepts new lines:

  • For payment methods K/C, all existing lines must be in NEW, ANG, HAL, MIN, OPH, BES, STO or NLB.
  • For other payment methods, no line may be in EIN or AUS.

Only if the result is 1 is the line created.

5. Header data

  • Customer, addresses, order type, currency and the existing header values are read from the order.
  • OrderNrExternal is taken from the order header. If the header has none, the parameter is used. If that is also missing, a timestamp string is generated.
  • Employee is stored as <Employee> (API), or as API if Employee is not given.

6. Currency If the setting MultiCurrencyEnabled is off, or the order has no exchange rate, the database currency is used with rate 1. Otherwise:

  • Today's exchange rates are read from pixi.ExchRate.
  • The database currency uses its rate source.
  • The base currency of the order's exchange rate record uses the shop's ExchRateSourceID as source.

7. Prices

  • FullPrice (gross) and its net counterpart come from the parameter if it is non-zero.
  • Otherwise the item price is used: the price in the order currency first, then the base-currency price × rate, then the database-currency price × rate, else 0.
  • For B2B orders, the FullPrice parameter is interpreted as the net price, and the gross price is always taken from the item prices.
  • ItemName overrides the item name.

8. Discount per line

  • FullPriceDiscountValue is used if it is given.
  • Otherwise DiscountPercent % of the gross price (B2C) or of the net price (other order types) is used.
  • Otherwise the full price minus DiscountedPrice is used.
  • Otherwise the discount is 0.

The same discount value is subtracted from both the gross and the net price to get Price and Price_Net.

9. Order header values

  • ShipCost, Discount, AddressRemarks, Verfahren, Product and Extras are taken from the parameters if they are non-empty or non-zero. Otherwise the existing header values are kept.
  • An existing voucher of the order always wins over VoucherID.

10. Insert The line is inserted via Pixi_InsertOrderline with these fixed values:

  • source I
  • line type ORD
  • wait days 15
  • LocationID as stock location and last order location

The call then returns a row with CanAdd = 1 and the new OrderlineId.

Notes

  • No result when lines cannot be added: if pipiCanAddOrderlines returns 0 or NULL, the call returns no rows at all. This happens when the order is not found or a line is already in a blocking status. Treat an empty response as "not added".
  • Duplicate error row: the check for UsePaymentStatus = 1 with Status ≠ NEW runs twice, so that error appears twice in the result.
  • Status not re-checked: a status taken from the payment method (UsePaymentStatus = 1) is not validated against the allowed list.
  • Item price required: the item must have a price row in the database currency (inner join on pixi.ItemPrice). Otherwise item data and prices are not filled and the line may be created without EAN or price.
  • Order header is overwritten: Pixi_InsertOrderline updates the header columns GiftMessage, ShipInstruct, Discount, Address_Remarks, Verfahren, Product, Extras, Shipdate and the tax rates.
    • GiftMessage defaults to '' and therefore overwrites an existing gift message.
    • ShipInstruct is set to '' and Shipdate to NULL.
  • Voucher creation: if the resulting Discount > 0 and no Voucher row with that ID exists, a voucher is created with shop GRM and the order currency. The expiry is computed with DATEADD(y, 1, …); datepart y means day of year, so it lies one day after the order date.
  • Logging: if OrderNrExternal differs from the header value, an entry is written to LogTable.
  • Transaction: the insert runs in a transaction inside Pixi_InsertOrderline.
  • Order line ID: the new ID is read from a temp table that is filled by an INSTEAD OF trigger on Orderlines. The trigger is not attached. If no ID is returned, OrderlineId is NULL although CanAdd = 1.
  • Reads: all reads use NOLOCK.
  • Exchange rates: rates are looked up only for the current date. If no rate exists for today, converted prices become NULL.

Tables used

Orderlines · Write OrderHeader · Write Voucher · Write LogTable · Write Items · Read ItemCode · Read ItemPrice · Read OrderStates · Read Addresses · Read Payments · Read Customers · Read Shops · Read ExchRate · Read Currency · Read Settings · Read
SQL object:
dbo.pipiAddOrderLine
Updated at 2026-10-30