Skip to content

Search is only available in production builds. Try building and previewing the site to test it out locally.

Purchase Order initialization

The Purchase Order initializer configures the drop-in for managing purchase order workflows, approval rules, and order tracking. Use initialization to set the purchase order reference, customize data models, and enable internationalization for multi-language B2B storefronts.

Version: 1.0.0-beta2

Configuration options

The following table describes the configuration options available for the Purchase Order initializer:

ParameterTypeReq?Description
langDefinitionsLangDefinitionsNoLanguage definitions for internationalization (i18n). Override dictionary keys for localization or branding.
poRefstringNoPurchase order reference identifier used to load and display a specific purchase order. Pass this to initialize the drop-in with purchase order details on page load.

Default configuration

The initializer runs with these defaults when no configuration is provided:

import { initializers } from '@dropins/tools/initializer.js';
import { initialize } from '@dropins/storefront-purchase-order';
// All configuration options are optional
await initializers.mountImmediately(initialize, {
langDefinitions: {}, // Uses built-in English strings
models: {}, // Uses default data models
// Drop-in-specific defaults:
// poRef: undefined // See configuration options below
});

Language definitions

Override dictionary keys for localization or branding. The langDefinitions object maps locale keys to custom strings that override default text for the drop-in.

import { initializers } from '@dropins/tools/initializer.js';
import { initialize } from '@dropins/storefront-purchase-order';
const customStrings = {
'AddToCart': 'Add to Bag',
'Checkout': 'Complete Purchase',
'Price': 'Cost',
};
const langDefinitions = {
default: customStrings,
};
await initializers.mountImmediately(initialize, { langDefinitions });

Customizing data models

Extend or transform data models by providing custom transformer functions. Use the models option to add custom fields or modify existing data structures returned from the backend.

Available models

The following models can be customized through the models configuration option:

ModelDescription
PurchaseOrderModelTransforms purchase order data from GraphQL including order details, approval status, items, totals, and history. Use this to add custom fields or modify existing purchase order data structures.

The following example shows how to customize the PurchaseOrderModel model for the Purchase Order drop-in:

import { initializers } from '@dropins/tools/initializer.js';
import { initialize } from '@dropins/storefront-purchase-order';
const models = {
PurchaseOrderModel: {
transformer: (data) => ({
// Add approval status badge text
approvalStatusDisplay: data?.status === 'PENDING' ? 'Awaiting Approval' :
data?.status === 'APPROVED' ? 'Approved - Ready to Order' :
data?.status,
// Add formatted approval flow summary
approvalSummary: data?.approvalFlow?.map(rule =>
`${rule.ruleName}: ${rule.events?.length || 0} events`
).join(', '),
// Add created by full name
createdByName: data?.createdBy ?
`${data.createdBy.firstname} ${data.createdBy.lastname}` : null,
}),
},
};
await initializers.mountImmediately(initialize, { models });

Drop-in configuration

The Purchase Order initializer configures the drop-in for managing purchase order workflows, approval rules, and order tracking. Use initialization to set the purchase order reference, customize data models, and enable internationalization for multi-language B2B storefronts.

import { initializers } from '@dropins/tools/initializer.js';
import { initialize } from '@dropins/storefront-purchase-order';
await initializers.mountImmediately(initialize, {
langDefinitions: {},
poRef: 'abc123',
});

Configuration types

The following TypeScript definitions show the structure of each configuration object:

langDefinitions

Maps locale identifiers to dictionaries of key-value pairs. The default locale is used as the fallback when no specific locale matches. Each dictionary key corresponds to a text string used in the drop-in UI.

langDefinitions?: {
[locale: string]: {
[key: string]: string;
};
};

Model definitions

The following TypeScript definitions show the structure of each customizable model:

PurchaseOrderModel

interface PurchaseOrderModel {
typename: string;
uid: string;
number: string;
status: string;
availableActions: string[];
approvalFlow:
| {
ruleName: string;
events: Array<{
message: string;
name: string;
role: string;
status: string;
updatedAt: string;
}>;
}[]
| [];
comments?: Array<{
uid: string;
createdAt: string;
author: {
firstname: string;
lastname: string;
email: string;
};
text: string;
}>;
createdAt: string;
updatedAt: string;
createdBy: {
firstname: string;
lastname: string;
email: string;
};
historyLog?: Array<{
activity: string;
createdAt: string;
message: string;
uid: string;
}>;
quote: QuoteProps | null;
order: {
orderNumber: string;
id: string;
};
}