@shopware/composables 1.11.1 → 1.12.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.
- package/README.md +12 -11
- package/dist/index.d.mts +26 -1
- package/dist/index.d.ts +26 -1
- package/dist/index.mjs +125 -75
- package/package.json +11 -12
- package/src/cms/useCmsElementConfig.test.ts +1 -0
- package/src/cms/useCmsElementConfig.ts +1 -0
- package/src/cms/useCmsElementImage.test.ts +1 -0
- package/src/cms/useCmsElementImage.ts +2 -0
- package/src/cms/useCmsElementProductBox.test.ts +1 -0
- package/src/cms/useCmsElementProductBox.ts +2 -0
- package/src/createShopwareContext.test.ts +1 -0
- package/src/createShopwareContext.ts +8 -0
- package/src/devtools/plugin.ts +13 -13
- package/src/helpers/ContextError.spec.ts +1 -0
- package/src/index.test.ts +2 -0
- package/src/index.ts +1 -0
- package/src/types/cmsElementTypes.ts +1 -0
- package/src/useAddToCart/useAddToCart.test.ts +1 -0
- package/src/useAddToCart/useAddToCart.ts +1 -0
- package/src/useAddress/useAddress.test.ts +2 -0
- package/src/useAddress/useAddress.ts +1 -0
- package/src/useB2bQuoteManagement/useB2bQuoteManagement.test.ts +1 -0
- package/src/useBreadcrumbs/useBreadcrumbs.test.ts +2 -0
- package/src/useBreadcrumbs/useBreadcrumbs.ts +1 -0
- package/src/useCart/useCart.test.ts +2 -0
- package/src/useCart/useCart.ts +1 -0
- package/src/useCartErrorParamsResolver/useCartErrorParamsResolver.test.ts +1 -0
- package/src/useCartItem/useCartItem.test.ts +2 -0
- package/src/useCartItem/useCartItem.ts +1 -0
- package/src/useCartNotification/useCartNotification.test.ts +2 -0
- package/src/useCategory/useCategory.test.ts +2 -0
- package/src/useCategory/useCategory.ts +2 -0
- package/src/useCategorySearch/useCategorySearch.test.ts +29 -0
- package/src/useCategorySearch/useCategorySearch.ts +15 -7
- package/src/useCheckout/useCheckout.test.ts +1 -0
- package/src/useCheckout/useCheckout.ts +1 -0
- package/src/useCmsBlock/useCmsBlock.test.ts +2 -0
- package/src/useCmsMeta/useCmsMeta.test.ts +2 -0
- package/src/useCmsMeta/useCmsMeta.ts +1 -0
- package/src/useCmsSection/useCmsSection.test.ts +2 -0
- package/src/useCmsTranslations/useCmsTranslations.test.ts +2 -0
- package/src/useCountries/useCountries.test.ts +19 -0
- package/src/useCountries/useCountries.ts +14 -7
- package/src/useCustomerOrders/useCustomerOrders.test.ts +1 -0
- package/src/useCustomerOrders/useCustomerOrders.ts +1 -0
- package/src/useCustomerPassword/useCustomerPassword.test.ts +1 -0
- package/src/useDefaultOrderAssociations/useDefaultOrderAssociations.test.ts +1 -0
- package/src/useInternationalization/useInternationalization.test.ts +14 -1
- package/src/useInternationalization/useInternationalization.ts +5 -3
- package/src/useLandingSearch/useLandingSearch.test.ts +1 -0
- package/src/useLandingSearch/useLandingSearch.ts +1 -0
- package/src/useListing/useListing.test.ts +2 -0
- package/src/useListing/useListing.ts +3 -2
- package/src/useLocalWishlist/useLocalWishlist.test.ts +1 -0
- package/src/useNavigation/useNavigation.test.ts +24 -1
- package/src/useNavigation/useNavigation.ts +36 -14
- package/src/useNavigationContext/useNavigationContext.test.ts +1 -0
- package/src/useNavigationContext/useNavigationContext.ts +1 -0
- package/src/useNavigationSearch/useNavigationSearch.test.ts +30 -0
- package/src/useNavigationSearch/useNavigationSearch.ts +19 -12
- package/src/useNewsletter/useNewsletter.test.ts +1 -0
- package/src/useNewsletter/useNewsletter.ts +1 -0
- package/src/useNotifications/useNotifications.test.ts +1 -0
- package/src/useOrderDetails/useOrderDetails.test.ts +1 -0
- package/src/useOrderDetails/useOrderDetails.ts +1 -0
- package/src/useOrderPayment/useOrderPayment.test.ts +2 -0
- package/src/useOrderPayment/useOrderPayment.ts +1 -0
- package/src/usePrice/usePrice.test.ts +2 -0
- package/src/usePrice/usePrice.ts +1 -0
- package/src/useProduct/useProduct.test.ts +2 -0
- package/src/useProduct/useProduct.ts +2 -0
- package/src/useProductAssociations/useProductAssociations.spec.ts +48 -0
- package/src/useProductAssociations/useProductAssociations.ts +7 -3
- package/src/useProductConfigurator/useProductConfigurator.spec.ts +24 -0
- package/src/useProductConfigurator/useProductConfigurator.ts +20 -13
- package/src/useProductPrice/useProductPrice.test.ts +2 -0
- package/src/useProductPrice/useProductPrice.ts +1 -0
- package/src/useProductReviews/useProductReviews.test.ts +1 -0
- package/src/useProductReviews/useProductReviews.ts +1 -0
- package/src/useProductSearch/useProductSearch.test.ts +24 -1
- package/src/useProductSearch/useProductSearch.ts +24 -11
- package/src/useProductSearchSuggest/useProductSearchSuggest.test.ts +1 -0
- package/src/useProductSearchSuggest/useProductSearchSuggest.ts +1 -0
- package/src/useProductWishlist/useProductWishlist.test.ts +2 -0
- package/src/useProductWishlist/useProductWishlist.ts +1 -0
- package/src/useSalutations/useSalutations.spec.ts +15 -0
- package/src/useSalutations/useSalutations.ts +5 -2
- package/src/useSessionContext/useSessionContext.test.ts +18 -0
- package/src/useSessionContext/useSessionContext.ts +10 -0
- package/src/useShopwareContext/useShopwareContext.test.ts +1 -0
- package/src/useShopwareContext/useShopwareContext.ts +13 -0
- package/src/useSyncWishlist/useSyncWishlist.test.ts +1 -0
- package/src/useSyncWishlist/useSyncWishlist.ts +1 -0
- package/src/useUrlResolver/useUrlResolver.test.ts +1 -0
- package/src/useUser/useUser.test.ts +35 -2
- package/src/useUser/useUser.ts +34 -25
- package/src/useWishlist/useWishlist.test.ts +2 -0
- package/src/useWishlist/useWishlist.ts +1 -0
package/README.md
CHANGED
|
@@ -123,6 +123,7 @@ Let's get back to the step where the `api-client` was initialized:
|
|
|
123
123
|
```ts [apiClient.ts]
|
|
124
124
|
import { createAPIClient } from "@shopware/api-client";
|
|
125
125
|
import Cookies from "js-cookie";
|
|
126
|
+
|
|
126
127
|
import type { operations } from "#shopware";
|
|
127
128
|
|
|
128
129
|
const shopwareEndpoint = "https://demo-frontends.shopware.store/store-api";
|
|
@@ -165,20 +166,20 @@ All composable functions are fully typed with TypeScript and they are registed g
|
|
|
165
166
|
|
|
166
167
|
Full changelog for stable version is available [here](https://github.com/shopware/frontends/blob/main/packages/composables/CHANGELOG.md)
|
|
167
168
|
|
|
168
|
-
### Latest changes: 1.
|
|
169
|
+
### Latest changes: 1.12.0
|
|
169
170
|
|
|
170
|
-
###
|
|
171
|
+
### Minor Changes
|
|
172
|
+
|
|
173
|
+
- [#2486](https://github.com/shopware/frontends/pull/2486) [`5678fb0`](https://github.com/shopware/frontends/commit/5678fb008cbd86eaddd061e004de89e6f45bb7ec) Thanks [@mkucmus](https://github.com/mkucmus)! - `useSessionContext`: expose `currentLocaleCode` — the active language's locale code (e.g. `"en-GB"`), read directly from the context's `languageInfo`. The current locale can now be derived from the session context alone, without loading the full language list via `useInternationalization().getAvailableLanguages()` just to map the current `languageId` to a locale.
|
|
171
174
|
|
|
172
|
-
- [#
|
|
175
|
+
- [#2473](https://github.com/shopware/frontends/pull/2473) [`22611e5`](https://github.com/shopware/frontends/commit/22611e542b8f42a4f34dce5186f628f9a17f457b) Thanks [@mkucmus](https://github.com/mkucmus)! - Add an opt-in `cacheableReads` flag that routes anonymous Store API reads through their cacheable GET variants instead of POST. Criteria is compressed into the `_criteria` query param via `encodeForQuery` from `@shopware/api-client/helpers`, which lets CDNs / reverse proxies / the browser cache the responses.
|
|
173
176
|
|
|
174
|
-
|
|
175
|
-
`useNavigationSearch` to resolve `/navigation/*`, `/detail/*`, and
|
|
176
|
-
`/landingPage/*` routes more reliably, including fallback behavior when no SEO
|
|
177
|
-
mapping row is returned.
|
|
177
|
+
Disabled by default — fully backwards compatible. Enable it in `nuxt.config` (`shopware: { cacheableReads: true }`) or via `createShopwareContext(app, { cacheableReads: true })` for non-Nuxt setups. It is surfaced on the Shopware context and read by the affected composables; public composable signatures are unchanged.
|
|
178
178
|
|
|
179
|
-
|
|
179
|
+
Affected composables: `useNavigation`, `useNavigationSearch`, `useCountries`, `useUser` (country + salutation lookups), `useSalutations`, `useInternationalization`, `useProductConfigurator`, `useProductSearch`, and `useCategorySearch.advancedSearch`.
|
|
180
180
|
|
|
181
|
-
|
|
181
|
+
`useListing` (product-listing), single-category `useCategorySearch.search`, and `useLandingSearch` remain POST for now: the generated Store API schema does not type `_criteria` on those GET routes (a Shopware OpenAPI gap). The backend does honor `_criteria` on product-listing GET at runtime, so that one can be migrated later once the types are augmented.
|
|
182
|
+
|
|
183
|
+
### Patch Changes
|
|
182
184
|
|
|
183
|
-
-
|
|
184
|
-
- @shopware/helpers@1.7.1
|
|
185
|
+
- [#2462](https://github.com/shopware/frontends/pull/2462) [`8be060d`](https://github.com/shopware/frontends/commit/8be060de825ca799f98a8f045a5e7fea61f5d1a2) Thanks [@mkucmus](https://github.com/mkucmus)! - `useProductAssociations`: add optional `includeSeoUrls` option. When `true`, the cross-selling request sends `sw-include-seo-urls: true` so returned products include the `seoUrls` association. Defaults to `false` to avoid extra backend overhead.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
2
|
import { CSSProperties, ComputedRef, AnchorHTMLAttributes, ImgHTMLAttributes, App, EffectScope, Ref } from 'vue';
|
|
3
3
|
import { createAPIClient, ApiError } from '@shopware/api-client';
|
|
4
|
-
import { operations as operations$1
|
|
4
|
+
import { components, operations as operations$1 } from '@shopware/api-client/store-api-types';
|
|
5
5
|
import * as _shopware_api_client_api_types from '@shopware/api-client/api-types';
|
|
6
6
|
import { getListingFilters, TierPrice } from '@shopware/helpers';
|
|
7
7
|
|
|
@@ -421,6 +421,13 @@ declare function createShopwareContext(app: App, options: {
|
|
|
421
421
|
devStorefrontUrl?: string | null;
|
|
422
422
|
enableDevtools?: boolean;
|
|
423
423
|
browserLocale?: string;
|
|
424
|
+
/**
|
|
425
|
+
* Opt in to reading data via cacheable GET Store API routes instead of
|
|
426
|
+
* POST. Surfaced on the Shopware context as `cacheableReads`.
|
|
427
|
+
*
|
|
428
|
+
* @default false
|
|
429
|
+
*/
|
|
430
|
+
cacheableReads?: boolean;
|
|
424
431
|
}): vue.Raw<{
|
|
425
432
|
install(app: App): void;
|
|
426
433
|
_a: App<any>;
|
|
@@ -430,6 +437,7 @@ declare function createShopwareContext(app: App, options: {
|
|
|
430
437
|
interceptors: {};
|
|
431
438
|
} | undefined;
|
|
432
439
|
browserLocale: string;
|
|
440
|
+
cacheableReads: boolean;
|
|
433
441
|
}>;
|
|
434
442
|
|
|
435
443
|
type UseAddressReturn = {
|
|
@@ -1715,6 +1723,7 @@ type UseProductAssociationsReturn = {
|
|
|
1715
1723
|
*/
|
|
1716
1724
|
declare function useProductAssociations(product: ComputedRef<Schemas["Product"]>, options: {
|
|
1717
1725
|
associationContext: "cross-selling" | "reviews";
|
|
1726
|
+
includeSeoUrls?: boolean;
|
|
1718
1727
|
}): UseProductAssociationsReturn;
|
|
1719
1728
|
|
|
1720
1729
|
type UseProductConfiguratorReturn = {
|
|
@@ -2018,6 +2027,12 @@ type UseSessionContextReturn = {
|
|
|
2018
2027
|
* current language code
|
|
2019
2028
|
*/
|
|
2020
2029
|
currentLanguageId: ComputedRef<string | undefined>;
|
|
2030
|
+
/**
|
|
2031
|
+
* Locale code of the active language (e.g. `"en-GB"`), read from the
|
|
2032
|
+
* context's `languageInfo`. Available from the session context alone — no
|
|
2033
|
+
* separate language list request is required to detect the current locale.
|
|
2034
|
+
*/
|
|
2035
|
+
currentLocaleCode: ComputedRef<string | undefined>;
|
|
2021
2036
|
/**
|
|
2022
2037
|
* current context's customer object
|
|
2023
2038
|
*/
|
|
@@ -2042,6 +2057,16 @@ type ShopwareContext = {
|
|
|
2042
2057
|
* If not provided, it will be "en-US"
|
|
2043
2058
|
*/
|
|
2044
2059
|
browserLocale: string;
|
|
2060
|
+
/**
|
|
2061
|
+
* When `true`, composables read data through the cacheable GET variants of
|
|
2062
|
+
* the Store API (criteria compressed into the `_criteria` query param)
|
|
2063
|
+
* instead of POST, so the responses can be cached by HTTP infrastructure
|
|
2064
|
+
* (CDN, reverse proxy, browser). Requires a backend that supports the GET
|
|
2065
|
+
* read routes.
|
|
2066
|
+
*
|
|
2067
|
+
* @default false
|
|
2068
|
+
*/
|
|
2069
|
+
cacheableReads: boolean;
|
|
2045
2070
|
};
|
|
2046
2071
|
/**
|
|
2047
2072
|
* @public
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
2
|
import { CSSProperties, ComputedRef, AnchorHTMLAttributes, ImgHTMLAttributes, App, EffectScope, Ref } from 'vue';
|
|
3
3
|
import { createAPIClient, ApiError } from '@shopware/api-client';
|
|
4
|
-
import { operations as operations$1
|
|
4
|
+
import { components, operations as operations$1 } from '@shopware/api-client/store-api-types';
|
|
5
5
|
import * as _shopware_api_client_api_types from '@shopware/api-client/api-types';
|
|
6
6
|
import { getListingFilters, TierPrice } from '@shopware/helpers';
|
|
7
7
|
|
|
@@ -421,6 +421,13 @@ declare function createShopwareContext(app: App, options: {
|
|
|
421
421
|
devStorefrontUrl?: string | null;
|
|
422
422
|
enableDevtools?: boolean;
|
|
423
423
|
browserLocale?: string;
|
|
424
|
+
/**
|
|
425
|
+
* Opt in to reading data via cacheable GET Store API routes instead of
|
|
426
|
+
* POST. Surfaced on the Shopware context as `cacheableReads`.
|
|
427
|
+
*
|
|
428
|
+
* @default false
|
|
429
|
+
*/
|
|
430
|
+
cacheableReads?: boolean;
|
|
424
431
|
}): vue.Raw<{
|
|
425
432
|
install(app: App): void;
|
|
426
433
|
_a: App<any>;
|
|
@@ -430,6 +437,7 @@ declare function createShopwareContext(app: App, options: {
|
|
|
430
437
|
interceptors: {};
|
|
431
438
|
} | undefined;
|
|
432
439
|
browserLocale: string;
|
|
440
|
+
cacheableReads: boolean;
|
|
433
441
|
}>;
|
|
434
442
|
|
|
435
443
|
type UseAddressReturn = {
|
|
@@ -1715,6 +1723,7 @@ type UseProductAssociationsReturn = {
|
|
|
1715
1723
|
*/
|
|
1716
1724
|
declare function useProductAssociations(product: ComputedRef<Schemas["Product"]>, options: {
|
|
1717
1725
|
associationContext: "cross-selling" | "reviews";
|
|
1726
|
+
includeSeoUrls?: boolean;
|
|
1718
1727
|
}): UseProductAssociationsReturn;
|
|
1719
1728
|
|
|
1720
1729
|
type UseProductConfiguratorReturn = {
|
|
@@ -2018,6 +2027,12 @@ type UseSessionContextReturn = {
|
|
|
2018
2027
|
* current language code
|
|
2019
2028
|
*/
|
|
2020
2029
|
currentLanguageId: ComputedRef<string | undefined>;
|
|
2030
|
+
/**
|
|
2031
|
+
* Locale code of the active language (e.g. `"en-GB"`), read from the
|
|
2032
|
+
* context's `languageInfo`. Available from the session context alone — no
|
|
2033
|
+
* separate language list request is required to detect the current locale.
|
|
2034
|
+
*/
|
|
2035
|
+
currentLocaleCode: ComputedRef<string | undefined>;
|
|
2021
2036
|
/**
|
|
2022
2037
|
* current context's customer object
|
|
2023
2038
|
*/
|
|
@@ -2042,6 +2057,16 @@ type ShopwareContext = {
|
|
|
2042
2057
|
* If not provided, it will be "en-US"
|
|
2043
2058
|
*/
|
|
2044
2059
|
browserLocale: string;
|
|
2060
|
+
/**
|
|
2061
|
+
* When `true`, composables read data through the cacheable GET variants of
|
|
2062
|
+
* the Store API (criteria compressed into the `_criteria` query param)
|
|
2063
|
+
* instead of POST, so the responses can be cached by HTTP infrastructure
|
|
2064
|
+
* (CDN, reverse proxy, browser). Requires a backend that supports the GET
|
|
2065
|
+
* read routes.
|
|
2066
|
+
*
|
|
2067
|
+
* @default false
|
|
2068
|
+
*/
|
|
2069
|
+
cacheableReads: boolean;
|
|
2045
2070
|
};
|
|
2046
2071
|
/**
|
|
2047
2072
|
* @public
|
package/dist/index.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import { computed, effectScope, reactive, markRaw, inject, ref, provide, unref,
|
|
|
3
3
|
import { urlIsAbsolute, relativeUrlSlash, getSrcSetForMedia, getMainImageUrl, getTranslatedProperty, getListingFilters, isTechnicalPath, normalizePath, getRouteFromPathInfo, getProductTierPrices, buildUrlPrefix } from '@shopware/helpers';
|
|
4
4
|
import { ApiClientError } from '@shopware/api-client';
|
|
5
5
|
import { createSharedComposable, injectLocal, provideLocal, createInjectionState, syncRefs } from '@vueuse/core';
|
|
6
|
+
import { encodeForQuery } from '@shopware/api-client/helpers';
|
|
6
7
|
import { defu } from 'defu';
|
|
7
8
|
|
|
8
9
|
function useCmsElementImage(element) {
|
|
@@ -86,7 +87,8 @@ function createShopwareContext(app, options) {
|
|
|
86
87
|
_e: scope,
|
|
87
88
|
devStorefrontUrl: options.devStorefrontUrl,
|
|
88
89
|
state,
|
|
89
|
-
browserLocale: options.browserLocale || "en-US"
|
|
90
|
+
browserLocale: options.browserLocale || "en-US",
|
|
91
|
+
cacheableReads: options.cacheableReads ?? false
|
|
90
92
|
});
|
|
91
93
|
if (options?.enableDevtools && typeof window !== "undefined") ;
|
|
92
94
|
return shopwarePlugin;
|
|
@@ -522,7 +524,7 @@ const cmsAssociations = {
|
|
|
522
524
|
};
|
|
523
525
|
|
|
524
526
|
function useCategorySearch() {
|
|
525
|
-
const { apiClient } = useShopwareContext();
|
|
527
|
+
const { apiClient, cacheableReads } = useShopwareContext();
|
|
526
528
|
async function search(categoryId, options) {
|
|
527
529
|
const associations = options?.withCmsAssociations ? cmsAssociations : {};
|
|
528
530
|
const result = await apiClient.invoke(
|
|
@@ -544,11 +546,14 @@ function useCategorySearch() {
|
|
|
544
546
|
}
|
|
545
547
|
async function advancedSearch(options) {
|
|
546
548
|
const associations = options?.withCmsAssociations ? cmsAssociations.associations : {};
|
|
547
|
-
const
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
549
|
+
const criteria = {
|
|
550
|
+
associations,
|
|
551
|
+
...options?.query
|
|
552
|
+
};
|
|
553
|
+
const result = cacheableReads ? await apiClient.invoke("readCategoryListGet get /category", {
|
|
554
|
+
query: { _criteria: encodeForQuery(criteria) }
|
|
555
|
+
}) : await apiClient.invoke("readCategoryList post /category", {
|
|
556
|
+
body: criteria
|
|
552
557
|
});
|
|
553
558
|
return result.data.elements ?? [];
|
|
554
559
|
}
|
|
@@ -698,16 +703,19 @@ function useContext(injectionName, params) {
|
|
|
698
703
|
}
|
|
699
704
|
|
|
700
705
|
function useCountries() {
|
|
701
|
-
const { apiClient } = useShopwareContext();
|
|
706
|
+
const { apiClient, cacheableReads } = useShopwareContext();
|
|
702
707
|
const _sharedCountries = inject("swCountries", ref());
|
|
703
708
|
provide("swCountries", _sharedCountries);
|
|
704
709
|
async function fetchCountries() {
|
|
705
|
-
const
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
states: {}
|
|
709
|
-
}
|
|
710
|
+
const criteria = {
|
|
711
|
+
associations: {
|
|
712
|
+
states: {}
|
|
710
713
|
}
|
|
714
|
+
};
|
|
715
|
+
const result = cacheableReads ? await apiClient.invoke("readCountryGet get /country", {
|
|
716
|
+
query: { _criteria: encodeForQuery(criteria) }
|
|
717
|
+
}) : await apiClient.invoke("readCountry post /country", {
|
|
718
|
+
body: criteria
|
|
711
719
|
});
|
|
712
720
|
_sharedCountries.value = result.data.elements;
|
|
713
721
|
return result.data;
|
|
@@ -835,8 +843,7 @@ function useDefaultOrderAssociations() {
|
|
|
835
843
|
}
|
|
836
844
|
|
|
837
845
|
function useInternationalization(pathResolver) {
|
|
838
|
-
const { devStorefrontUrl } = useShopwareContext();
|
|
839
|
-
const { apiClient } = useShopwareContext();
|
|
846
|
+
const { devStorefrontUrl, apiClient, cacheableReads } = useShopwareContext();
|
|
840
847
|
const _storeLanguages = useContext("swLanguages");
|
|
841
848
|
const _storeCurrentLanguage = useContext(
|
|
842
849
|
"swLanguagesCurrentLanguage"
|
|
@@ -846,7 +853,7 @@ function useInternationalization(pathResolver) {
|
|
|
846
853
|
return devStorefrontUrl ?? window.location.origin ?? "";
|
|
847
854
|
}
|
|
848
855
|
async function getAvailableLanguages() {
|
|
849
|
-
const { data } = await apiClient.invoke("readLanguages post /language");
|
|
856
|
+
const { data } = cacheableReads ? await apiClient.invoke("readLanguagesGet get /language") : await apiClient.invoke("readLanguages post /language");
|
|
850
857
|
_storeLanguages.value = data.elements;
|
|
851
858
|
return data;
|
|
852
859
|
}
|
|
@@ -1262,7 +1269,7 @@ function useLocalWishlist() {
|
|
|
1262
1269
|
|
|
1263
1270
|
function useNavigation(params) {
|
|
1264
1271
|
const type = params?.type || "main-navigation";
|
|
1265
|
-
const { apiClient } = useShopwareContext();
|
|
1272
|
+
const { apiClient, cacheableReads } = useShopwareContext();
|
|
1266
1273
|
const sharedElements = inject(
|
|
1267
1274
|
`swNavigation-${type}`,
|
|
1268
1275
|
ref([])
|
|
@@ -1271,7 +1278,24 @@ function useNavigation(params) {
|
|
|
1271
1278
|
const navigationElements = computed(() => sharedElements.value);
|
|
1272
1279
|
async function loadNavigationElements(params2) {
|
|
1273
1280
|
try {
|
|
1274
|
-
const
|
|
1281
|
+
const { buildTree, depth, ...criteria } = params2;
|
|
1282
|
+
const navigationResponse = cacheableReads ? await apiClient.invoke(
|
|
1283
|
+
"readNavigationGet get /navigation/{activeId}/{rootId}",
|
|
1284
|
+
{
|
|
1285
|
+
headers: {
|
|
1286
|
+
"sw-include-seo-urls": true
|
|
1287
|
+
},
|
|
1288
|
+
pathParams: {
|
|
1289
|
+
activeId: type,
|
|
1290
|
+
rootId: type
|
|
1291
|
+
},
|
|
1292
|
+
query: {
|
|
1293
|
+
_criteria: encodeForQuery(criteria),
|
|
1294
|
+
buildTree,
|
|
1295
|
+
depth
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
) : await apiClient.invoke(
|
|
1275
1299
|
"readNavigation post /navigation/{activeId}/{rootId}",
|
|
1276
1300
|
{
|
|
1277
1301
|
headers: {
|
|
@@ -1310,7 +1334,7 @@ function useNavigationContext(context) {
|
|
|
1310
1334
|
}
|
|
1311
1335
|
|
|
1312
1336
|
function useNavigationSearch() {
|
|
1313
|
-
const { apiClient } = useShopwareContext();
|
|
1337
|
+
const { apiClient, cacheableReads } = useShopwareContext();
|
|
1314
1338
|
const { sessionContext } = useSessionContext();
|
|
1315
1339
|
async function resolvePath(path) {
|
|
1316
1340
|
if (path === "/") {
|
|
@@ -1322,16 +1346,19 @@ function useNavigationSearch() {
|
|
|
1322
1346
|
}
|
|
1323
1347
|
const isTechnicalUrl = isTechnicalPath(path);
|
|
1324
1348
|
const normalizedPath = isTechnicalUrl ? normalizePath(path) : path.substring(1);
|
|
1325
|
-
const
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1349
|
+
const criteria = {
|
|
1350
|
+
filter: [
|
|
1351
|
+
{
|
|
1352
|
+
type: "equals",
|
|
1353
|
+
field: isTechnicalUrl ? "pathInfo" : "seoPathInfo",
|
|
1354
|
+
value: normalizedPath
|
|
1355
|
+
}
|
|
1356
|
+
]
|
|
1357
|
+
};
|
|
1358
|
+
const seoResult = cacheableReads ? await apiClient.invoke("readSeoUrlGet get /seo-url", {
|
|
1359
|
+
query: { _criteria: encodeForQuery(criteria) }
|
|
1360
|
+
}) : await apiClient.invoke("readSeoUrl post /seo-url", {
|
|
1361
|
+
body: criteria
|
|
1335
1362
|
});
|
|
1336
1363
|
const element = seoResult.data.elements?.[0];
|
|
1337
1364
|
if (element) {
|
|
@@ -1413,7 +1440,7 @@ function useNotifications() {
|
|
|
1413
1440
|
_notifications.value = [];
|
|
1414
1441
|
}
|
|
1415
1442
|
function geterateId() {
|
|
1416
|
-
return +`${( new Date()).getTime()}${Math.random() * 1e3}`;
|
|
1443
|
+
return +`${(/* @__PURE__ */ new Date()).getTime()}${Math.random() * 1e3}`;
|
|
1417
1444
|
}
|
|
1418
1445
|
async function pushNotification(message, options) {
|
|
1419
1446
|
const timeout = options.timeout || 2500;
|
|
@@ -1739,7 +1766,6 @@ function useProduct(product, configurator) {
|
|
|
1739
1766
|
function useProductAssociations(product, options) {
|
|
1740
1767
|
if (!product.value)
|
|
1741
1768
|
throw new Error("[useProductAssociations]: Product is not provided.");
|
|
1742
|
-
options.associationContext;
|
|
1743
1769
|
const { apiClient } = useShopwareContext();
|
|
1744
1770
|
const isLoading = ref(false);
|
|
1745
1771
|
const associations = ref([]);
|
|
@@ -1749,6 +1775,11 @@ function useProductAssociations(product, options) {
|
|
|
1749
1775
|
const response = await apiClient.invoke(
|
|
1750
1776
|
"readProductCrossSellings post /product/{productId}/cross-selling",
|
|
1751
1777
|
{
|
|
1778
|
+
...options.includeSeoUrls && {
|
|
1779
|
+
headers: {
|
|
1780
|
+
"sw-include-seo-urls": true
|
|
1781
|
+
}
|
|
1782
|
+
},
|
|
1752
1783
|
pathParams: { productId: product.value.id }
|
|
1753
1784
|
}
|
|
1754
1785
|
);
|
|
@@ -1770,7 +1801,7 @@ function useProductAssociations(product, options) {
|
|
|
1770
1801
|
}
|
|
1771
1802
|
|
|
1772
1803
|
function useProductConfigurator() {
|
|
1773
|
-
const { apiClient } = useShopwareContext();
|
|
1804
|
+
const { apiClient, cacheableReads } = useShopwareContext();
|
|
1774
1805
|
const { configurator, product } = useProduct();
|
|
1775
1806
|
const selected = ref({});
|
|
1776
1807
|
const isLoadingOptions = ref(!!product.value.options?.length);
|
|
@@ -1809,18 +1840,21 @@ function useProductConfigurator() {
|
|
|
1809
1840
|
)
|
|
1810
1841
|
];
|
|
1811
1842
|
try {
|
|
1812
|
-
const
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
seoUrls: {}
|
|
1822
|
-
}
|
|
1843
|
+
const criteria = {
|
|
1844
|
+
filter,
|
|
1845
|
+
limit: 1,
|
|
1846
|
+
includes: {
|
|
1847
|
+
product: ["id", "translated", "productNumber", "seoUrls"],
|
|
1848
|
+
seo_url: ["seoPathInfo"]
|
|
1849
|
+
},
|
|
1850
|
+
associations: {
|
|
1851
|
+
seoUrls: {}
|
|
1823
1852
|
}
|
|
1853
|
+
};
|
|
1854
|
+
const response = cacheableReads ? await apiClient.invoke("readProductGet get /product", {
|
|
1855
|
+
query: { _criteria: encodeForQuery(criteria) }
|
|
1856
|
+
}) : await apiClient.invoke("readProduct post /product", {
|
|
1857
|
+
body: criteria
|
|
1824
1858
|
});
|
|
1825
1859
|
return response.data.elements?.[0];
|
|
1826
1860
|
} catch (e) {
|
|
@@ -1931,23 +1965,31 @@ function useProductReviews(product) {
|
|
|
1931
1965
|
}
|
|
1932
1966
|
|
|
1933
1967
|
function useProductSearch() {
|
|
1934
|
-
const { apiClient } = useShopwareContext();
|
|
1968
|
+
const { apiClient, cacheableReads } = useShopwareContext();
|
|
1935
1969
|
const search = async (productId, options) => {
|
|
1936
1970
|
const associations = defu(
|
|
1937
1971
|
options?.withCmsAssociations ? cmsAssociations : {},
|
|
1938
1972
|
options?.criteria,
|
|
1939
1973
|
{ associations: options?.associations ?? {} }
|
|
1940
1974
|
);
|
|
1941
|
-
const result = await apiClient.invoke(
|
|
1942
|
-
"
|
|
1975
|
+
const result = cacheableReads ? await apiClient.invoke(
|
|
1976
|
+
"readProductDetailGet get /product/{productId}",
|
|
1943
1977
|
{
|
|
1944
1978
|
headers: {
|
|
1945
1979
|
"sw-include-seo-urls": true
|
|
1946
1980
|
},
|
|
1947
1981
|
pathParams: { productId },
|
|
1948
|
-
|
|
1982
|
+
query: {
|
|
1983
|
+
_criteria: encodeForQuery(associations)
|
|
1984
|
+
}
|
|
1949
1985
|
}
|
|
1950
|
-
)
|
|
1986
|
+
) : await apiClient.invoke("readProductDetail post /product/{productId}", {
|
|
1987
|
+
headers: {
|
|
1988
|
+
"sw-include-seo-urls": true
|
|
1989
|
+
},
|
|
1990
|
+
pathParams: { productId },
|
|
1991
|
+
body: associations
|
|
1992
|
+
});
|
|
1951
1993
|
return result.data;
|
|
1952
1994
|
};
|
|
1953
1995
|
return {
|
|
@@ -2015,11 +2057,11 @@ function useProductWishlist(productId) {
|
|
|
2015
2057
|
}
|
|
2016
2058
|
|
|
2017
2059
|
function useSalutations() {
|
|
2018
|
-
const { apiClient } = useShopwareContext();
|
|
2060
|
+
const { apiClient, cacheableReads } = useShopwareContext();
|
|
2019
2061
|
const _salutations = inject("swSalutations", ref());
|
|
2020
2062
|
provide("swSalutations", _salutations);
|
|
2021
2063
|
const fetchSalutations = async () => {
|
|
2022
|
-
const result = await apiClient.invoke("readSalutation post /salutation");
|
|
2064
|
+
const result = cacheableReads ? await apiClient.invoke("readSalutationGet get /salutation") : await apiClient.invoke("readSalutation post /salutation");
|
|
2023
2065
|
_salutations.value = result.data.elements;
|
|
2024
2066
|
return result.data;
|
|
2025
2067
|
};
|
|
@@ -2162,6 +2204,9 @@ function useSessionContext(newContext) {
|
|
|
2162
2204
|
const languageIdChain = computed(
|
|
2163
2205
|
() => sessionContext.value?.context?.languageIdChain?.[0] || ""
|
|
2164
2206
|
);
|
|
2207
|
+
const currentLocaleCode = computed(
|
|
2208
|
+
() => sessionContext.value?.languageInfo?.localeCode
|
|
2209
|
+
);
|
|
2165
2210
|
const taxState = computed(() => sessionContext.value?.context?.taxState);
|
|
2166
2211
|
const userFromContext = computed(() => sessionContext.value?.customer);
|
|
2167
2212
|
return {
|
|
@@ -2186,6 +2231,7 @@ function useSessionContext(newContext) {
|
|
|
2186
2231
|
languageIdChain,
|
|
2187
2232
|
salesChannelLanguageId: languageId,
|
|
2188
2233
|
currentLanguageId: languageIdChain,
|
|
2234
|
+
currentLocaleCode,
|
|
2189
2235
|
setCountry,
|
|
2190
2236
|
setContext
|
|
2191
2237
|
};
|
|
@@ -2201,7 +2247,8 @@ function useShopwareContext() {
|
|
|
2201
2247
|
return {
|
|
2202
2248
|
apiClient,
|
|
2203
2249
|
devStorefrontUrl: shopwareContext.devStorefrontUrl,
|
|
2204
|
-
browserLocale: shopwareContext.browserLocale || "en-US"
|
|
2250
|
+
browserLocale: shopwareContext.browserLocale || "en-US",
|
|
2251
|
+
cacheableReads: shopwareContext.cacheableReads ?? false
|
|
2205
2252
|
};
|
|
2206
2253
|
}
|
|
2207
2254
|
|
|
@@ -2298,7 +2345,7 @@ function useUrlResolver() {
|
|
|
2298
2345
|
}
|
|
2299
2346
|
|
|
2300
2347
|
function useUser() {
|
|
2301
|
-
const { apiClient } = useShopwareContext();
|
|
2348
|
+
const { apiClient, cacheableReads } = useShopwareContext();
|
|
2302
2349
|
const { userFromContext, refreshSessionContext } = useSessionContext();
|
|
2303
2350
|
const _user = useContext("customer");
|
|
2304
2351
|
syncRefs(userFromContext, _user, {
|
|
@@ -2367,35 +2414,38 @@ function useUser() {
|
|
|
2367
2414
|
}
|
|
2368
2415
|
}
|
|
2369
2416
|
async function loadCountry(countryId) {
|
|
2370
|
-
const
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2417
|
+
const criteria = {
|
|
2418
|
+
filter: [
|
|
2419
|
+
{
|
|
2420
|
+
field: "id",
|
|
2421
|
+
type: "equals",
|
|
2422
|
+
value: countryId
|
|
2423
|
+
}
|
|
2424
|
+
]
|
|
2425
|
+
};
|
|
2426
|
+
const countries = cacheableReads ? await apiClient.invoke("readCountryGet get /country", {
|
|
2427
|
+
query: { _criteria: encodeForQuery(criteria) }
|
|
2428
|
+
}) : await apiClient.invoke("readCountry post /country", {
|
|
2429
|
+
body: criteria
|
|
2380
2430
|
});
|
|
2381
2431
|
country.value = countries.data.elements?.[0] ?? null;
|
|
2382
2432
|
return countries.data;
|
|
2383
2433
|
}
|
|
2384
2434
|
async function loadSalutation(salutationId) {
|
|
2385
|
-
const
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
field: "id",
|
|
2392
|
-
type: "equals",
|
|
2393
|
-
value: salutationId
|
|
2394
|
-
}
|
|
2395
|
-
]
|
|
2435
|
+
const criteria = {
|
|
2436
|
+
filter: [
|
|
2437
|
+
{
|
|
2438
|
+
field: "id",
|
|
2439
|
+
type: "equals",
|
|
2440
|
+
value: salutationId
|
|
2396
2441
|
}
|
|
2397
|
-
|
|
2398
|
-
|
|
2442
|
+
]
|
|
2443
|
+
};
|
|
2444
|
+
const salutations = cacheableReads ? await apiClient.invoke("readSalutationGet get /salutation", {
|
|
2445
|
+
query: { _criteria: encodeForQuery(criteria) }
|
|
2446
|
+
}) : await apiClient.invoke("readSalutation post /salutation", {
|
|
2447
|
+
body: criteria
|
|
2448
|
+
});
|
|
2399
2449
|
salutation.value = salutations.data.elements?.[0] ?? null;
|
|
2400
2450
|
return salutations.data;
|
|
2401
2451
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopware/composables",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"description": "Shopware Frontends composables for Vue",
|
|
5
5
|
"author": "Shopware",
|
|
6
6
|
"repository": {
|
|
@@ -52,31 +52,30 @@
|
|
|
52
52
|
"app.config.ts"
|
|
53
53
|
],
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@vueuse/core": "14.
|
|
55
|
+
"@vueuse/core": "14.3.0",
|
|
56
56
|
"defu": "6.1.7",
|
|
57
57
|
"scule": "1.3.0",
|
|
58
58
|
"@shopware/helpers": "1.7.1",
|
|
59
59
|
"@shopware/api-client": "1.5.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@
|
|
63
|
-
"@nuxt/kit": "4.4.6",
|
|
62
|
+
"@nuxt/kit": "4.4.8",
|
|
64
63
|
"@typescript/native-preview": "7.0.0-dev.20260205.1",
|
|
65
|
-
"@vitest/coverage-v8": "4.1.
|
|
66
|
-
"@vue/test-utils": "2.4.
|
|
67
|
-
"happy-dom": "20.
|
|
64
|
+
"@vitest/coverage-v8": "4.1.9",
|
|
65
|
+
"@vue/test-utils": "2.4.11",
|
|
66
|
+
"happy-dom": "20.10.6",
|
|
68
67
|
"typescript": "5.9.3",
|
|
69
|
-
"unbuild": "
|
|
70
|
-
"vitest": "4.1.
|
|
71
|
-
"vue": "3.5.
|
|
68
|
+
"unbuild": "3.6.1",
|
|
69
|
+
"vitest": "4.1.9",
|
|
70
|
+
"vue": "3.5.38",
|
|
72
71
|
"tsconfig": "0.0.0"
|
|
73
72
|
},
|
|
74
73
|
"scripts": {
|
|
75
74
|
"build": "unbuild && pnpm build:types",
|
|
76
75
|
"build:types": "tsgo",
|
|
77
76
|
"dev": "unbuild --stub",
|
|
78
|
-
"lint": "
|
|
79
|
-
"lint:fix": "
|
|
77
|
+
"lint": "oxlint . && oxfmt --check .",
|
|
78
|
+
"lint:fix": "oxlint --fix . && oxfmt --write . && pnpm run typecheck",
|
|
80
79
|
"typecheck": "tsgo --noEmit",
|
|
81
80
|
"test": "vitest run",
|
|
82
81
|
"coverage": "vitest run --coverage",
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { inject } from "vue";
|
|
2
2
|
import { computed } from "vue";
|
|
3
3
|
import type { ComputedRef } from "vue";
|
|
4
|
+
|
|
4
5
|
import type { Schemas } from "#shopware";
|
|
6
|
+
|
|
5
7
|
import { useCmsElementConfig } from "../index";
|
|
6
8
|
import type { BoxLayout, CmsElementProductBox } from "../types";
|
|
7
9
|
|