@shopware/composables 1.11.1 → 1.12.1
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 +18 -13
- package/dist/index.d.mts +35 -5
- package/dist/index.d.ts +35 -5
- package/dist/index.mjs +167 -100
- package/nuxt.config.ts +10 -0
- package/package.json +14 -15
- 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 +2 -1
- package/src/useCart/useCart.test.ts +19 -0
- package/src/useCart/useCart.ts +6 -3
- package/src/useCartErrorParamsResolver/useCartErrorParamsResolver.test.ts +1 -0
- package/src/useCartItem/useCartItem.test.ts +15 -0
- package/src/useCartItem/useCartItem.ts +15 -7
- 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 +104 -2
- package/src/useCategorySearch/useCategorySearch.ts +45 -23
- 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 +96 -6
- package/src/useCountries/useCountries.ts +19 -8
- 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 +42 -2
- package/src/useProductReviews/useProductReviews.ts +18 -8
- 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 +84 -6
- package/src/useSessionContext/useSessionContext.ts +17 -2
- 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 +55 -2
- package/src/useUser/useUser.ts +34 -25
- package/src/useWishlist/useWishlist.test.ts +2 -0
- package/src/useWishlist/useWishlist.ts +1 -0
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;
|
|
@@ -355,7 +357,7 @@ function useCartFunction() {
|
|
|
355
357
|
});
|
|
356
358
|
const count = computed(() => {
|
|
357
359
|
return cartItems.value.reduce(
|
|
358
|
-
(accumulator, lineItem) => lineItem.good === true ? lineItem.quantity + accumulator : accumulator,
|
|
360
|
+
(accumulator, lineItem) => lineItem.good === true ? (lineItem.quantity ?? 0) + accumulator : accumulator,
|
|
359
361
|
0
|
|
360
362
|
);
|
|
361
363
|
});
|
|
@@ -376,7 +378,7 @@ function useCartFunction() {
|
|
|
376
378
|
return cartPrice || 0;
|
|
377
379
|
});
|
|
378
380
|
const isVirtualCart = computed(() => {
|
|
379
|
-
return cartItems.value.length > 0 && cartItems.value.filter((element) => element.type !== "promotion").every((item) => item.states
|
|
381
|
+
return cartItems.value.length > 0 && cartItems.value.filter((element) => element.type !== "promotion").every((item) => item.states?.includes("is-download") ?? false);
|
|
380
382
|
});
|
|
381
383
|
const setCartErrors = (cart2) => {
|
|
382
384
|
if (Object.keys(cart2.errors || {}).length) {
|
|
@@ -428,11 +430,12 @@ function useCartItem(cartItem) {
|
|
|
428
430
|
() => cartItem.value?.price?.listPrice?.price && cartItem.value?.price?.unitPrice
|
|
429
431
|
);
|
|
430
432
|
const itemTotalPrice = computed(() => cartItem.value.price?.totalPrice);
|
|
431
|
-
const itemOptions = computed(
|
|
432
|
-
|
|
433
|
-
|
|
433
|
+
const itemOptions = computed(() => {
|
|
434
|
+
const payload = cartItem.value.payload;
|
|
435
|
+
return cartItem.value.type === "product" ? payload?.options ?? [] : [];
|
|
436
|
+
});
|
|
434
437
|
const itemStock = computed(
|
|
435
|
-
() => cartItem.value.deliveryInformation
|
|
438
|
+
() => cartItem.value.deliveryInformation?.stock
|
|
436
439
|
);
|
|
437
440
|
const isDigital = computed(
|
|
438
441
|
() => !!cartItem.value.states?.includes("is-download")
|
|
@@ -522,33 +525,44 @@ const cmsAssociations = {
|
|
|
522
525
|
};
|
|
523
526
|
|
|
524
527
|
function useCategorySearch() {
|
|
525
|
-
const { apiClient } = useShopwareContext();
|
|
528
|
+
const { apiClient, cacheableReads } = useShopwareContext();
|
|
526
529
|
async function search(categoryId, options) {
|
|
527
530
|
const associations = options?.withCmsAssociations ? cmsAssociations : {};
|
|
528
|
-
const
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
531
|
+
const criteria = {
|
|
532
|
+
associations,
|
|
533
|
+
...options?.query
|
|
534
|
+
};
|
|
535
|
+
const result = cacheableReads ? await apiClient.invoke("readCategoryGet get /category/{navigationId}", {
|
|
536
|
+
pathParams: {
|
|
537
|
+
navigationId: categoryId
|
|
538
|
+
},
|
|
539
|
+
headers: {
|
|
540
|
+
"sw-include-seo-urls": true
|
|
541
|
+
},
|
|
542
|
+
query: {
|
|
543
|
+
_criteria: encodeForQuery(criteria)
|
|
541
544
|
}
|
|
542
|
-
)
|
|
545
|
+
}) : await apiClient.invoke("readCategory post /category/{navigationId}", {
|
|
546
|
+
pathParams: {
|
|
547
|
+
navigationId: categoryId
|
|
548
|
+
},
|
|
549
|
+
headers: {
|
|
550
|
+
"sw-include-seo-urls": true
|
|
551
|
+
},
|
|
552
|
+
body: criteria
|
|
553
|
+
});
|
|
543
554
|
return result.data;
|
|
544
555
|
}
|
|
545
556
|
async function advancedSearch(options) {
|
|
546
557
|
const associations = options?.withCmsAssociations ? cmsAssociations.associations : {};
|
|
547
|
-
const
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
558
|
+
const criteria = {
|
|
559
|
+
associations,
|
|
560
|
+
...options?.query
|
|
561
|
+
};
|
|
562
|
+
const result = cacheableReads ? await apiClient.invoke("readCategoryListGet get /category", {
|
|
563
|
+
query: { _criteria: encodeForQuery(criteria) }
|
|
564
|
+
}) : await apiClient.invoke("readCategoryList post /category", {
|
|
565
|
+
body: criteria
|
|
552
566
|
});
|
|
553
567
|
return result.data.elements ?? [];
|
|
554
568
|
}
|
|
@@ -697,18 +711,22 @@ function useContext(injectionName, params) {
|
|
|
697
711
|
return _context;
|
|
698
712
|
}
|
|
699
713
|
|
|
700
|
-
function useCountries() {
|
|
701
|
-
const { apiClient } = useShopwareContext();
|
|
714
|
+
function useCountries(criteria) {
|
|
715
|
+
const { apiClient, cacheableReads } = useShopwareContext();
|
|
702
716
|
const _sharedCountries = inject("swCountries", ref());
|
|
703
717
|
provide("swCountries", _sharedCountries);
|
|
718
|
+
const searchCriteria = ref(criteria ?? {});
|
|
704
719
|
async function fetchCountries() {
|
|
705
|
-
const
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
states: {}
|
|
709
|
-
}
|
|
720
|
+
const queryCriteria = defu(searchCriteria.value, {
|
|
721
|
+
associations: {
|
|
722
|
+
states: {}
|
|
710
723
|
}
|
|
711
724
|
});
|
|
725
|
+
const result = cacheableReads ? await apiClient.invoke("readCountryGet get /country", {
|
|
726
|
+
query: { _criteria: encodeForQuery(queryCriteria) }
|
|
727
|
+
}) : await apiClient.invoke("readCountry post /country", {
|
|
728
|
+
body: queryCriteria
|
|
729
|
+
});
|
|
712
730
|
_sharedCountries.value = result.data.elements;
|
|
713
731
|
return result.data;
|
|
714
732
|
}
|
|
@@ -835,8 +853,7 @@ function useDefaultOrderAssociations() {
|
|
|
835
853
|
}
|
|
836
854
|
|
|
837
855
|
function useInternationalization(pathResolver) {
|
|
838
|
-
const { devStorefrontUrl } = useShopwareContext();
|
|
839
|
-
const { apiClient } = useShopwareContext();
|
|
856
|
+
const { devStorefrontUrl, apiClient, cacheableReads } = useShopwareContext();
|
|
840
857
|
const _storeLanguages = useContext("swLanguages");
|
|
841
858
|
const _storeCurrentLanguage = useContext(
|
|
842
859
|
"swLanguagesCurrentLanguage"
|
|
@@ -846,7 +863,7 @@ function useInternationalization(pathResolver) {
|
|
|
846
863
|
return devStorefrontUrl ?? window.location.origin ?? "";
|
|
847
864
|
}
|
|
848
865
|
async function getAvailableLanguages() {
|
|
849
|
-
const { data } = await apiClient.invoke("readLanguages post /language");
|
|
866
|
+
const { data } = cacheableReads ? await apiClient.invoke("readLanguagesGet get /language") : await apiClient.invoke("readLanguages post /language");
|
|
850
867
|
_storeLanguages.value = data.elements;
|
|
851
868
|
return data;
|
|
852
869
|
}
|
|
@@ -1262,7 +1279,7 @@ function useLocalWishlist() {
|
|
|
1262
1279
|
|
|
1263
1280
|
function useNavigation(params) {
|
|
1264
1281
|
const type = params?.type || "main-navigation";
|
|
1265
|
-
const { apiClient } = useShopwareContext();
|
|
1282
|
+
const { apiClient, cacheableReads } = useShopwareContext();
|
|
1266
1283
|
const sharedElements = inject(
|
|
1267
1284
|
`swNavigation-${type}`,
|
|
1268
1285
|
ref([])
|
|
@@ -1271,7 +1288,24 @@ function useNavigation(params) {
|
|
|
1271
1288
|
const navigationElements = computed(() => sharedElements.value);
|
|
1272
1289
|
async function loadNavigationElements(params2) {
|
|
1273
1290
|
try {
|
|
1274
|
-
const
|
|
1291
|
+
const { buildTree, depth, ...criteria } = params2;
|
|
1292
|
+
const navigationResponse = cacheableReads ? await apiClient.invoke(
|
|
1293
|
+
"readNavigationGet get /navigation/{activeId}/{rootId}",
|
|
1294
|
+
{
|
|
1295
|
+
headers: {
|
|
1296
|
+
"sw-include-seo-urls": true
|
|
1297
|
+
},
|
|
1298
|
+
pathParams: {
|
|
1299
|
+
activeId: type,
|
|
1300
|
+
rootId: type
|
|
1301
|
+
},
|
|
1302
|
+
query: {
|
|
1303
|
+
_criteria: encodeForQuery(criteria),
|
|
1304
|
+
buildTree,
|
|
1305
|
+
depth
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
) : await apiClient.invoke(
|
|
1275
1309
|
"readNavigation post /navigation/{activeId}/{rootId}",
|
|
1276
1310
|
{
|
|
1277
1311
|
headers: {
|
|
@@ -1310,7 +1344,7 @@ function useNavigationContext(context) {
|
|
|
1310
1344
|
}
|
|
1311
1345
|
|
|
1312
1346
|
function useNavigationSearch() {
|
|
1313
|
-
const { apiClient } = useShopwareContext();
|
|
1347
|
+
const { apiClient, cacheableReads } = useShopwareContext();
|
|
1314
1348
|
const { sessionContext } = useSessionContext();
|
|
1315
1349
|
async function resolvePath(path) {
|
|
1316
1350
|
if (path === "/") {
|
|
@@ -1322,16 +1356,19 @@ function useNavigationSearch() {
|
|
|
1322
1356
|
}
|
|
1323
1357
|
const isTechnicalUrl = isTechnicalPath(path);
|
|
1324
1358
|
const normalizedPath = isTechnicalUrl ? normalizePath(path) : path.substring(1);
|
|
1325
|
-
const
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1359
|
+
const criteria = {
|
|
1360
|
+
filter: [
|
|
1361
|
+
{
|
|
1362
|
+
type: "equals",
|
|
1363
|
+
field: isTechnicalUrl ? "pathInfo" : "seoPathInfo",
|
|
1364
|
+
value: normalizedPath
|
|
1365
|
+
}
|
|
1366
|
+
]
|
|
1367
|
+
};
|
|
1368
|
+
const seoResult = cacheableReads ? await apiClient.invoke("readSeoUrlGet get /seo-url", {
|
|
1369
|
+
query: { _criteria: encodeForQuery(criteria) }
|
|
1370
|
+
}) : await apiClient.invoke("readSeoUrl post /seo-url", {
|
|
1371
|
+
body: criteria
|
|
1335
1372
|
});
|
|
1336
1373
|
const element = seoResult.data.elements?.[0];
|
|
1337
1374
|
if (element) {
|
|
@@ -1413,7 +1450,7 @@ function useNotifications() {
|
|
|
1413
1450
|
_notifications.value = [];
|
|
1414
1451
|
}
|
|
1415
1452
|
function geterateId() {
|
|
1416
|
-
return +`${( new Date()).getTime()}${Math.random() * 1e3}`;
|
|
1453
|
+
return +`${(/* @__PURE__ */ new Date()).getTime()}${Math.random() * 1e3}`;
|
|
1417
1454
|
}
|
|
1418
1455
|
async function pushNotification(message, options) {
|
|
1419
1456
|
const timeout = options.timeout || 2500;
|
|
@@ -1739,7 +1776,6 @@ function useProduct(product, configurator) {
|
|
|
1739
1776
|
function useProductAssociations(product, options) {
|
|
1740
1777
|
if (!product.value)
|
|
1741
1778
|
throw new Error("[useProductAssociations]: Product is not provided.");
|
|
1742
|
-
options.associationContext;
|
|
1743
1779
|
const { apiClient } = useShopwareContext();
|
|
1744
1780
|
const isLoading = ref(false);
|
|
1745
1781
|
const associations = ref([]);
|
|
@@ -1749,6 +1785,11 @@ function useProductAssociations(product, options) {
|
|
|
1749
1785
|
const response = await apiClient.invoke(
|
|
1750
1786
|
"readProductCrossSellings post /product/{productId}/cross-selling",
|
|
1751
1787
|
{
|
|
1788
|
+
...options.includeSeoUrls && {
|
|
1789
|
+
headers: {
|
|
1790
|
+
"sw-include-seo-urls": true
|
|
1791
|
+
}
|
|
1792
|
+
},
|
|
1752
1793
|
pathParams: { productId: product.value.id }
|
|
1753
1794
|
}
|
|
1754
1795
|
);
|
|
@@ -1770,7 +1811,7 @@ function useProductAssociations(product, options) {
|
|
|
1770
1811
|
}
|
|
1771
1812
|
|
|
1772
1813
|
function useProductConfigurator() {
|
|
1773
|
-
const { apiClient } = useShopwareContext();
|
|
1814
|
+
const { apiClient, cacheableReads } = useShopwareContext();
|
|
1774
1815
|
const { configurator, product } = useProduct();
|
|
1775
1816
|
const selected = ref({});
|
|
1776
1817
|
const isLoadingOptions = ref(!!product.value.options?.length);
|
|
@@ -1809,18 +1850,21 @@ function useProductConfigurator() {
|
|
|
1809
1850
|
)
|
|
1810
1851
|
];
|
|
1811
1852
|
try {
|
|
1812
|
-
const
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
seoUrls: {}
|
|
1822
|
-
}
|
|
1853
|
+
const criteria = {
|
|
1854
|
+
filter,
|
|
1855
|
+
limit: 1,
|
|
1856
|
+
includes: {
|
|
1857
|
+
product: ["id", "translated", "productNumber", "seoUrls"],
|
|
1858
|
+
seo_url: ["seoPathInfo"]
|
|
1859
|
+
},
|
|
1860
|
+
associations: {
|
|
1861
|
+
seoUrls: {}
|
|
1823
1862
|
}
|
|
1863
|
+
};
|
|
1864
|
+
const response = cacheableReads ? await apiClient.invoke("readProductGet get /product", {
|
|
1865
|
+
query: { _criteria: encodeForQuery(criteria) }
|
|
1866
|
+
}) : await apiClient.invoke("readProduct post /product", {
|
|
1867
|
+
body: criteria
|
|
1824
1868
|
});
|
|
1825
1869
|
return response.data.elements?.[0];
|
|
1826
1870
|
} catch (e) {
|
|
@@ -1901,10 +1945,16 @@ function useProductPrice(product) {
|
|
|
1901
1945
|
}
|
|
1902
1946
|
|
|
1903
1947
|
function useProductReviews(product) {
|
|
1904
|
-
const { apiClient } = useShopwareContext();
|
|
1948
|
+
const { apiClient, cacheableReads } = useShopwareContext();
|
|
1905
1949
|
const productReviews = ref([]);
|
|
1906
1950
|
const loadProductReviews = async (parameters = {}) => {
|
|
1907
|
-
const fetchedReviews = await apiClient.invoke(
|
|
1951
|
+
const fetchedReviews = cacheableReads ? await apiClient.invoke(
|
|
1952
|
+
"readProductReviewsGet get /product/{productId}/reviews",
|
|
1953
|
+
{
|
|
1954
|
+
pathParams: { productId: product.value.id },
|
|
1955
|
+
query: { _criteria: encodeForQuery(parameters) }
|
|
1956
|
+
}
|
|
1957
|
+
) : await apiClient.invoke(
|
|
1908
1958
|
"readProductReviews post /product/{productId}/reviews",
|
|
1909
1959
|
{
|
|
1910
1960
|
pathParams: { productId: product.value.id },
|
|
@@ -1931,23 +1981,31 @@ function useProductReviews(product) {
|
|
|
1931
1981
|
}
|
|
1932
1982
|
|
|
1933
1983
|
function useProductSearch() {
|
|
1934
|
-
const { apiClient } = useShopwareContext();
|
|
1984
|
+
const { apiClient, cacheableReads } = useShopwareContext();
|
|
1935
1985
|
const search = async (productId, options) => {
|
|
1936
1986
|
const associations = defu(
|
|
1937
1987
|
options?.withCmsAssociations ? cmsAssociations : {},
|
|
1938
1988
|
options?.criteria,
|
|
1939
1989
|
{ associations: options?.associations ?? {} }
|
|
1940
1990
|
);
|
|
1941
|
-
const result = await apiClient.invoke(
|
|
1942
|
-
"
|
|
1991
|
+
const result = cacheableReads ? await apiClient.invoke(
|
|
1992
|
+
"readProductDetailGet get /product/{productId}",
|
|
1943
1993
|
{
|
|
1944
1994
|
headers: {
|
|
1945
1995
|
"sw-include-seo-urls": true
|
|
1946
1996
|
},
|
|
1947
1997
|
pathParams: { productId },
|
|
1948
|
-
|
|
1998
|
+
query: {
|
|
1999
|
+
_criteria: encodeForQuery(associations)
|
|
2000
|
+
}
|
|
1949
2001
|
}
|
|
1950
|
-
)
|
|
2002
|
+
) : await apiClient.invoke("readProductDetail post /product/{productId}", {
|
|
2003
|
+
headers: {
|
|
2004
|
+
"sw-include-seo-urls": true
|
|
2005
|
+
},
|
|
2006
|
+
pathParams: { productId },
|
|
2007
|
+
body: associations
|
|
2008
|
+
});
|
|
1951
2009
|
return result.data;
|
|
1952
2010
|
};
|
|
1953
2011
|
return {
|
|
@@ -2015,11 +2073,11 @@ function useProductWishlist(productId) {
|
|
|
2015
2073
|
}
|
|
2016
2074
|
|
|
2017
2075
|
function useSalutations() {
|
|
2018
|
-
const { apiClient } = useShopwareContext();
|
|
2076
|
+
const { apiClient, cacheableReads } = useShopwareContext();
|
|
2019
2077
|
const _salutations = inject("swSalutations", ref());
|
|
2020
2078
|
provide("swSalutations", _salutations);
|
|
2021
2079
|
const fetchSalutations = async () => {
|
|
2022
|
-
const result = await apiClient.invoke("readSalutation post /salutation");
|
|
2080
|
+
const result = cacheableReads ? await apiClient.invoke("readSalutationGet get /salutation") : await apiClient.invoke("readSalutation post /salutation");
|
|
2023
2081
|
_salutations.value = result.data.elements;
|
|
2024
2082
|
return result.data;
|
|
2025
2083
|
};
|
|
@@ -2050,6 +2108,7 @@ function useSessionContext(newContext) {
|
|
|
2050
2108
|
_sessionContext.value = data;
|
|
2051
2109
|
} catch (e) {
|
|
2052
2110
|
console.error("[UseSessionContext][refreshSessionContext]", e);
|
|
2111
|
+
throw e;
|
|
2053
2112
|
}
|
|
2054
2113
|
};
|
|
2055
2114
|
const selectedShippingMethod = computed(
|
|
@@ -2129,7 +2188,7 @@ function useSessionContext(newContext) {
|
|
|
2129
2188
|
shippingAddressId: address.id
|
|
2130
2189
|
}
|
|
2131
2190
|
});
|
|
2132
|
-
refreshSessionContext();
|
|
2191
|
+
await refreshSessionContext();
|
|
2133
2192
|
};
|
|
2134
2193
|
const activeBillingAddress = computed(
|
|
2135
2194
|
() => sessionContext.value?.customer?.activeBillingAddress || null
|
|
@@ -2145,7 +2204,7 @@ function useSessionContext(newContext) {
|
|
|
2145
2204
|
billingAddressId: address.id
|
|
2146
2205
|
}
|
|
2147
2206
|
});
|
|
2148
|
-
refreshSessionContext();
|
|
2207
|
+
await refreshSessionContext();
|
|
2149
2208
|
};
|
|
2150
2209
|
const setContext = (context) => {
|
|
2151
2210
|
_sessionContext.value = context;
|
|
@@ -2162,6 +2221,9 @@ function useSessionContext(newContext) {
|
|
|
2162
2221
|
const languageIdChain = computed(
|
|
2163
2222
|
() => sessionContext.value?.context?.languageIdChain?.[0] || ""
|
|
2164
2223
|
);
|
|
2224
|
+
const currentLocaleCode = computed(
|
|
2225
|
+
() => sessionContext.value?.languageInfo?.localeCode
|
|
2226
|
+
);
|
|
2165
2227
|
const taxState = computed(() => sessionContext.value?.context?.taxState);
|
|
2166
2228
|
const userFromContext = computed(() => sessionContext.value?.customer);
|
|
2167
2229
|
return {
|
|
@@ -2186,6 +2248,7 @@ function useSessionContext(newContext) {
|
|
|
2186
2248
|
languageIdChain,
|
|
2187
2249
|
salesChannelLanguageId: languageId,
|
|
2188
2250
|
currentLanguageId: languageIdChain,
|
|
2251
|
+
currentLocaleCode,
|
|
2189
2252
|
setCountry,
|
|
2190
2253
|
setContext
|
|
2191
2254
|
};
|
|
@@ -2201,7 +2264,8 @@ function useShopwareContext() {
|
|
|
2201
2264
|
return {
|
|
2202
2265
|
apiClient,
|
|
2203
2266
|
devStorefrontUrl: shopwareContext.devStorefrontUrl,
|
|
2204
|
-
browserLocale: shopwareContext.browserLocale || "en-US"
|
|
2267
|
+
browserLocale: shopwareContext.browserLocale || "en-US",
|
|
2268
|
+
cacheableReads: shopwareContext.cacheableReads ?? false
|
|
2205
2269
|
};
|
|
2206
2270
|
}
|
|
2207
2271
|
|
|
@@ -2298,7 +2362,7 @@ function useUrlResolver() {
|
|
|
2298
2362
|
}
|
|
2299
2363
|
|
|
2300
2364
|
function useUser() {
|
|
2301
|
-
const { apiClient } = useShopwareContext();
|
|
2365
|
+
const { apiClient, cacheableReads } = useShopwareContext();
|
|
2302
2366
|
const { userFromContext, refreshSessionContext } = useSessionContext();
|
|
2303
2367
|
const _user = useContext("customer");
|
|
2304
2368
|
syncRefs(userFromContext, _user, {
|
|
@@ -2367,35 +2431,38 @@ function useUser() {
|
|
|
2367
2431
|
}
|
|
2368
2432
|
}
|
|
2369
2433
|
async function loadCountry(countryId) {
|
|
2370
|
-
const
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2434
|
+
const criteria = {
|
|
2435
|
+
filter: [
|
|
2436
|
+
{
|
|
2437
|
+
field: "id",
|
|
2438
|
+
type: "equals",
|
|
2439
|
+
value: countryId
|
|
2440
|
+
}
|
|
2441
|
+
]
|
|
2442
|
+
};
|
|
2443
|
+
const countries = cacheableReads ? await apiClient.invoke("readCountryGet get /country", {
|
|
2444
|
+
query: { _criteria: encodeForQuery(criteria) }
|
|
2445
|
+
}) : await apiClient.invoke("readCountry post /country", {
|
|
2446
|
+
body: criteria
|
|
2380
2447
|
});
|
|
2381
2448
|
country.value = countries.data.elements?.[0] ?? null;
|
|
2382
2449
|
return countries.data;
|
|
2383
2450
|
}
|
|
2384
2451
|
async function loadSalutation(salutationId) {
|
|
2385
|
-
const
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
field: "id",
|
|
2392
|
-
type: "equals",
|
|
2393
|
-
value: salutationId
|
|
2394
|
-
}
|
|
2395
|
-
]
|
|
2452
|
+
const criteria = {
|
|
2453
|
+
filter: [
|
|
2454
|
+
{
|
|
2455
|
+
field: "id",
|
|
2456
|
+
type: "equals",
|
|
2457
|
+
value: salutationId
|
|
2396
2458
|
}
|
|
2397
|
-
|
|
2398
|
-
|
|
2459
|
+
]
|
|
2460
|
+
};
|
|
2461
|
+
const salutations = cacheableReads ? await apiClient.invoke("readSalutationGet get /salutation", {
|
|
2462
|
+
query: { _criteria: encodeForQuery(criteria) }
|
|
2463
|
+
}) : await apiClient.invoke("readSalutation post /salutation", {
|
|
2464
|
+
body: criteria
|
|
2465
|
+
});
|
|
2399
2466
|
salutation.value = salutations.data.elements?.[0] ?? null;
|
|
2400
2467
|
return salutations.data;
|
|
2401
2468
|
}
|
package/nuxt.config.ts
CHANGED
|
@@ -8,6 +8,16 @@ export default defineNuxtConfig({
|
|
|
8
8
|
build: {
|
|
9
9
|
transpile: ["@shopware/composables"],
|
|
10
10
|
},
|
|
11
|
+
vite: {
|
|
12
|
+
build: {
|
|
13
|
+
rolldownOptions: {
|
|
14
|
+
checks: {
|
|
15
|
+
invalidAnnotation: false,
|
|
16
|
+
pluginTimings: false,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
11
21
|
telemetry: {
|
|
12
22
|
enabled: false,
|
|
13
23
|
},
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopware/composables",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.1",
|
|
4
4
|
"description": "Shopware Frontends composables for Vue",
|
|
5
5
|
"author": "Shopware",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://github.com/shopware/frontends.git"
|
|
9
9
|
},
|
|
10
|
-
"homepage": "https://
|
|
10
|
+
"homepage": "https://developer.shopware.com/frontends/packages/composables.html",
|
|
11
11
|
"keywords": [
|
|
12
12
|
"shopware",
|
|
13
13
|
"vue",
|
|
@@ -52,31 +52,30 @@
|
|
|
52
52
|
"app.config.ts"
|
|
53
53
|
],
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@vueuse/core": "14.
|
|
55
|
+
"@vueuse/core": "14.4.0",
|
|
56
56
|
"defu": "6.1.7",
|
|
57
57
|
"scule": "1.3.0",
|
|
58
|
-
"@shopware/helpers": "1.7.
|
|
59
|
-
"@shopware/api-client": "1.5.
|
|
58
|
+
"@shopware/helpers": "1.7.2",
|
|
59
|
+
"@shopware/api-client": "1.5.1"
|
|
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.10",
|
|
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.10",
|
|
70
|
+
"vue": "3.5.39",
|
|
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
|
|
|
@@ -14,6 +14,13 @@ export function createShopwareContext(
|
|
|
14
14
|
devStorefrontUrl?: string | null;
|
|
15
15
|
enableDevtools?: boolean;
|
|
16
16
|
browserLocale?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Opt in to reading data via cacheable GET Store API routes instead of
|
|
19
|
+
* POST. Surfaced on the Shopware context as `cacheableReads`.
|
|
20
|
+
*
|
|
21
|
+
* @default false
|
|
22
|
+
*/
|
|
23
|
+
cacheableReads?: boolean;
|
|
17
24
|
},
|
|
18
25
|
) {
|
|
19
26
|
const scope: EffectScope = effectScope(true);
|
|
@@ -36,6 +43,7 @@ export function createShopwareContext(
|
|
|
36
43
|
devStorefrontUrl: options.devStorefrontUrl,
|
|
37
44
|
state,
|
|
38
45
|
browserLocale: options.browserLocale || "en-US",
|
|
46
|
+
cacheableReads: options.cacheableReads ?? false,
|
|
39
47
|
});
|
|
40
48
|
|
|
41
49
|
if (options?.enableDevtools && typeof window !== "undefined") {
|