@shopware/composables 1.12.1 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,24 @@ import type { Schemas } from "#shopware";
7
7
  type UseB2bQuoteManagement = {
8
8
  getQuoteList: () => Promise<Schemas["Quote"][]>;
9
9
  getQuote: (quoteId: string) => Promise<Schemas["Quote"]>;
10
+ /**
11
+ * @deprecated use `declineQuoteWithComment` instead — it sends the
12
+ * `lineItemId` and `versionId` that `POST /quote/{id}/decline` expects.
13
+ * A `comment`-only body is still accepted at runtime on 6.7.12+: the API
14
+ * schema marks `lineItemId` and `versionId` as required, but the endpoint
15
+ * does not validate the request body, so existing callers keep working.
16
+ * Removed in v2.
17
+ */
10
18
  declineQuote: (quoteId: string, comment: string) => Promise<void>;
19
+ declineQuoteWithComment: (
20
+ quoteId: string,
21
+ params: DeclineQuoteParams,
22
+ ) => Promise<void>;
23
+ createDraftQuoteVersion: (quoteId: string) => Promise<string>;
24
+ deleteDraftQuoteVersion: (
25
+ quoteId: string,
26
+ versionId: string,
27
+ ) => Promise<void>;
11
28
  requestChangeQuote: (quoteId: string, comment: string) => Promise<void>;
12
29
  requestQuote: (comment: string) => Promise<Schemas["Quote"]>;
13
30
  createOrderFromQuote: (
@@ -24,6 +41,19 @@ type UseB2bQuoteManagement = {
24
41
  ) => Promise<void>;
25
42
  };
26
43
 
44
+ export type DeclineQuoteParams = {
45
+ /** Message content */
46
+ comment: string;
47
+ /** Identifier of the quote line item that owns the new comment */
48
+ lineItemId: string;
49
+ /**
50
+ * Draft version identifier of the quote currently shown in storefront,
51
+ * as returned by `createDraftQuoteVersion`. This is not the `versionId`
52
+ * property of the quote entity.
53
+ */
54
+ versionId: string;
55
+ };
56
+
27
57
  export type ChangePaymentShippingMethodParams = {
28
58
  quoteId: string;
29
59
  paymentMethodId?: string;
@@ -36,7 +66,8 @@ export type ChangePaymentShippingMethodParams = {
36
66
  * With this composable you can:
37
67
  * - Get list of quotes
38
68
  * - Get quote details
39
- * - Decline quote
69
+ * - Create and delete a storefront draft version of the quote
70
+ * - Decline quote, with or without a line item comment
40
71
  * - Request change of the quote
41
72
  * - Change shipping method
42
73
  * - Change payment method
@@ -66,26 +97,78 @@ export function useB2bQuoteManagement(): UseB2bQuoteManagement {
66
97
  * @returns {Promise<Schemas["Quote"]>}
67
98
  */
68
99
  const getQuote = async (quoteId: string) => {
100
+ const response = await apiClient.invoke("readQuote post /quote/{id}", {
101
+ pathParams: {
102
+ id: quoteId,
103
+ },
104
+ body: {
105
+ associations: {
106
+ lineItems: {},
107
+ comments: {},
108
+ stateMachineState: {},
109
+ },
110
+ },
111
+ });
112
+ return response.data;
113
+ };
114
+
115
+ /**
116
+ * Create a temporary draft version of the quote for storefront editing.
117
+ *
118
+ * The returned identifier is the `versionId` that quote write operations
119
+ * expect, for example {@link declineQuoteWithComment}. It is not the
120
+ * `versionId` property of the quote entity.
121
+ *
122
+ * @param {string} quoteId
123
+ * @returns {Promise<string>} draft version identifier
124
+ */
125
+ async function createDraftQuoteVersion(quoteId: string) {
69
126
  const response = await apiClient.invoke(
70
- "readQuote post /quote/detail/{id}",
127
+ "createDraftQuoteVersion post /quote/{id}/draft-version",
71
128
  {
72
129
  pathParams: {
73
130
  id: quoteId,
74
131
  },
75
- body: {
76
- associations: {
77
- lineItems: {},
78
- comments: {},
79
- stateMachineState: {},
80
- },
132
+ },
133
+ );
134
+
135
+ if (!response.data.versionId) {
136
+ throw new Error(
137
+ `Could not create a draft version for quote "${quoteId}": the API returned no versionId.`,
138
+ );
139
+ }
140
+
141
+ return response.data.versionId;
142
+ }
143
+
144
+ /**
145
+ * Delete the temporary draft version of the quote.
146
+ *
147
+ * @param {string} quoteId
148
+ * @param {string} versionId draft version identifier returned by {@link createDraftQuoteVersion}
149
+ * @returns {Promise<void>}
150
+ */
151
+ async function deleteDraftQuoteVersion(quoteId: string, versionId: string) {
152
+ await apiClient.invoke(
153
+ "deleteDraftQuoteVersion delete /quote/{id}/draft-version",
154
+ {
155
+ pathParams: {
156
+ id: quoteId,
81
157
  },
158
+ body: { versionId },
82
159
  },
83
160
  );
84
- return response.data;
85
- };
161
+ }
86
162
 
87
163
  /**
88
- * Decline quote
164
+ * Decline quote with a comment only.
165
+ *
166
+ * @deprecated use {@link declineQuoteWithComment} instead — it sends the
167
+ * `lineItemId` and `versionId` that `POST /quote/{id}/decline` expects.
168
+ * A `comment`-only body is still accepted at runtime on 6.7.12+: the API
169
+ * schema marks `lineItemId` and `versionId` as required, but the endpoint
170
+ * does not validate the request body, so existing callers keep working.
171
+ * Removed in v2.
89
172
  *
90
173
  * @param {string} quoteId
91
174
  * @param {string} comment
@@ -96,9 +179,30 @@ export function useB2bQuoteManagement(): UseB2bQuoteManagement {
96
179
  pathParams: {
97
180
  id: quoteId,
98
181
  },
99
- body: {
100
- comment,
182
+ // The 6.7.12 schema marks `lineItemId` and `versionId` as required, so a
183
+ // comment-only body no longer matches the generated type. Sent as-is to
184
+ // keep the pre-6.7.12 behaviour of this deprecated method unchanged.
185
+ body: { comment } as DeclineQuoteParams,
186
+ });
187
+ }
188
+
189
+ /**
190
+ * Decline quote, attaching the comment to a quote line item in the current
191
+ * draft version.
192
+ *
193
+ * @param {string} quoteId
194
+ * @param {DeclineQuoteParams} params
195
+ * @returns {Promise<void>}
196
+ */
197
+ async function declineQuoteWithComment(
198
+ quoteId: string,
199
+ params: DeclineQuoteParams,
200
+ ) {
201
+ await apiClient.invoke("declineQuote post /quote/{id}/decline", {
202
+ pathParams: {
203
+ id: quoteId,
101
204
  },
205
+ body: params,
102
206
  });
103
207
  }
104
208
 
@@ -202,7 +306,7 @@ export function useB2bQuoteManagement(): UseB2bQuoteManagement {
202
306
  */
203
307
  const createOrderFromQuote = async (quoteId: string, comment: string) => {
204
308
  const response = await apiClient.invoke(
205
- "createOrderFromQuote post /quote/order/{id}",
309
+ "createOrderFromQuote post /quote/{id}/order",
206
310
  {
207
311
  pathParams: { id: quoteId },
208
312
  body: { customerComment: comment },
@@ -216,6 +320,9 @@ export function useB2bQuoteManagement(): UseB2bQuoteManagement {
216
320
  getQuoteList,
217
321
  getQuote,
218
322
  declineQuote,
323
+ declineQuoteWithComment,
324
+ createDraftQuoteVersion,
325
+ deleteDraftQuoteVersion,
219
326
  requestChangeQuote,
220
327
  changeShippingMethod,
221
328
  changePaymentMethod,
@@ -45,7 +45,7 @@ describe("useCategorySearch", () => {
45
45
  "sw-include-seo-urls": true,
46
46
  },
47
47
  body: {
48
- associations: cmsAssociations,
48
+ associations: cmsAssociations.associations,
49
49
  },
50
50
  }),
51
51
  );
@@ -79,7 +79,7 @@ describe("useCategorySearch", () => {
79
79
  },
80
80
  query: {
81
81
  _criteria: encodeForQuery({
82
- associations: cmsAssociations,
82
+ associations: cmsAssociations.associations,
83
83
  filter: [{ type: "equals", field: "active", value: true }],
84
84
  limit: 1,
85
85
  sort: [{ field: "name", order: "ASC" }],
@@ -46,7 +46,9 @@ export function useCategorySearch(): UseCategorySearchReturn {
46
46
  query?: Schemas["Criteria"];
47
47
  },
48
48
  ) {
49
- const associations = options?.withCmsAssociations ? cmsAssociations : {};
49
+ const associations = options?.withCmsAssociations
50
+ ? cmsAssociations.associations
51
+ : {};
50
52
  const criteria = {
51
53
  associations,
52
54
  ...options?.query,
@@ -1,27 +1,61 @@
1
1
  import { describe, expect, it } from "vitest";
2
+ import { ref } from "vue";
2
3
 
3
4
  import type { Schemas } from "#shopware";
4
5
 
5
6
  import { useSetup } from "../_test";
6
7
  import { useCmsBlock } from "./useCmsBlock";
7
8
 
9
+ const blockWith = (slot: string) =>
10
+ ({
11
+ apiAlias: "cms_block",
12
+ createdAt: "2020-08-06T06:26:23.880+00:00",
13
+ position: 0,
14
+ sectionId: "ri3n2ldk",
15
+ slots: [
16
+ {
17
+ slot,
18
+ },
19
+ ],
20
+ type: "page",
21
+ }) as unknown as Schemas["CmsBlock"];
22
+
8
23
  describe("composables - useCmsBlock", () => {
9
24
  it("get block data", () => {
10
- const mockData = {
11
- apiAlias: "cms_block",
12
- createdAt: "2020-08-06T06:26:23.880+00:00",
13
- position: 0,
14
- sectionId: "ri3n2ldk",
15
- slots: [
16
- {
17
- slot: "left-bottom",
18
- },
19
- ],
20
- type: "page",
21
- };
22
- const { vm } = useSetup(() => useCmsBlock(mockData as Schemas["CmsBlock"]));
25
+ const mockData = blockWith("left-bottom");
26
+ const { vm } = useSetup(() => useCmsBlock(mockData));
23
27
 
24
28
  expect(vm.block).toEqual(mockData);
25
29
  expect(vm.getSlotContent("left-bottom")).toEqual(mockData.slots[0]);
26
30
  });
31
+
32
+ it("returns undefined for a slot the block does not carry", () => {
33
+ const { vm } = useSetup(() => useCmsBlock(blockWith("left-bottom")));
34
+
35
+ expect(vm.getSlotContent("right-top")).toBeUndefined();
36
+ });
37
+
38
+ it("looks up slots on a replaced block", () => {
39
+ const first = blockWith("left-bottom");
40
+ const content = ref(first);
41
+ const { vm } = useSetup(() => useCmsBlock(content));
42
+
43
+ expect(vm.getSlotContent("left-bottom")).toBeDefined();
44
+
45
+ content.value = blockWith("right-top");
46
+
47
+ expect(vm.getSlotContent("left-bottom")).toBeUndefined();
48
+ expect(vm.getSlotContent("right-top")).toEqual(content.value.slots[0]);
49
+ // `block` is the value read when the composable was called
50
+ expect(vm.block).toEqual(first);
51
+ });
52
+
53
+ it("accepts a getter", () => {
54
+ const content = ref(blockWith("left-bottom"));
55
+ const { vm } = useSetup(() => useCmsBlock(() => content.value));
56
+
57
+ content.value = blockWith("right-top");
58
+
59
+ expect(vm.getSlotContent("right-top")).toEqual(content.value.slots[0]);
60
+ });
27
61
  });
@@ -1,3 +1,6 @@
1
+ import { toValue } from "vue";
2
+ import type { MaybeRefOrGetter } from "vue";
3
+
1
4
  import type { Schemas } from "#shopware";
2
5
 
3
6
  type ArrayElement<ArrayType extends readonly unknown[]> =
@@ -5,11 +8,18 @@ type ArrayElement<ArrayType extends readonly unknown[]> =
5
8
 
6
9
  export type UseCmsBlockReturn = {
7
10
  /**
8
- * Cms block content
11
+ * Cms block content, as it was when the composable was called.
9
12
  */
10
13
  block: Schemas["CmsBlock"];
11
14
  /**
12
- * Get slot content by slot name (identifier)
15
+ * Get slot content by slot name (identifier).
16
+ *
17
+ * Reads the block on every call, so it follows a `ref` or getter passed as
18
+ * `content`.
19
+ *
20
+ * A block does not have to carry every slot its layout allows: the lookup
21
+ * returns `undefined` at runtime for a slot that is not there, which the
22
+ * return type does not express yet. Guard on the result.
13
23
  * @example getSlotContent("main")
14
24
  */
15
25
  getSlotContent(slotName: string): ArrayElement<Schemas["CmsBlock"]["slots"]>;
@@ -21,16 +31,16 @@ export type UseCmsBlockReturn = {
21
31
  * @category CMS (Shopping Experiences)
22
32
  */
23
33
  export function useCmsBlock<BLOCK_TYPE extends Schemas["CmsBlock"]>(
24
- content: BLOCK_TYPE,
34
+ content: MaybeRefOrGetter<BLOCK_TYPE>,
25
35
  ): UseCmsBlockReturn {
26
36
  function getSlotContent(slotName: ArrayElement<BLOCK_TYPE["slots"]>["slot"]) {
27
- return content.slots.find((slot) => slot.slot === slotName) as ArrayElement<
28
- BLOCK_TYPE["slots"]
29
- >;
37
+ return toValue(content).slots.find(
38
+ (slot) => slot.slot === slotName,
39
+ ) as ArrayElement<BLOCK_TYPE["slots"]>;
30
40
  }
31
41
 
32
42
  return {
33
- block: content,
43
+ block: toValue(content),
34
44
  getSlotContent,
35
45
  };
36
46
  }
@@ -1,4 +1,5 @@
1
1
  import { describe, expect, it } from "vitest";
2
+ import { ref } from "vue";
2
3
 
3
4
  import type { Schemas } from "#shopware";
4
5
 
@@ -6,15 +7,57 @@ import { useSetup } from "../_test";
6
7
  import CmsPage from "../mocks/CmsPage";
7
8
  import { useCmsSection } from "./useCmsSection";
8
9
 
10
+ const sectionWith = (sectionPosition: string) =>
11
+ ({
12
+ apiAlias: "cms_section",
13
+ type: "default",
14
+ blocks: [
15
+ {
16
+ apiAlias: "cms_block",
17
+ sectionPosition,
18
+ type: "text",
19
+ },
20
+ ],
21
+ }) as unknown as Schemas["CmsSection"];
22
+
9
23
  describe("useCmsSection", () => {
10
- it("search", async () => {
24
+ it("returns the blocks placed on the given position", () => {
11
25
  const section = CmsPage.cmsPage.sections?.[0];
12
26
 
13
- const { vm, injections } = useSetup(() =>
27
+ const { vm } = useSetup(() =>
14
28
  useCmsSection(section as unknown as Schemas["CmsSection"]),
15
29
  );
16
- injections.apiClient.invoke.mockResolvedValue({ data: {} });
17
- const block = await vm.getPositionContent("main");
18
- expect(block).toEqual(section?.blocks);
30
+
31
+ expect(vm.getPositionContent("main")).toEqual(section?.blocks);
32
+ });
33
+
34
+ it("returns an empty array for a position no block uses", () => {
35
+ const { vm } = useSetup(() => useCmsSection(sectionWith("main")));
36
+
37
+ expect(vm.getPositionContent("sidebar")).toEqual([]);
38
+ });
39
+
40
+ it("groups blocks of a replaced section", () => {
41
+ const first = sectionWith("main");
42
+ const content = ref(first);
43
+ const { vm } = useSetup(() => useCmsSection(content));
44
+
45
+ expect(vm.getPositionContent("main")).toHaveLength(1);
46
+
47
+ content.value = sectionWith("sidebar");
48
+
49
+ expect(vm.getPositionContent("main")).toEqual([]);
50
+ expect(vm.getPositionContent("sidebar")).toHaveLength(1);
51
+ // `section` is the value read when the composable was called
52
+ expect(vm.section).toEqual(first);
53
+ });
54
+
55
+ it("accepts a getter", () => {
56
+ const content = ref(sectionWith("main"));
57
+ const { vm } = useSetup(() => useCmsSection(() => content.value));
58
+
59
+ content.value = sectionWith("sidebar");
60
+
61
+ expect(vm.getPositionContent("sidebar")).toHaveLength(1);
19
62
  });
20
63
  });
@@ -1,3 +1,6 @@
1
+ import { toValue } from "vue";
2
+ import type { MaybeRefOrGetter } from "vue";
3
+
1
4
  import type { Schemas } from "#shopware";
2
5
 
3
6
  type ArrayElement<ArrayType extends readonly unknown[]> =
@@ -5,11 +8,14 @@ type ArrayElement<ArrayType extends readonly unknown[]> =
5
8
 
6
9
  type UseCmsSectionType = {
7
10
  /**
8
- * CMS section
11
+ * CMS section, as it was when the composable was called.
9
12
  */
10
13
  section: Schemas["CmsSection"];
11
14
  /**
12
- * Position of the section
15
+ * Blocks of the section placed on the given position.
16
+ *
17
+ * Reads the section on every call, so it follows a `ref` or getter passed as
18
+ * `content`.
13
19
  */
14
20
  getPositionContent(
15
21
  position: ArrayElement<Schemas["CmsSection"]["blocks"]>["sectionPosition"],
@@ -22,18 +28,18 @@ type UseCmsSectionType = {
22
28
  * @category CMS (Shopping Experiences)
23
29
  */
24
30
  export function useCmsSection<SECTION_TYPE extends Schemas["CmsSection"]>(
25
- content: SECTION_TYPE,
31
+ content: MaybeRefOrGetter<SECTION_TYPE>,
26
32
  ): UseCmsSectionType {
27
33
  function getPositionContent(
28
34
  position: ArrayElement<SECTION_TYPE["blocks"]>["sectionPosition"],
29
35
  ) {
30
- return content.blocks.filter(
36
+ return toValue(content).blocks.filter(
31
37
  (block) => block.sectionPosition === position,
32
38
  ) as Array<Schemas["CmsBlock"]>;
33
39
  }
34
40
 
35
41
  return {
36
- section: content,
42
+ section: toValue(content),
37
43
  getPositionContent,
38
44
  };
39
45
  }
@@ -3,6 +3,7 @@ import { describe, expect, it, vi } from "vitest";
3
3
  import type { Schemas } from "#shopware";
4
4
 
5
5
  import { useSetup } from "../_test";
6
+ import { useSessionContext } from "../useSessionContext/useSessionContext";
6
7
  import { useInternationalization } from "./useInternationalization";
7
8
  import type { RouteObject } from "./useInternationalization";
8
9
 
@@ -140,6 +141,159 @@ describe("useInternationalization", () => {
140
141
  );
141
142
  });
142
143
 
144
+ it("uses a sales channel domain when the preferred storefront URL is not configured there", async () => {
145
+ const { vm } = useSetup(
146
+ () => {
147
+ const session = useSessionContext();
148
+ const i18n = useInternationalization();
149
+ return {
150
+ setContext: session.setContext,
151
+ getStorefrontUrl: i18n.getStorefrontUrl,
152
+ };
153
+ },
154
+ {
155
+ shopware: {
156
+ devStorefrontUrl: "https://frontends-starter-template.vercel.app",
157
+ },
158
+ },
159
+ );
160
+
161
+ vm.setContext({
162
+ salesChannel: {
163
+ domains: [
164
+ {
165
+ url: "https://demo-frontends.shopware.store/figma",
166
+ languageId: "lang-en",
167
+ },
168
+ ],
169
+ languageId: "lang-en",
170
+ },
171
+ } as Schemas["SalesChannelContext"]);
172
+
173
+ expect(vm.getStorefrontUrl()).toBe(
174
+ "https://demo-frontends.shopware.store/figma",
175
+ );
176
+ });
177
+
178
+ it("keeps the preferred storefront URL when it matches a sales channel domain", async () => {
179
+ const preferred = "https://frontends-starter-template.vercel.app";
180
+ const { vm } = useSetup(
181
+ () => {
182
+ const session = useSessionContext();
183
+ const i18n = useInternationalization();
184
+ return {
185
+ setContext: session.setContext,
186
+ getStorefrontUrl: i18n.getStorefrontUrl,
187
+ };
188
+ },
189
+ {
190
+ shopware: { devStorefrontUrl: preferred },
191
+ },
192
+ );
193
+
194
+ vm.setContext({
195
+ salesChannel: {
196
+ domains: [{ url: preferred, languageId: "lang-en" }],
197
+ languageId: "lang-en",
198
+ },
199
+ } as Schemas["SalesChannelContext"]);
200
+
201
+ expect(vm.getStorefrontUrl()).toBe(preferred);
202
+ });
203
+
204
+ it("falls back to the first sales channel domain when no language domain matches", async () => {
205
+ const { vm } = useSetup(
206
+ () => {
207
+ const session = useSessionContext();
208
+ const i18n = useInternationalization();
209
+ return {
210
+ setContext: session.setContext,
211
+ getStorefrontUrl: i18n.getStorefrontUrl,
212
+ };
213
+ },
214
+ {
215
+ shopware: { devStorefrontUrl: "https://not-a-channel-domain.example" },
216
+ },
217
+ );
218
+
219
+ vm.setContext({
220
+ salesChannel: {
221
+ domains: [
222
+ { url: undefined, languageId: "lang-de" },
223
+ {
224
+ url: "https://demo-frontends.shopware.store/figma",
225
+ languageId: "lang-en",
226
+ },
227
+ ],
228
+ languageId: "lang-pl",
229
+ },
230
+ context: { languageIdChain: ["lang-fr"] },
231
+ } as Schemas["SalesChannelContext"]);
232
+
233
+ expect(vm.getStorefrontUrl()).toBe(
234
+ "https://demo-frontends.shopware.store/figma",
235
+ );
236
+ });
237
+
238
+ it("keeps the preferred URL when sales channel domains have no url", async () => {
239
+ const preferred = "https://frontends-starter-template.vercel.app";
240
+ const { vm } = useSetup(
241
+ () => {
242
+ const session = useSessionContext();
243
+ const i18n = useInternationalization();
244
+ return {
245
+ setContext: session.setContext,
246
+ getStorefrontUrl: i18n.getStorefrontUrl,
247
+ };
248
+ },
249
+ {
250
+ shopware: { devStorefrontUrl: preferred },
251
+ },
252
+ );
253
+
254
+ vm.setContext({
255
+ salesChannel: {
256
+ domains: [{ languageId: "lang-en" }],
257
+ languageId: "lang-de",
258
+ },
259
+ } as Schemas["SalesChannelContext"]);
260
+
261
+ expect(vm.getStorefrontUrl()).toBe(preferred);
262
+ });
263
+
264
+ it("treats a trailing slash as the same sales channel domain", async () => {
265
+ const { vm } = useSetup(
266
+ () => {
267
+ const session = useSessionContext();
268
+ const i18n = useInternationalization();
269
+ return {
270
+ setContext: session.setContext,
271
+ getStorefrontUrl: i18n.getStorefrontUrl,
272
+ };
273
+ },
274
+ {
275
+ shopware: {
276
+ devStorefrontUrl: "https://frontends-starter-template.vercel.app/",
277
+ },
278
+ },
279
+ );
280
+
281
+ vm.setContext({
282
+ salesChannel: {
283
+ domains: [
284
+ {
285
+ url: "https://frontends-starter-template.vercel.app",
286
+ languageId: "lang-en",
287
+ },
288
+ ],
289
+ },
290
+ } as Schemas["SalesChannelContext"]);
291
+
292
+ expect(vm.getStorefrontUrl()).toBe(
293
+ "https://frontends-starter-template.vercel.app",
294
+ );
295
+ });
296
+
143
297
  it("getStorefrontUrl without devStorefrontUrl and window", async () => {
144
298
  vi.spyOn(window, "location", "get").mockImplementation(
145
299
  () => ({}) as Location,
@@ -1,7 +1,7 @@
1
1
  import { urlIsAbsolute } from "@shopware/helpers";
2
2
  import type { Ref } from "vue";
3
3
 
4
- import { useContext, useShopwareContext } from "#imports";
4
+ import { useContext, useSessionContext, useShopwareContext } from "#imports";
5
5
  import type { Schemas, operations } from "#shopware";
6
6
 
7
7
  export type UseInternationalizationReturn = {
@@ -82,6 +82,7 @@ export function useInternationalization(
82
82
  pathResolver?: (path: string) => string,
83
83
  ): UseInternationalizationReturn {
84
84
  const { devStorefrontUrl, apiClient, cacheableReads } = useShopwareContext();
85
+ const { sessionContext } = useSessionContext();
85
86
 
86
87
  const _storeLanguages = useContext<Schemas["Language"][]>("swLanguages");
87
88
  const _storeCurrentLanguage = useContext<string>(
@@ -90,7 +91,25 @@ export function useInternationalization(
90
91
  const _storeCurrentPrefix = useContext<string>("swLanguagesCurrentPrefix");
91
92
 
92
93
  function getStorefrontUrl() {
93
- return devStorefrontUrl ?? window.location.origin ?? "";
94
+ const preferred = devStorefrontUrl ?? window.location.origin ?? "";
95
+ const domains = sessionContext?.value?.salesChannel?.domains ?? [];
96
+ if (!domains.length) return preferred;
97
+
98
+ const normalizedPreferred = preferred.replace(/\/$/, "");
99
+ const matchingDomain = domains.find(
100
+ (domain) => domain.url?.replace(/\/$/, "") === normalizedPreferred,
101
+ );
102
+ if (matchingDomain?.url) return matchingDomain.url;
103
+
104
+ const languageId =
105
+ sessionContext?.value?.context?.languageIdChain?.[0] ??
106
+ sessionContext?.value?.salesChannel?.languageId;
107
+ const languageDomain = domains.find(
108
+ (domain) => domain.languageId === languageId && domain.url,
109
+ );
110
+ if (languageDomain?.url) return languageDomain.url;
111
+
112
+ return domains.find((domain) => domain.url)?.url ?? preferred;
94
113
  }
95
114
 
96
115
  async function getAvailableLanguages() {
@@ -96,7 +96,9 @@ export type UseListingReturn = {
96
96
  * Available sorting orders
97
97
  */
98
98
  getSortingOrders: ComputedRef<
99
- Schemas["ProductSorting"][] | { key: string; label: string }[] | undefined
99
+ | Schemas["ProductListingResult"]["availableSortings"]
100
+ | { key: string; label: string }[]
101
+ | undefined
100
102
  >;
101
103
  /**
102
104
  * Current sorting order