Back to Medusa

{metadata.title}

www/apps/resources/app/commerce-modules/store/links-to-other-modules/page.mdx

2.14.24.4 KB
Original Source

import { CodeTabs, CodeTab, Table, Prerequisites } from "docs-ui"

export const metadata = { title: Links between Store Module and Other Modules, }

{metadata.title}

This document showcases the module links defined between the Store Module and other Commerce Modules.

Summary

The Store Module has the following links to other modules:

<Note title="Tip">

Read-only links are used to query data across modules, but the relations aren't stored in a pivot table in the database.

</Note> <Table> <Table.Header> <Table.Row> <Table.HeaderCell> First Data Model </Table.HeaderCell> <Table.HeaderCell> Second Data Model </Table.HeaderCell> <Table.HeaderCell> Type </Table.HeaderCell> <Table.HeaderCell> Description </Table.HeaderCell> </Table.Row> </Table.Header> <Table.Body> <Table.Row> <Table.Cell> [StoreCurrency](/references/store/models/StoreCurrency) </Table.Cell> <Table.Cell> [Currency](/references/currency/models/Currency) in [Currency Module](../../currency/page.mdx) </Table.Cell> <Table.Cell> Read-only - has many </Table.Cell> <Table.Cell> [Learn more](#currency-module) </Table.Cell> </Table.Row> <Table.Row> <Table.Cell> [StoreLocale](/references/store/models/StoreLocale) </Table.Cell> <Table.Cell> [Locale](/references/translation/models/Locale) in [Translation Module](../../translation/page.mdx) </Table.Cell> <Table.Cell> Read-only - has many </Table.Cell> <Table.Cell> [Learn more](#translation-module) </Table.Cell> </Table.Row> </Table.Body> </Table>

Currency Module

The Store Module has a StoreCurrency data model that stores the supported currencies of a store. However, these currencies don't hold all the details of a currency, such as its name or symbol.

Instead, Medusa defines a read-only link from the Store Module's StoreCurrency data model to the Currency Module's Currency data model. This means you can retrieve the details of a store's supported currencies, but you don't manage the links in a pivot table in the database.

Retrieve with Query

To retrieve the details of a store's currencies with Query, pass supported_currencies.currency.* in fields:

<CodeTabs group="relation-query"> <CodeTab label="query.graph" value="method">
ts
const { data: stores } = await query.graph({
  entity: "store",
  fields: [
    "supported_currencies.currency.*",
  ],
})

// stores[0].supported_currencies
</CodeTab> <CodeTab label="useQueryGraphStep" value="step">
ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"

// ...

const { data: stores } = useQueryGraphStep({
  entity: "store",
  fields: [
    "supported_currencies.currency.*",
  ],
})

// stores[0].supported_currencies
</CodeTab> </CodeTabs>

Translation Module

<Prerequisites items={[ { text: "Translation Module Configured", link: "/commerce-modules/translation#configure-translation-module", } ]} />

The Store Module has a StoreLocale data model that stores the supported locales of a store. However, these locales don't hold all the details of a locale, such as its name.

Instead, Medusa defines a read-only link from the Store Module's StoreLocale data model to the Translation Module's Locale data model. This means you can retrieve the details of a store's supported locales, but you don't manage the links in a pivot table in the database.

Retrieve with Query

To retrieve the details of a store's locales with Query, pass supported_locales.locale.* in fields:

<CodeTabs group="relation-query"> <CodeTab label="query.graph" value="method">
ts
const { data: stores } = await query.graph({
  entity: "store",
  fields: [
    "supported_locales.locale.*",
  ],
})

// stores[0].supported_locales[0].locale
</CodeTab> <CodeTab label="useQueryGraphStep" value="step">
ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"

// ...

const { data: stores } = useQueryGraphStep({
  entity: "store",
  fields: [
    "supported_locales.locale.*",
  ],
})

// stores[0].supported_locales[0].locale
</CodeTab> </CodeTabs>