# Purchase order

An object representing a purchase order for the current shop. At the present moment purchase orders are used to indicate when a product that is out of stock is expected to be in stock again.

To be able to access this API class the webshop must have enabled the purchase orders functionality.

# Properties

Property Type Description
uid integer The unique identifier of the purchase order.
reference string A unique reference to the purchase order, for example a referense to the purchase order in an external system. The reference can be set only when creating a new purchase order, it can not be changed after that.
status string The status of the pruchase orders, valid values are "active" and "inactive".

# Methods

# create

Creates a new purchase order. This is shorthand for set with the unique identifier null.

# Parameters

Parameters Description
reference A unique reference to the purchase order.
status Valid values are "active" and "inactive".

# delete

Removes an existing purchase order.

# Parameters

Parameters Description
uid UID of object to delete.

# get

Fetches information about a purchase order.

# Parameters

Parameter Description
uid The unique identifier of the purchase order.
query Which info to return. See Query language.

# Example 1

PurchaseOrder.get(12345)

# getSchema

Fetches the JSON Schema which can be used for client-side validation.

# Parameters

The unique identifier of the purchase order.

# list

Returns an array of objects representing purchase orders.

# Example 2

PurchaseOrder.list(true, {
  "filters": {
    "/status": "active"
  }
})

# Example 3

PurchaseOrder.list(true, {
  "filters": {
    "/reference": "my unique reference"
  }
})

# Parameters

Parameter Description
query Which info to return. See Query language.
selection Which purchase orders to list. See List selection.

# getByReference

Utility method to simplify getting a purchase order with given referens, see example 3 above.

# Parameters

Parameter Description
reference The unique reference of the purchase order
query A query specifying what to return after a successful set (optional). See Query language.

# Example 4

PurchaseOrder.getByReference("my unique reference", true)

# set

Creates or updates a purchase order.

# Parameters

Parameter Description
uid The unique identifier of the purchase order or null to create a new purchase order.
patch An object containing the properties and values to set for the purchase order.
query A query specifying what to return after a successful set (optional). See Query language.

# Example 5

PurchaseOrder.set(1, {
  "status": "inactive"
}, true)

# setItem

Utitility method to simplify adding or updating purchase order iten (a product) in the purchase order.

# Parameters

Parameter Description
uid The unique identifier of the purchase order
item An object refresentoing containing the properties and values to set for the purchase order. See below.
query A query specifying what to return after a successful set (optional). See Query language and Purchase order item.

# Purchase order item data

Parameter Description
articleUid The unique identifier of the article
variantUid The unique identifier of the article variant
articleNumber The article number of the article or variant of article
quantity How many items has been ordered
deliveryDate Expected delivery date

Please note that you must specify one, and only one, of articleUid, variantUid or articleNumber.

# Example 6

Add or update PurchaseOrderItem for Article or ArticleVariant with article number "hat".

PurchaseOrder.setItem(1, {
  "articleNumber": "hat",
  "quantity": 18,
  "deliveryDate": "2024-08-13"
}, true)

# Example 7

Add or update PurchaseOrderItem for Article with Uid 12345.

PurchaseOrder.setItem(1, {
  "articleUid": 12345,
  "quantity": 50,
  "deliveryDate": "2024-08-30"
}, true)

# Example 8

Add or update PurchaseOrderItem for ArticleVariant with Uid 54321.

PurchaseOrder.setItem(1, {
  "variantUid": 54321,
  "quantity": 50,
  "deliveryDate": "2024-08-30"
}, true)