Draft orders: build an order for a customer (custom pricing, B2B, phone orders), send its invoice URL, then complete it into a real order. Needs write_draft_orders.

Values

DRAFT_ORDER_FIELDS

DRAFT_ORDER_FIELDS: Str "id name status invoiceUrl createdAt\ntotalPriceSet { shopMoney { amount currencyCode } }\norder { id name }"

Functions

build-complete-variables

fn (id: Str, options: Map): Map

Variables for draftOrderComplete. Options: paymentGatewayId, sourceName. Unset options are omitted. Exposed for testing.

complete-draft-order

fn (id: Str): Map
fn (id: Str, options: Map): Map
fn (id: Str, options: Map, opts: Map): Map

Turn a draft order into an order (draftOrderComplete), marked paid. Options: paymentGatewayId, sourceName (a channel handle for attribution). To leave it payment pending, give the draft order payment terms instead (Shopify deprecated paymentPending). Returns the draft order with the new order {id name}.

create-draft-order

fn (input: Map): Map
fn (input: Map, opts: Map): Map

Create a draft order (draftOrderCreate) from a DraftOrderInput: lineItems ([{variantId, quantity}] or custom [{title, originalUnitPriceWithCurrency: {amount, currencyCode}, quantity}]), customerId via purchasingEntity: {customerId}, email, shippingAddress, note, tags, appliedDiscount, ... Returns the draft order with its invoiceUrl.

Example

draft ::shopify::draft-orders/create-draft-order({
  email: "ada@example.com",
  lineItems: [{variantId: variant.id, quantity: 2}]
})

get-draft-order

fn (id: Str): Map?
fn (id: Str, opts: Map): Map?

One draft order by GraphQL id with its line items. Returns null when not found.