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

Closed
wants to merge 14 commits into from
Closed
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
7 changes: 7 additions & 0 deletions .changeset/healthy-goats-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@shopware/composables": patch
---

Added `sw-language-id` header property for API calls in `useCart`, `useCategorySearch`, `useCheckout`, `useCustomerOrders`, `useInternationalization`, and `useLandingSearch` composables.

Added `currentSessionLanguageID` that is a alias for `languageIdChain` in `useSessionContext` composable
8 changes: 6 additions & 2 deletions examples/adyen-dropin-component/api-types/storeApiTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8432,11 +8432,15 @@ export type operations = {
"readBreadcrumb get /breadcrumb/{id}": {
contentType?: "application/json";
accept?: "application/json";
headers?: {
/** Instructs Shopware to return the response in the given language. */
"sw-language-id"?: string; //TODO: [OpenAPI][readBreadcrumb] - sw-language-id should be added
};
query?: {
/** UUID for referrer category only used for product breadcrumb */
referrerCategoryId?: string;
/** Type: category or product (optional - default: product) */
type?: "product" | "category";
/** UUID for referrer category only used for product breadcrumb */
referrerCategoryId?: string;
};
pathParams: {
/** UUID for product or category */
Expand Down
8 changes: 6 additions & 2 deletions examples/b2b-quote-management/api-types/storeApiTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8321,11 +8321,15 @@ export type operations = {
"readBreadcrumb get /breadcrumb/{id}": {
contentType?: "application/json";
accept?: "application/json";
headers?: {
/** Instructs Shopware to return the response in the given language. */
"sw-language-id"?: string; //TODO: [OpenAPI][readBreadcrumb] - sw-language-id should be added
};
query?: {
/** UUID for referrer category only used for product breadcrumb */
referrerCategoryId?: string;
/** Type: category or product (optional - default: product) */
type?: "product" | "category";
/** UUID for referrer category only used for product breadcrumb */
referrerCategoryId?: string;
};
pathParams: {
/** UUID for product or category */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8343,11 +8343,15 @@ export type operations = {
"readBreadcrumb get /breadcrumb/{id}": {
contentType?: "application/json";
accept?: "application/json";
headers?: {
/** Instructs Shopware to return the response in the given language. */
"sw-language-id"?: string; //TODO: [OpenAPI][readBreadcrumb] - sw-language-id should be added
};
query?: {
/** UUID for referrer category only used for product breadcrumb */
referrerCategoryId?: string;
/** Type: category or product (optional - default: product) */
type?: "product" | "category";
/** UUID for referrer category only used for product breadcrumb */
referrerCategoryId?: string;
};
pathParams: {
/** UUID for product or category */
Expand Down
8 changes: 6 additions & 2 deletions examples/commercial-quick-order/api-types/storeApiTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8345,11 +8345,15 @@ export type operations = {
"readBreadcrumb get /breadcrumb/{id}": {
contentType?: "application/json";
accept?: "application/json";
headers?: {
/** Instructs Shopware to return the response in the given language. */
"sw-language-id"?: string; //TODO: [OpenAPI][readBreadcrumb] - sw-language-id should be added
};
query?: {
/** UUID for referrer category only used for product breadcrumb */
referrerCategoryId?: string;
/** Type: category or product (optional - default: product) */
type?: "product" | "category";
/** UUID for referrer category only used for product breadcrumb */
referrerCategoryId?: string;
};
pathParams: {
/** UUID for product or category */
Expand Down
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, currentSessionLanguageID } =
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": currentSessionLanguageID.value,
},
});

chosenItems.value = new Map();
Expand Down
8 changes: 6 additions & 2 deletions examples/express-checkout/api-types/storeApiTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8321,11 +8321,15 @@ export type operations = {
"readBreadcrumb get /breadcrumb/{id}": {
contentType?: "application/json";
accept?: "application/json";
headers?: {
/** Instructs Shopware to return the response in the given language. */
"sw-language-id"?: string; //TODO: [OpenAPI][readBreadcrumb] - sw-language-id should be added
};
query?: {
/** UUID for referrer category only used for product breadcrumb */
referrerCategoryId?: string;
/** Type: category or product (optional - default: product) */
type?: "product" | "category";
/** UUID for referrer category only used for product breadcrumb */
referrerCategoryId?: string;
};
pathParams: {
/** UUID for product or category */
Expand Down
8 changes: 6 additions & 2 deletions examples/mollie-credit-card/api-types/storeApiTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8324,11 +8324,15 @@ export type operations = {
"readBreadcrumb get /breadcrumb/{id}": {
contentType?: "application/json";
accept?: "application/json";
headers?: {
/** Instructs Shopware to return the response in the given language. */
"sw-language-id"?: string; //TODO: [OpenAPI][readBreadcrumb] - sw-language-id should be added
};
query?: {
/** UUID for referrer category only used for product breadcrumb */
referrerCategoryId?: string;
/** Type: category or product (optional - default: product) */
type?: "product" | "category";
/** UUID for referrer category only used for product breadcrumb */
referrerCategoryId?: string;
};
pathParams: {
/** UUID for product or category */
Expand Down
8 changes: 5 additions & 3 deletions examples/multi-sales-channel/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ sessionContextData.value = contextResponse.data;

useSessionContext(sessionContextData.value);

const { languageIdChain, refreshSessionContext } = useSessionContext();
const { currentSessionLanguageID, refreshSessionContext } = useSessionContext();
const { locale, availableLocales, defaultLocale, localeProperties } = useI18n();
const router = useRouter();
const {
Expand All @@ -45,11 +45,13 @@ if (languages.value?.elements.length && router.currentRoute.value.name) {

// Language set on the backend side
if (localeProperties.value.localeId) {
if (languageIdChain.value !== localeProperties.value.localeId) {
if (currentSessionLanguageID.value !== localeProperties.value.localeId) {
languageToChangeId = localeProperties.value.localeId;
}
} else {
const sessionLanguage = getLanguageCodeFromId(languageIdChain.value);
const sessionLanguage = getLanguageCodeFromId(
currentSessionLanguageID.value,
);

// If languages are not the same, set one from prefix
if (sessionLanguage !== prefix) {
Expand Down
8 changes: 4 additions & 4 deletions examples/multi-sales-channel/pages/[...all].vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import { getLanguageName, getTranslatedProperty } from "@shopware/helpers";

const { languages, getLanguageCodeFromId } = useInternationalization();
const { sessionContext, languageIdChain } = useSessionContext();
const { sessionContext, currentSessionLanguageID } = useSessionContext();

const language = computed(() =>
languages.value.find((l) => languageIdChain.value === l.id),
languages.value.find((l) => currentSessionLanguageID.value === l.id),
);

const onChangeHandler = async (option: Event) => {
Expand All @@ -22,7 +22,7 @@ const onChangeHandler = async (option: Event) => {
<div>
<ul>
<li>
Language: {{ language ? getLanguageName(language) : languageIdChain }}
Language: {{ language ? getLanguageName(language) : currentSessionLanguageID }}
</li>
<li>
Sales channel:
Expand All @@ -35,7 +35,7 @@ const onChangeHandler = async (option: Event) => {
v-for="language in languages"
:key="language.id"
:value="language.id"
:selected="languageIdChain === language.id"
:selected="currentSessionLanguageID === language.id"
:label="getLanguageName(language)"
>
{{ getLanguageName(language) }}
Expand Down
8 changes: 6 additions & 2 deletions packages/api-client/api-types/storeApiTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8322,11 +8322,15 @@ export type operations = {
"readBreadcrumb get /breadcrumb/{id}": {
contentType?: "application/json";
accept?: "application/json";
headers?: {
/** Instructs Shopware to return the response in the given language. */
"sw-language-id"?: string; //TODO: [OpenAPI][readBreadcrumb] - sw-language-id should be added
};
query?: {
/** UUID for referrer category only used for product breadcrumb */
referrerCategoryId?: string;
/** Type: category or product (optional - default: product) */
type?: "product" | "category";
/** UUID for referrer category only used for product breadcrumb */
referrerCategoryId?: string;
};
pathParams: {
/** UUID for product or category */
Expand Down
74 changes: 73 additions & 1 deletion packages/api-client/api-types/storeApiTypes.overrides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,76 @@ export type Schemas = {
};
};

// export type operations = {};
export type operations = {
"updateLineItem patch /checkout/cart/line-item": {
contentType?: "application/json";
accept?: "application/json";
headers?: {
/** Instructs Shopware to return the response in the given language. */
"sw-language-id"?: string;
};
body: {
// TODO: [OpenAPI][updateLineItem] - add proper request body type with required fields
items: Array<{
id: string;
quantity: number;
}>;
};
response: components["schemas"]["Cart"];
responseCode: 200;
};
"readProduct post /product": {
contentType?: "application/json";
accept?: "application/json";
headers?: {
/** Instructs Shopware to return the response in the given language. */
"sw-language-id"?: string;
};
body?: components["schemas"]["Criteria"];
response: {
elements: components["schemas"]["Product"][]; // TODO: [OpenAPI][readProduct]: add elements property as required
} & components["schemas"]["EntitySearchResult"];
responseCode: 200;
};
"readShippingMethod post /shipping-method": {
contentType?: "application/json";
accept?: "application/json";
headers?: {
/** Instructs Shopware to return the response in the given language. */
"sw-language-id"?: string;
};
query?: {
/** List only available shipping methods. This filters shipping methods methods which can not be used in the actual context because of their availability rule. */
onlyAvailable?: boolean;
};
body?: components["schemas"]["Criteria"];
response: {
/** aggregation result */
aggregations?: Record<string, never>;
elements: components["schemas"]["ShippingMethod"][]; // TODO: [OpenAPI][readShippingMethod]: response should be `EntitySearchResult` and elements should be required
/** Total amount */
total?: number;
};
responseCode: 200;
};
"readBreadcrumb get /breadcrumb/{id}": {
contentType?: "application/json";
accept?: "application/json";
headers?: {
/** Instructs Shopware to return the response in the given language. */
"sw-language-id"?: string; //TODO: [OpenAPI][readBreadcrumb] - sw-language-id should be added
};
query?: {
/** Type: category or product (optional - default: product) */
type?: "product" | "category";
/** UUID for referrer category only used for product breadcrumb */
referrerCategoryId?: string;
};
pathParams: {
/** UUID for product or category */
id: string;
};
response: components["schemas"]["BreadcrumbCollection"];
responseCode: 200;
};
};
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 { currentSessionLanguageID } = useSessionContext();

const getConfirmationText = computed(
() =>
Expand Down Expand Up @@ -145,6 +147,9 @@ const invokeSubmit = async () => {
...state,
navigationId: foreignKey.value,
},
headers: {
"sw-language-id": currentSessionLanguageID.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 { currentSessionLanguageID } = 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": currentSessionLanguageID.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
Loading
Loading