@hyperse-hub/hps-plugin-token-active-order
Token-based active order strategy for Vendure.
This plugin prepends a custom activeOrderStrategy which can resolve the active order by
Order.customFields.orderToken. It is useful for server-to-server scenarios where you
can't rely on a browser session.
Install
yarn add @hyperse-hub/hps-plugin-token-active-order
Register the plugin in your Vendure config:
import { HpsPluginTokenActiveOrder } from '@hyperse-hub/hps-plugin-token-active-order';
plugins: [
HpsPluginTokenActiveOrder.init({
verifyActiveOrderOwner: false,
}),
];
Options
verifyActiveOrderOwner: When true, the token-resolved order will only be treated as
active if it belongs to the current active user.
Usage
Resolve active order by token
The plugin adds a orderToken input to Shop API activeOrder input.
query ActiveOrderByToken($token: String!) {
activeOrder(input: { orderToken: { token: $token } }) {
id
code
state
}
}
Add item to order (Shop API)
Once you have an active order (session-based or token-based), you can use Vendure's built-in
mutation addItemToOrder.
mutation AddItem($productVariantId: ID!, $quantity: Int!) {
addItemToOrder(productVariantId: $productVariantId, quantity: $quantity) {
... on Order {
id
lines {
id
quantity
productVariant {
id
}
}
}
... on ErrorResult {
errorCode
message
}
}
}