Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add missing sw-language-id header #1657

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions .changeset/great-spoons-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vue-demo-store": patch
---

Added `sw-language-id` header property in `SwContactForm.vue` and `App.vue` components
5 changes: 5 additions & 0 deletions .changeset/healthy-goats-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@shopware/composables": patch
---

Added `sw-language-id` header property for API calls in `useCart`, `useCategorySearch`, `useCheckout`, `useCustomerOrders`, `useInternationalization`, and `useLandingSearch` composables.
6 changes: 5 additions & 1 deletion examples/commercial-quick-order/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import type { Schemas } from "#shopware";

const { apiClient } = useShopwareContext();
// for initialize the session and get the current currency
const { currency, refreshSessionContext } = useSessionContext();
const { currency, refreshSessionContext, languageIdChain } =
useSessionContext();
// to log in a customer, because the Quick Order feature is enabled for specifically selected users (in admin panel)
const { login } = useUser();

Expand Down Expand Up @@ -108,6 +109,9 @@ const onAddToCartClick = async () => {
body: {
items: lineItemsPayload,
},
headers: {
"sw-language-id": languageIdChain.value,
},
});

chosenItems.value = new Map();
Expand Down
5 changes: 5 additions & 0 deletions packages/cms-base-layer/components/SwContactForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
useCmsElementConfig,
useNavigationContext,
useSalutations,
useSessionContext,
useShopwareContext,
} from "#imports";

Expand Down Expand Up @@ -84,6 +85,7 @@ const { getSalutations } = useSalutations();
const { foreignKey } = useNavigationContext();
const { apiClient } = useShopwareContext();
const { getConfigValue } = useCmsElementConfig(props.content);
const { languageIdChain } = useSessionContext();

const getConfirmationText = computed(
() =>
Expand Down Expand Up @@ -148,6 +150,9 @@ const invokeSubmit = async () => {
...state,
navigationId: foreignKey.value,
},
headers: {
"sw-language-id": languageIdChain.value,
},
});
formSent.value = true;
} catch (e) {
Expand Down
5 changes: 5 additions & 0 deletions packages/composables/src/useCart/useCart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ describe("useCart", () => {
await vm.refreshCart();
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
expect.stringContaining("readCart"),
expect.objectContaining({
headers: {
"sw-language-id": "",
},
}),
);
});

Expand Down
9 changes: 7 additions & 2 deletions packages/composables/src/useCart/useCart.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createSharedComposable } from "@vueuse/core";
import { computed } from "vue";
import type { ComputedRef } from "vue";
import { useContext, useShopwareContext } from "#imports";
import { useContext, useSessionContext, useShopwareContext } from "#imports";
import type { Schemas, operations } from "#shopware";

/**
Expand Down Expand Up @@ -101,6 +101,7 @@ export type UseCartReturn = {
*/
export function useCartFunction(): UseCartReturn {
const { apiClient } = useShopwareContext();
const { languageIdChain } = useSessionContext();

const _storeCart = useContext<Schemas["Cart"]>("swCart");
const _storeCartErrors = useContext<Schemas["Cart"]["errors"] | null>(
Expand All @@ -115,7 +116,11 @@ export function useCartFunction(): UseCartReturn {
return newCart;
}

const { data } = await apiClient.invoke("readCart get /checkout/cart");
const { data } = await apiClient.invoke("readCart get /checkout/cart", {
headers: {
"sw-language-id": languageIdChain.value,
},
});
_storeCart.value = data;
setCartErrors(data);
return data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe("useCategorySearch", () => {
},
headers: {
"sw-include-seo-urls": true,
"sw-language-id": "",
},
}),
);
Expand All @@ -41,6 +42,7 @@ describe("useCategorySearch", () => {
},
headers: {
"sw-include-seo-urls": true,
"sw-language-id": "",
},
body: {
associations: cmsAssociations,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useShopwareContext } from "#imports";
import { useSessionContext, useShopwareContext } from "#imports";
import type { Schemas } from "#shopware";
import { cmsAssociations } from "../cms/cmsAssociations";

Expand Down Expand Up @@ -31,6 +31,7 @@ export type UseCategorySearchReturn = {
*/
export function useCategorySearch(): UseCategorySearchReturn {
const { apiClient } = useShopwareContext();
const { languageIdChain } = useSessionContext();

async function search(
categoryId: string,
Expand All @@ -48,6 +49,7 @@ export function useCategorySearch(): UseCategorySearchReturn {
},
headers: {
"sw-include-seo-urls": true,
"sw-language-id": languageIdChain.value,
},
body: {
associations,
Expand All @@ -70,6 +72,9 @@ export function useCategorySearch(): UseCategorySearchReturn {
associations,
...options?.query,
},
headers: {
"sw-language-id": languageIdChain.value,
},
});
return result.data.elements ?? [];
}
Expand Down
10 changes: 10 additions & 0 deletions packages/composables/src/useCheckout/useCheckout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export function useCheckout(): UseCheckoutReturn {
selectedShippingMethod,
setShippingMethod,
setPaymentMethod,
languageIdChain,
} = useSessionContext();

const storeShippingMethods = inject("swShippingMethods", ref());
Expand Down Expand Up @@ -109,6 +110,9 @@ export function useCheckout(): UseCheckoutReturn {
query: {
onlyAvailable: true,
},
headers: {
"sw-language-id": languageIdChain.value,
},
},
);
storeShippingMethods.value =
Expand All @@ -125,6 +129,9 @@ export function useCheckout(): UseCheckoutReturn {
"readPaymentMethod post /payment-method",
{
body: { onlyAvailable: true },
headers: {
"sw-language-id": languageIdChain.value,
},
},
);
storePaymentMethods.value = response.data.elements || [];
Expand All @@ -136,6 +143,9 @@ export function useCheckout(): UseCheckoutReturn {
) {
const order = await apiClient.invoke("createOrder post /checkout/order", {
body: params,
headers: {
"sw-language-id": languageIdChain.value,
},
});
return order.data;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { computed, ref } from "vue";
import type { ComputedRef, Ref } from "vue";
import { useShopwareContext } from "#imports";
import { useSessionContext, useShopwareContext } from "#imports";
import type { Schemas, operations } from "#shopware";

export type UseCustomerOrdersReturn = {
Expand Down Expand Up @@ -41,7 +41,7 @@ export type UseCustomerOrdersReturn = {
*/
export function useCustomerOrders(): UseCustomerOrdersReturn {
const { apiClient } = useShopwareContext();

const { languageIdChain } = useSessionContext();
const orders: Ref<Schemas["Order"][]> = ref([]);

const currentPaginationPage = ref<number>(1);
Expand All @@ -61,6 +61,9 @@ export function useCustomerOrders(): UseCustomerOrdersReturn {
currentParams.value = params;
const fetchedOrders = await apiClient.invoke("readOrder post /order", {
body: { ...params, "total-count-mode": "exact" },
headers: {
"sw-language-id": languageIdChain.value,
},
});
orders.value = fetchedOrders.data.orders.elements;
totalOrderItemsCount.value = fetchedOrders.data.orders.total ?? 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ describe("useInternationalization", () => {
vm.getAvailableLanguages();
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
expect.stringContaining("readLanguages"),
expect.objectContaining({
headers: {
"sw-language-id": "",
},
}),
);
});

Expand All @@ -38,7 +43,9 @@ describe("useInternationalization", () => {
vm.changeLanguage("test-id");
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
expect.stringContaining("updateContext"),
expect.objectContaining({ body: { languageId: "test-id" } }),
expect.objectContaining({
body: { languageId: "test-id" },
}),
);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { urlIsAbsolute } from "@shopware/helpers";
import type { Ref } from "vue";
import { useContext, useShopwareContext } from "#imports";
import { useContext, useSessionContext, useShopwareContext } from "#imports";
import type { Schemas, operations } from "#shopware";

export type UseInternationalizationReturn = {
Expand Down Expand Up @@ -82,7 +82,7 @@ export function useInternationalization(
): UseInternationalizationReturn {
const { devStorefrontUrl } = useShopwareContext();
const { apiClient } = useShopwareContext();

const { languageIdChain } = useSessionContext();
const _storeLanguages = useContext<Schemas["Language"][]>("swLanguages");
const _storeCurrentLanguage = useContext<string>(
"swLanguagesCurrentLanguage",
Expand All @@ -94,7 +94,11 @@ export function useInternationalization(
}

async function getAvailableLanguages() {
const { data } = await apiClient.invoke("readLanguages post /language");
const { data } = await apiClient.invoke("readLanguages post /language", {
headers: {
"sw-language-id": languageIdChain.value,
},
});
_storeLanguages.value = data.elements;
return data;
}
Expand Down
7 changes: 5 additions & 2 deletions packages/composables/src/useLandingSearch/useLandingSearch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useShopwareContext } from "#imports";
import { useSessionContext, useShopwareContext } from "#imports";
import type { Schemas, operations } from "#shopware";
import { cmsAssociations } from "../cms/cmsAssociations";

Expand Down Expand Up @@ -29,7 +29,7 @@ export function useLandingSearch(): {
) => Promise<Schemas["LandingPage"]>;
} {
const { apiClient } = useShopwareContext();

const { languageIdChain } = useSessionContext();
const search = async (
navigationId: string,
options?: {
Expand All @@ -47,6 +47,9 @@ export function useLandingSearch(): {
body: {
associations,
},
headers: {
"sw-language-id": languageIdChain.value,
},
},
);
return result.data;
Expand Down
13 changes: 12 additions & 1 deletion packages/composables/src/useListing/useListing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ describe("useListing", () => {

expect(injections.apiClient.invoke).toHaveBeenCalledWith(
expect.stringContaining("search"),
expect.objectContaining({}),
expect.objectContaining({
headers: {
"sw-include-seo-urls": true,
"sw-language-id": "",
},
}),
);

expect(vm.getCurrentPage).toBe(1);
Expand All @@ -48,6 +53,7 @@ describe("useListing", () => {
},
headers: {
"sw-include-seo-urls": true,
"sw-language-id": "",
},
pathParams: {
categoryId: "1234",
Expand Down Expand Up @@ -92,6 +98,7 @@ describe("useListing", () => {
},
headers: {
"sw-include-seo-urls": true,
"sw-language-id": "",
},
pathParams: {
categoryId: "1234",
Expand Down Expand Up @@ -131,6 +138,7 @@ describe("useListing", () => {
},
headers: {
"sw-include-seo-urls": true,
"sw-language-id": "",
},
pathParams: {
categoryId: "1234",
Expand Down Expand Up @@ -189,6 +197,7 @@ describe("useListing", () => {
},
headers: {
"sw-include-seo-urls": true,
"sw-language-id": "",
},
}),
);
Expand All @@ -211,6 +220,7 @@ describe("useListing", () => {
},
headers: {
"sw-include-seo-urls": true,
"sw-language-id": "",
},
}),
);
Expand All @@ -233,6 +243,7 @@ describe("useListing", () => {
},
headers: {
"sw-include-seo-urls": true,
"sw-language-id": "",
},
}),
);
Expand Down
6 changes: 4 additions & 2 deletions packages/composables/src/useListing/useListing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getListingFilters } from "@shopware/helpers";
import { createInjectionState, createSharedComposable } from "@vueuse/core";
import { computed, inject, provide, ref } from "vue";
import type { ComputedRef, Ref } from "vue";
import { useCategory, useShopwareContext } from "#imports";
import { useCategory, useSessionContext, useShopwareContext } from "#imports";
import type { Schemas, operations } from "#shopware";

function isObject<T>(item: T): boolean {
Expand Down Expand Up @@ -186,7 +186,7 @@ export function useListing(params?: {
}): UseListingReturn {
const listingType = params?.listingType || "categoryListing";
let categoryId = params?.categoryId || null;

const { languageIdChain } = useSessionContext();
// const { getDefaults } = useDefaults({ defaultsKey: contextName });
const { apiClient } = useShopwareContext();

Expand All @@ -205,6 +205,7 @@ export function useListing(params?: {
const { data } = await apiClient.invoke("searchPage post /search", {
headers: {
"sw-include-seo-urls": true,
"sw-language-id": languageIdChain.value,
},
body: searchCriteria,
});
Expand All @@ -224,6 +225,7 @@ export function useListing(params?: {
{
headers: {
"sw-include-seo-urls": true,
"sw-language-id": languageIdChain.value,
},
pathParams: {
categoryId: categoryId as string, // null exception in useCategory,
Expand Down
Loading
Loading