Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export async function POST(
files: files?.map((f) => ({
filename: f.originalname,
mimeType: f.mimetype,
content: f.buffer.toString("binary"),
content: f.buffer.toString("base64"),
access: "public",
})),
},
Expand All @@ -181,6 +181,12 @@ export async function POST(

The uploaded files are stored in the `req.files` property as an array of Multer file objects that have properties like `filename` and `mimetype`.

<Note>

Always encode the file content as `base64` when passing it to `uploadFilesWorkflow`. The File Module Providers expect base64-encoded content, and using `binary` encoding will corrupt binary files such as images when stored by remote providers.

</Note>

To upload the files, you can use the [uploadFilesWorkflow](!resources!/references/medusa-workflows/uploadFilesWorkflow), which uploads the files using the configured [File Module Provider](!resources!/infrastructure-modules/file).

### Test API Route
Expand All @@ -205,4 +211,4 @@ The request will return a JSON response with the uploaded file information:
}
]
}
```
```
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ After a minute, the following message will be logged to the terminal:
info: Greeting!
```

### Disable a Scheduled Job

Do not disable a scheduled job by commenting out or removing the `config` export while keeping the file in `src/jobs/`. This will cause errors when you build or start your Medusa application.

To disable a scheduled job, move its file out of the `src/jobs` directory. For example, move it to `src/scripts/` or any directory other than `src/jobs/`.

### Troubleshooting Scheduled Jobs

If your scheduled job is not running at the expected times, refer to the [Scheduled Job Troubleshooting Guide](!resources!/troubleshooting/scheduled-job-not-running).
Expand Down Expand Up @@ -147,4 +153,4 @@ export const config = {

The `context` parameter is an object that has the following property:

- `scheduledFor`: A `Date` object indicating the exact date and time the job was scheduled to run at.
- `scheduledFor`: A `Date` object indicating the exact date and time the job was scheduled to run at.
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ Learn more about product variant's inventory management in [this guide](../varia

### Retrieve with Query

To retrieve the inventory items of a product variant with [Query](!docs!/learn/fundamentals/module-links/query), pass `inventory_items.*` in `fields`:
To retrieve the inventory items of a product variant with [Query](!docs!/learn/fundamentals/module-links/query), pass `inventory_items.inventory.*` in `fields`. The `inventory_items` relation holds link records, so use `inventory_items.inventory` to access the actual `InventoryItem` data:

<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
Expand All @@ -423,11 +423,11 @@ To retrieve the inventory items of a product variant with [Query](!docs!/learn/f
const { data: variants } = await query.graph({
entity: "variant",
fields: [
"inventory_items.*",
"inventory_items.inventory.*",
],
})

// variants[0].inventory_items
// variants[0].inventory_items[0].inventory
```

</CodeTab>
Expand All @@ -441,16 +441,59 @@ import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
const { data: variants } = useQueryGraphStep({
entity: "variant",
fields: [
"inventory_items.*",
"inventory_items.inventory.*",
],
})

// variants[0].inventory_items
// variants[0].inventory_items[0].inventory
```

</CodeTab>
</CodeTabs>

You can also traverse from the `product` entity through its variants to their inventory items:

<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">

```ts
const { data: products } = await query.graph({
entity: "product",
fields: [
"variants.inventory_items.inventory.id",
],
})

// products[0].variants[0].inventory_items[0].inventory.id
```

</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">

```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"

// ...

const { data: products } = useQueryGraphStep({
entity: "product",
fields: [
"variants.inventory_items.inventory.id",
],
})

// products[0].variants[0].inventory_items[0].inventory.id
```

</CodeTab>
</CodeTabs>

<Note>

Creating a product variant with `manage_inventory` enabled creates an inventory item automatically, but does not create inventory levels. You must create inventory levels separately to set the stocked quantity at a specific location. Refer to the [Inventory Module's documentation](../../inventory/page.mdx) for details.

</Note>

### Manage with Link

To manage the inventory items of a variant, use [Link](!docs!/learn/fundamentals/module-links/link):
Expand Down Expand Up @@ -804,4 +847,4 @@ const { data: products } = useQueryGraphStep({
```

</CodeTab>
</CodeTabs>
</CodeTabs>
Loading