docs: fix cart completion in subscriptions recipe (#10021)

This commit is contained in:
Shahed Nasser
2024-11-11 20:37:26 +02:00
committed by GitHub
parent a131a4468d
commit 713e428ec2
@@ -591,9 +591,10 @@ The compensation function receives the subscription as a parameter. It cancels t
Create the file `src/workflows/create-subscription/index.ts` with the following content: Create the file `src/workflows/create-subscription/index.ts` with the following content:
export const createSubscriptionWorkflowHighlights = [ export const createSubscriptionWorkflowHighlights = [
["25", "completeCartWorkflow", "Complete the cart and create the order."], ["26", "completeCartWorkflow", "Complete the cart and create the order."],
["31", "createSubscriptionStep", "Create the subscription."], ["32", "useRemoteQueryStep", "Retrieve the order's details."],
["38", "createRemoteLinkStep", "Create the links returned by the previous step."] ["44", "createSubscriptionStep", "Create the subscription."],
["51", "createRemoteLinkStep", "Create the links returned by the previous step."]
] ]
```ts title="src/workflows/create-subscription/index.ts" highlights={createSubscriptionWorkflowHighlights} collapsibleLines="1-13" expandMoreLabel="Show Imports" ```ts title="src/workflows/create-subscription/index.ts" highlights={createSubscriptionWorkflowHighlights} collapsibleLines="1-13" expandMoreLabel="Show Imports"
@@ -604,6 +605,7 @@ import {
import { import {
createRemoteLinkStep, createRemoteLinkStep,
completeCartWorkflow, completeCartWorkflow,
useRemoteQueryStep
} from "@medusajs/medusa/core-flows" } from "@medusajs/medusa/core-flows"
import { import {
SubscriptionInterval, SubscriptionInterval,
@@ -621,10 +623,22 @@ type WorkflowInput = {
const createSubscriptionWorkflow = createWorkflow( const createSubscriptionWorkflow = createWorkflow(
"create-subscription", "create-subscription",
(input: WorkflowInput) => { (input: WorkflowInput) => {
const order = completeCartWorkflow.runAsStep({ const { id } = completeCartWorkflow.runAsStep({
input: { input: {
id: input.cart_id, id: input.cart_id
}
})
const order = useRemoteQueryStep({
entry_point: "order",
fields: ["*", "id", "customer_id"],
variables: {
filters: {
id
}
}, },
list: false,
throw_if_key_not_found: true
}) })
const { subscription, linkDefs } = createSubscriptionStep({ const { subscription, linkDefs } = createSubscriptionStep({
@@ -649,8 +663,9 @@ export default createSubscriptionWorkflow
This workflow accepts the carts ID, along with the subscription details. It executes the following steps: This workflow accepts the carts ID, along with the subscription details. It executes the following steps:
1. `completeCartWorkflow` from `@medusajs/medusa/core-flows` that completes a cart and creates an order. 1. `completeCartWorkflow` from `@medusajs/medusa/core-flows` that completes a cart and creates an order.
2. `createSubscriptionStep`, which is the step you created previously. 2. `useRemoteQueryStep` from `@medusajs/medusa/core-flows` to retrieve the order's details.
3. `createRemoteLinkStep` from `@medusajs/medusa/core-flows`, which accepts links to create. These links are in the `linkDefs` array returned by the previous step. 3. `createSubscriptionStep`, which is the step you created previously.
4. `createRemoteLinkStep` from `@medusajs/medusa/core-flows`, which accepts links to create. These links are in the `linkDefs` array returned by the previous step.
The workflow returns the created subscription and order. The workflow returns the created subscription and order.