@shopware/composables 1.9.1 → 1.11.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.
Files changed (60) hide show
  1. package/README.md +12 -5
  2. package/dist/index.d.mts +116 -34
  3. package/dist/index.d.ts +116 -34
  4. package/dist/index.mjs +117 -74
  5. package/package.json +13 -12
  6. package/src/cms/cmsAssociations.ts +5 -1
  7. package/src/cms/useCmsElementConfig.test.ts +8 -0
  8. package/src/cms/useCmsElementConfig.ts +4 -1
  9. package/src/cms/useCmsElementImage.test.ts +23 -0
  10. package/src/cms/useCmsElementProductBox.test.ts +21 -0
  11. package/src/devtools/plugin.ts +1 -2
  12. package/src/mocks/Configurator.ts +36 -36
  13. package/src/types/cmsBlockTypes.ts +2 -0
  14. package/src/types/cmsElementTypes.ts +24 -18
  15. package/src/useAddToCart/useAddToCart.test.ts +18 -1
  16. package/src/useAddress/useAddress.test.ts +41 -2
  17. package/src/useAddress/useAddress.ts +1 -1
  18. package/src/useCart/useCart.test.ts +42 -0
  19. package/src/useCart/useCart.ts +17 -0
  20. package/src/useCartNotification/useCartNotification.test.ts +30 -0
  21. package/src/useCheckout/useCheckout.test.ts +43 -1
  22. package/src/useCmsMeta/useCmsMeta.test.ts +26 -0
  23. package/src/useCountries/useCountries.test.ts +14 -0
  24. package/src/useCustomerOrders/useCustomerOrders.ts +1 -1
  25. package/src/useDefaultOrderAssociations/useDefaultOrderAssociations.test.ts +19 -21
  26. package/src/useDefaultOrderAssociations/useDefaultOrderAssociations.ts +23 -30
  27. package/src/useLandingSearch/useLandingSearch.test.ts +1 -1
  28. package/src/useLandingSearch/useLandingSearch.ts +1 -1
  29. package/src/useListing/useListing.test.ts +73 -0
  30. package/src/useListing/useListing.ts +10 -3
  31. package/src/useLocalWishlist/useLocalWishlist.test.ts +44 -5
  32. package/src/useLocalWishlist/useLocalWishlist.ts +3 -2
  33. package/src/useNavigationContext/useNavigationContext.test.ts +25 -24
  34. package/src/useNewsletter/useNewsletter.test.ts +16 -0
  35. package/src/useNewsletter/useNewsletter.ts +13 -0
  36. package/src/useOrderDetails/useOrderDetails.test.ts +92 -3
  37. package/src/useOrderDetails/useOrderDetails.ts +12 -14
  38. package/src/useOrderPayment/useOrderPayment.test.ts +55 -1
  39. package/src/useOrderPayment/useOrderPayment.ts +1 -0
  40. package/src/usePrice/usePrice.test.ts +10 -0
  41. package/src/usePrice/usePrice.ts +2 -7
  42. package/src/useProduct/useProduct.test.ts +14 -1
  43. package/src/useProductAssociations/useProductAssociations.spec.ts +1 -0
  44. package/src/useProductConfigurator/useProductConfigurator.spec.ts +38 -0
  45. package/src/useProductConfigurator/useProductConfigurator.ts +1 -1
  46. package/src/useProductPrice/useProductPrice.test.ts +7 -7
  47. package/src/useProductPrice/useProductPrice.ts +12 -4
  48. package/src/useProductReviews/useProductReviews.test.ts +15 -3
  49. package/src/useProductWishlist/useProductWishlist.ts +2 -2
  50. package/src/useSalutations/useSalutations.spec.ts +13 -0
  51. package/src/useSessionContext/useSessionContext.test.ts +122 -4
  52. package/src/useSessionContext/useSessionContext.ts +14 -2
  53. package/src/useSyncWishlist/useSyncWishlist.test.ts +94 -25
  54. package/src/useSyncWishlist/useSyncWishlist.ts +27 -8
  55. package/src/useUrlResolver/useUrlResolver.test.ts +6 -12
  56. package/src/useUrlResolver/useUrlResolver.ts +4 -6
  57. package/src/useUser/useUser.test.ts +233 -18
  58. package/src/useUser/useUser.ts +6 -1
  59. package/src/useWishlist/useWishlist.test.ts +133 -26
  60. package/src/useWishlist/useWishlist.ts +22 -6
package/dist/index.mjs CHANGED
@@ -57,6 +57,9 @@ function useCmsElementImage(element) {
57
57
 
58
58
  function useCmsElementConfig(element) {
59
59
  const getConfigValue = (key) => {
60
+ if (!element?.config) {
61
+ return void 0;
62
+ }
60
63
  return element.config[key]?.source !== "mapped" && element.config[key]?.value;
61
64
  };
62
65
  return {
@@ -171,7 +174,7 @@ function useAddress() {
171
174
  }
172
175
  }
173
176
  return {
174
- customerAddresses: computed(() => _storeCustomerAddresses.value || []),
177
+ customerAddresses: computed(() => _storeCustomerAddresses.value),
175
178
  loadCustomerAddresses,
176
179
  createCustomerAddress,
177
180
  updateCustomerAddress,
@@ -292,6 +295,17 @@ function useCartFunction() {
292
295
  setCartErrors(data);
293
296
  return data;
294
297
  }
298
+ async function removeItemById(id) {
299
+ const { data } = await apiClient.invoke(
300
+ "removeLineItem post /checkout/cart/line-item/delete",
301
+ {
302
+ body: { ids: [id] }
303
+ }
304
+ );
305
+ _storeCart.value = data;
306
+ setCartErrors(data);
307
+ return data;
308
+ }
295
309
  async function changeProductQuantity(params) {
296
310
  const { data } = await apiClient.invoke(
297
311
  "updateLineItem patch /checkout/cart/line-item",
@@ -388,6 +402,7 @@ function useCartFunction() {
388
402
  count,
389
403
  refreshCart,
390
404
  removeItem,
405
+ removeItemById,
391
406
  totalPrice,
392
407
  shippingTotal,
393
408
  subtotal,
@@ -475,7 +490,11 @@ function useCategory(category) {
475
490
 
476
491
  const cmsAssociations = {
477
492
  associations: {
478
- media: {},
493
+ media: {
494
+ associations: {
495
+ media: {}
496
+ }
497
+ },
479
498
  cmsPage: {
480
499
  associations: {
481
500
  sections: {
@@ -786,31 +805,29 @@ function useCustomerPassword() {
786
805
 
787
806
  function useDefaultOrderAssociations() {
788
807
  const orderAssociations = {
789
- associations: {
790
- stateMachineState: {},
791
- lineItems: {
792
- associations: {
793
- cover: {},
794
- downloads: {
795
- associations: {
796
- media: {}
797
- }
808
+ stateMachineState: {},
809
+ lineItems: {
810
+ associations: {
811
+ cover: {},
812
+ downloads: {
813
+ associations: {
814
+ media: {}
798
815
  }
799
816
  }
800
- },
801
- addresses: {},
802
- deliveries: {
803
- associations: {
804
- shippingMethod: {},
805
- shippingOrderAddress: {},
806
- stateMachineState: {}
807
- }
808
- },
809
- transactions: {
810
- associations: {
811
- paymentMethod: {},
812
- stateMachineState: {}
813
- }
817
+ }
818
+ },
819
+ addresses: {},
820
+ deliveries: {
821
+ associations: {
822
+ shippingMethod: {},
823
+ shippingOrderAddress: {},
824
+ stateMachineState: {}
825
+ }
826
+ },
827
+ transactions: {
828
+ associations: {
829
+ paymentMethod: {},
830
+ stateMachineState: {}
814
831
  }
815
832
  }
816
833
  };
@@ -880,7 +897,7 @@ function useInternationalization(pathResolver) {
880
897
  function useLandingSearch() {
881
898
  const { apiClient } = useShopwareContext();
882
899
  const search = async (navigationId, options) => {
883
- const associations = options?.withCmsAssociations ? cmsAssociations : {};
900
+ const associations = options?.withCmsAssociations ? cmsAssociations.associations : {};
884
901
  const result = await apiClient.invoke(
885
902
  "readLandingPage post /landing-page/{landingPageId}",
886
903
  {
@@ -960,13 +977,17 @@ function useListing(params) {
960
977
  return createListingComposable({
961
978
  listingKey: listingType,
962
979
  searchMethod,
963
- searchDefaults: params?.defaultSearchCriteria || {}
980
+ searchDefaults: params?.defaultSearchCriteria || {},
964
981
  //getDefaults(),
982
+ initialListing: params?.initialListing
965
983
  });
966
984
  }
967
985
  const [_createCategoryListingContext, _categoryListingContext] = createInjectionState(
968
- () => {
969
- return useListing({ listingType: "categoryListing" });
986
+ (initialListing) => {
987
+ return useListing({
988
+ listingType: "categoryListing",
989
+ initialListing
990
+ });
970
991
  },
971
992
  {
972
993
  injectionKey: "categoryListing"
@@ -988,17 +1009,18 @@ const useProductSearchListing = createSharedComposable(
988
1009
  function createListingComposable({
989
1010
  searchMethod,
990
1011
  searchDefaults,
991
- listingKey
1012
+ listingKey,
1013
+ initialListing
992
1014
  }) {
993
1015
  const loading = ref(false);
994
1016
  const loadingMore = ref(false);
995
- const _storeInitialListing = inject(`useListingInitial-${listingKey}`, ref(null));
1017
+ const _storeInitialListing = inject(`useListingInitial-${listingKey}`, ref(initialListing ?? null));
996
1018
  provide(`useListingInitial-${listingKey}`, _storeInitialListing);
997
1019
  const _storeAppliedListing = inject(`useListingApplied-${listingKey}`, ref(null));
998
1020
  provide(`useListingApplied-${listingKey}`, _storeAppliedListing);
999
1021
  const getInitialListing = computed(() => _storeInitialListing.value);
1000
- const setInitialListing = async (initialListing) => {
1001
- _storeInitialListing.value = initialListing;
1022
+ const setInitialListing = async (initialListing2) => {
1023
+ _storeInitialListing.value = initialListing2;
1002
1024
  _storeAppliedListing.value = null;
1003
1025
  };
1004
1026
  const initSearch = async (criteria) => {
@@ -1198,8 +1220,10 @@ function useLocalWishlist() {
1198
1220
  );
1199
1221
  };
1200
1222
  const getFromStorage = () => {
1201
- if (typeof window !== "undefined" && localStorage) {
1223
+ try {
1202
1224
  return JSON.parse(localStorage.getItem("sw-wishlist-items") ?? "[]");
1225
+ } catch {
1226
+ return void 0;
1203
1227
  }
1204
1228
  };
1205
1229
  async function removeFromWishlist(id) {
@@ -1317,6 +1341,8 @@ function useNavigationSearch() {
1317
1341
  }
1318
1342
 
1319
1343
  function useNewsletter() {
1344
+ const SUBSCRIBE_KEY = "subscribe";
1345
+ const UNSUBSCRIBE_KEY = "unsubscribe";
1320
1346
  const { apiClient } = useShopwareContext();
1321
1347
  const { getStorefrontUrl } = useInternationalization();
1322
1348
  const newsletterStatus = ref("undefined");
@@ -1359,7 +1385,9 @@ function useNewsletter() {
1359
1385
  isNewsletterSubscriber,
1360
1386
  getNewsletterStatus,
1361
1387
  newsletterStatus,
1362
- confirmationNeeded
1388
+ confirmationNeeded,
1389
+ SUBSCRIBE_KEY,
1390
+ UNSUBSCRIBE_KEY
1363
1391
  };
1364
1392
  }
1365
1393
 
@@ -1376,7 +1404,7 @@ function useNotifications() {
1376
1404
  _notifications.value = [];
1377
1405
  }
1378
1406
  function geterateId() {
1379
- return +`${(/* @__PURE__ */ new Date()).getTime()}${Math.random() * 1e3}`;
1407
+ return +`${( new Date()).getTime()}${Math.random() * 1e3}`;
1380
1408
  }
1381
1409
  async function pushNotification(message, options) {
1382
1410
  const timeout = options.timeout || 2500;
@@ -1453,14 +1481,8 @@ function useOrderDetails(orderId, associations) {
1453
1481
  associations ? associations : {}
1454
1482
  );
1455
1483
  const params = {
1456
- filter: [
1457
- {
1458
- type: "equals",
1459
- field: "id",
1460
- value: orderId
1461
- }
1462
- ],
1463
- associations: mergedAssociations.associations,
1484
+ ids: [orderId],
1485
+ associations: mergedAssociations,
1464
1486
  checkPromotion: true
1465
1487
  };
1466
1488
  const orderDetailsResponse = await apiClient.invoke(
@@ -1531,7 +1553,8 @@ function useOrderDetails(orderId, associations) {
1531
1553
  pathParams: {
1532
1554
  documentId,
1533
1555
  deepLinkCode
1534
- }
1556
+ },
1557
+ accept: "application/pdf"
1535
1558
  }
1536
1559
  );
1537
1560
  return response.data;
@@ -1585,7 +1608,10 @@ function useOrderPayment(order) {
1585
1608
  const paymentUrl = ref();
1586
1609
  const state = computed(() => activeTransaction.value?.stateMachineState);
1587
1610
  const isAsynchronous = computed(
1588
- () => activeTransaction.value?.paymentMethod?.asynchronous && activeTransaction.value?.paymentMethod?.afterOrderEnabled
1611
+ () => (
1612
+ // @ts-expect-error TODO: [MAJOR] Removed since 6.7
1613
+ activeTransaction.value?.paymentMethod?.asynchronous && activeTransaction.value?.paymentMethod?.afterOrderEnabled
1614
+ )
1589
1615
  );
1590
1616
  async function handlePayment(finishUrl, errorUrl) {
1591
1617
  if (!order.value) {
@@ -1633,12 +1659,8 @@ function useOrderPayment(order) {
1633
1659
  function _usePrice(params) {
1634
1660
  const { sessionContext } = useSessionContext();
1635
1661
  const { browserLocale } = useShopwareContext();
1636
- const currencyLocale = ref(browserLocale);
1637
- const currencyCode = ref("");
1638
- if (params) {
1639
- currencyCode.value = params.currencyCode;
1640
- _setLocaleCode(params.localeCode);
1641
- }
1662
+ const currencyCode = ref(params?.currencyCode ?? "");
1663
+ const currencyLocale = ref(params?.localeCode || browserLocale);
1642
1664
  function update(params2) {
1643
1665
  _setCurrencyCode(params2.currencyCode);
1644
1666
  _setLocaleCode(params2.localeCode);
@@ -1847,7 +1869,7 @@ function useProductPrice(product) {
1847
1869
  const price = computed(
1848
1870
  () => _price.value
1849
1871
  );
1850
- const isListPrice = computed(() => {
1872
+ const hasListPrice = computed(() => {
1851
1873
  return !!_price.value?.listPrice?.percentage;
1852
1874
  });
1853
1875
  const regulationPrice = computed(
@@ -1862,7 +1884,9 @@ function useProductPrice(product) {
1862
1884
  displayFrom,
1863
1885
  tierPrices,
1864
1886
  referencePrice,
1865
- isListPrice,
1887
+ hasListPrice,
1888
+ /** @deprecated Use hasListPrice instead */
1889
+ isListPrice: hasListPrice,
1866
1890
  regulationPrice
1867
1891
  };
1868
1892
  }
@@ -2151,6 +2175,8 @@ function useSessionContext(newContext) {
2151
2175
  setLanguage,
2152
2176
  languageId,
2153
2177
  languageIdChain,
2178
+ salesChannelLanguageId: languageId,
2179
+ currentLanguageId: languageIdChain,
2154
2180
  setCountry,
2155
2181
  setContext
2156
2182
  };
@@ -2171,8 +2197,11 @@ function useShopwareContext() {
2171
2197
  }
2172
2198
 
2173
2199
  const _wishlistItems = ref([]);
2200
+ const _wishlistProducts = ref([]);
2174
2201
  const _currentPage = ref(1);
2202
+ const _limit = ref(15);
2175
2203
  const totalWishlistItemsCount = ref(0);
2204
+ const isLoading = ref(false);
2176
2205
  function useSyncWishlist() {
2177
2206
  const { apiClient } = useShopwareContext();
2178
2207
  async function addToWishlistSync(id) {
@@ -2200,13 +2229,15 @@ function useSyncWishlist() {
2200
2229
  _wishlistItems.value = [
2201
2230
  ...response.data.products.elements.map((element) => element.id)
2202
2231
  ];
2232
+ _wishlistProducts.value = response.data.products.elements;
2203
2233
  totalWishlistItemsCount.value = response.data.products.total ?? 0;
2204
2234
  _currentPage.value = response.data.products.page ?? 1;
2205
- } catch (e) {
2206
- if (e instanceof ApiClientError) {
2207
- if (e.status !== 404) console.error(e);
2208
- _wishlistItems.value = [];
2209
- }
2235
+ _limit.value = response.data.products.limit ?? 15;
2236
+ } catch (error) {
2237
+ console.error("[useSyncWishlist][getWishlistProducts][error]:", error);
2238
+ _wishlistItems.value = [];
2239
+ _wishlistProducts.value = [];
2240
+ totalWishlistItemsCount.value = 0;
2210
2241
  }
2211
2242
  }
2212
2243
  async function mergeWishlistProducts(productIds) {
@@ -2220,30 +2251,34 @@ function useSyncWishlist() {
2220
2251
  const items = computed(() => _wishlistItems.value);
2221
2252
  const count = computed(() => totalWishlistItemsCount.value);
2222
2253
  const currentPage = computed(() => _currentPage.value);
2254
+ const products = computed(() => _wishlistProducts.value);
2255
+ const limit = computed(() => _limit.value);
2223
2256
  return {
2224
2257
  getWishlistProducts,
2225
2258
  addToWishlistSync,
2226
2259
  removeFromWishlistSync,
2227
2260
  mergeWishlistProducts,
2261
+ products,
2228
2262
  items,
2229
2263
  count,
2230
- currentPage
2264
+ currentPage,
2265
+ isLoading,
2266
+ limit
2231
2267
  };
2232
2268
  }
2233
2269
 
2234
2270
  function useUrlResolver() {
2235
- const getUrlPrefix = () => inject("urlPrefix", "");
2271
+ const urlPrefix = inject("urlPrefix", "");
2272
+ const getUrlPrefix = () => urlPrefix;
2236
2273
  const resolveUrl = (url) => {
2237
2274
  if (url.length > 2083) {
2238
2275
  throw new Error("URL Input too long");
2239
2276
  }
2240
2277
  const navigationPattern = /[a-zA-Z0-9]+\/navigation\/[a-zA-Z0-9]+/;
2241
- const urlPrefix = getUrlPrefix();
2278
+ const prefix = getUrlPrefix();
2242
2279
  if (navigationPattern.test(url)) {
2243
2280
  const newUrl = url.split("/").slice(1);
2244
- if (newUrl.length > 0) {
2245
- return `${buildUrlPrefix(newUrl.join("/"), urlPrefix)}`;
2246
- }
2281
+ return buildUrlPrefix(newUrl.join("/"), prefix).path;
2247
2282
  }
2248
2283
  return url;
2249
2284
  };
@@ -2263,7 +2298,8 @@ function useUser() {
2263
2298
  const { getStorefrontUrl } = useInternationalization();
2264
2299
  const { refreshCart } = useCart();
2265
2300
  const userDefaultPaymentMethod = computed(
2266
- () => user.value?.defaultPaymentMethod?.translated || null
2301
+ () => user.value?.lastPaymentMethod?.translated || // @ts-expect-error TODO: [MAJOR] Removed since 6.7
2302
+ user.value?.defaultPaymentMethod?.translated || null
2267
2303
  );
2268
2304
  const userDefaultBillingAddress = computed(
2269
2305
  () => user.value?.defaultBillingAddress || null
@@ -2366,6 +2402,7 @@ function useUser() {
2366
2402
  }
2367
2403
  async function setDefaultPaymentMethod(paymentMethodId) {
2368
2404
  await apiClient.invoke(
2405
+ // @ts-expect-error TODO: [MAJOR] Removed since 6.7
2369
2406
  "changePaymentMethod post /account/change-payment-method/{paymentMethodId}",
2370
2407
  {
2371
2408
  pathParams: { paymentMethodId }
@@ -2425,19 +2462,23 @@ function useWishlist() {
2425
2462
  mergeWishlistProducts: mergeWishlistProductsSync,
2426
2463
  removeFromWishlistSync,
2427
2464
  count: countSync,
2428
- currentPage
2465
+ currentPage,
2466
+ products,
2467
+ limit: limitSync
2429
2468
  } = useSyncWishlist();
2430
2469
  const limit = ref(15);
2431
2470
  const getWishlistProducts = async (query) => {
2432
- const wishlistQuery = {};
2471
+ let wishlistQuery = {
2472
+ limit: limit.value
2473
+ };
2433
2474
  if (query) {
2434
- defu(wishlistQuery, query);
2435
- }
2436
- if (query?.limit) {
2437
- limit.value = query.limit;
2475
+ wishlistQuery = defu(query, wishlistQuery);
2476
+ if (query.limit) {
2477
+ limit.value = query.limit;
2478
+ }
2438
2479
  }
2439
2480
  if (canSyncWishlist.value) {
2440
- await getWishlistProductsSync(query);
2481
+ await getWishlistProductsSync(wishlistQuery);
2441
2482
  } else {
2442
2483
  getWishlistProductsLocal();
2443
2484
  }
@@ -2475,7 +2516,9 @@ function useWishlist() {
2475
2516
  currentPage,
2476
2517
  totalPagesCount,
2477
2518
  count,
2478
- canSyncWishlist
2519
+ canSyncWishlist,
2520
+ products,
2521
+ limit: limitSync
2479
2522
  };
2480
2523
  }
2481
2524
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopware/composables",
3
- "version": "1.9.1",
3
+ "version": "1.11.0",
4
4
  "description": "Shopware Frontends composables for Vue",
5
5
  "author": "Shopware",
6
6
  "repository": {
@@ -51,31 +51,32 @@
51
51
  "types"
52
52
  ],
53
53
  "dependencies": {
54
- "@vueuse/core": "13.3.0",
54
+ "@vueuse/core": "14.1.0",
55
55
  "defu": "6.1.4",
56
56
  "scule": "1.3.0",
57
- "@shopware/helpers": "1.5.0",
58
- "@shopware/api-client": "1.3.0"
57
+ "@shopware/helpers": "1.7.0",
58
+ "@shopware/api-client": "1.5.0"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@biomejs/biome": "1.8.3",
62
- "@nuxt/kit": "3.17.5",
63
- "@vitest/coverage-v8": "3.2.3",
62
+ "@nuxt/kit": "4.2.2",
63
+ "@typescript/native-preview": "7.0.0-dev.20260111.1",
64
+ "@vitest/coverage-v8": "4.0.18",
64
65
  "@vue/test-utils": "2.4.6",
65
- "happy-dom": "18.0.1",
66
- "typescript": "5.8.3",
66
+ "happy-dom": "20.8.9",
67
+ "typescript": "5.9.3",
67
68
  "unbuild": "2.0.0",
68
- "vitest": "3.2.3",
69
- "vue": "3.5.16",
69
+ "vitest": "4.0.18",
70
+ "vue": "3.5.27",
70
71
  "tsconfig": "0.0.0"
71
72
  },
72
73
  "scripts": {
73
74
  "build": "unbuild && pnpm build:types",
74
- "build:types": "npx -p typescript tsc",
75
+ "build:types": "tsgo",
75
76
  "dev": "unbuild --stub",
76
77
  "lint": "biome check .",
77
78
  "lint:fix": "biome check . --write && pnpm run typecheck",
78
- "typecheck": "tsc --noEmit",
79
+ "typecheck": "tsgo --noEmit",
79
80
  "test": "vitest run",
80
81
  "coverage": "vitest run --coverage",
81
82
  "test:watch": "vitest"
@@ -1,6 +1,10 @@
1
1
  export const cmsAssociations = {
2
2
  associations: {
3
- media: {},
3
+ media: {
4
+ associations: {
5
+ media: {},
6
+ },
7
+ },
4
8
  cmsPage: {
5
9
  associations: {
6
10
  sections: {
@@ -59,6 +59,14 @@ describe("useCmsElementConfig", () => {
59
59
  expect(getConfigValue("alignment")).toEqual("flex-start");
60
60
  });
61
61
 
62
+ it("should return undefined if element config is undefined", () => {
63
+ const { getConfigValue } = useCmsElementConfig({
64
+ config: undefined,
65
+ } as unknown as CmsElementBuyBox);
66
+
67
+ expect(getConfigValue("alignment")).toBeUndefined();
68
+ });
69
+
62
70
  it("should return undefined if config value is undefined", () => {
63
71
  const { getConfigValue } = useCmsElementConfig({
64
72
  config: {
@@ -7,7 +7,7 @@ import type { ElementConfig } from "../types";
7
7
  * @category CMS (Shopping Experiences)
8
8
  */
9
9
  export function useCmsElementConfig<
10
- T extends Schemas["CmsSlot"] & {
10
+ T extends Omit<Schemas["CmsSlot"], "config"> & {
11
11
  config: T["config"] extends {
12
12
  [key in infer X extends keyof T["config"]]: ElementConfig<unknown>;
13
13
  }
@@ -18,6 +18,9 @@ export function useCmsElementConfig<
18
18
  const getConfigValue = <ELEMENT_CONFIG extends keyof T["config"]>(
19
19
  key: ELEMENT_CONFIG,
20
20
  ): (typeof element.config)[ELEMENT_CONFIG]["value"] => {
21
+ if (!element?.config) {
22
+ return undefined as (typeof element.config)[ELEMENT_CONFIG]["value"];
23
+ }
21
24
  return (
22
25
  element.config[key]?.source !== "mapped" && element.config[key]?.value
23
26
  );
@@ -95,6 +95,29 @@ describe("useCmsElementImage", () => {
95
95
  });
96
96
  });
97
97
 
98
+ it("should return imageContainerAttrs without url", () => {
99
+ const { imageContainerAttrs } = useCmsElementImage({
100
+ data: {
101
+ newTab: false,
102
+ },
103
+ } as CmsElementImage);
104
+
105
+ expect(imageContainerAttrs.value).toEqual({});
106
+ });
107
+
108
+ it("should return imageContainerAttrs with url but no newTab", () => {
109
+ const { imageContainerAttrs } = useCmsElementImage({
110
+ data: {
111
+ url: "https://shopware.com/logo.png",
112
+ newTab: false,
113
+ },
114
+ } as CmsElementImage);
115
+
116
+ expect(imageContainerAttrs.value).toEqual({
117
+ href: "https://shopware.com/logo.png",
118
+ });
119
+ });
120
+
98
121
  it("should return imageLink", () => {
99
122
  const { imageLink } = useCmsElementImage({
100
123
  data: {
@@ -12,4 +12,25 @@ describe("useCmsElementProductBox", () => {
12
12
 
13
13
  expect(vm.product).toEqual(CmsProductBox.data.product);
14
14
  });
15
+
16
+ it("should use injected product when provided", () => {
17
+ const injectedProduct = { id: "injected-id", name: "Injected Product" };
18
+ const { vm } = useSetup(
19
+ () =>
20
+ useCmsElementProductBox(
21
+ CmsProductBox as unknown as CmsElementProductBox,
22
+ ),
23
+ { product: injectedProduct } as Parameters<typeof useSetup>[1],
24
+ );
25
+
26
+ expect(vm.product).toEqual(injectedProduct);
27
+ });
28
+
29
+ it("should return boxLayout from config", () => {
30
+ const { vm } = useSetup(() =>
31
+ useCmsElementProductBox(CmsProductBox as unknown as CmsElementProductBox),
32
+ );
33
+
34
+ expect(vm.boxLayout).toEqual("standard");
35
+ });
15
36
  });
@@ -1,6 +1,5 @@
1
1
  // TODO fix types in this plugin
2
2
  import { setupDevtoolsPlugin } from "@vue/devtools-api";
3
- import type { DevtoolsPluginApi } from "@vue/devtools-api";
4
3
  import { unref } from "vue";
5
4
  import type { App, InjectionKey } from "vue";
6
5
 
@@ -15,7 +14,7 @@ export function registerShopwareDevtools(
15
14
  shopwarePluginInstance: any,
16
15
  ) {
17
16
  // biome-ignore lint: not used plugin for now, ignoring type errors
18
- let devtoolsApi: DevtoolsPluginApi<any>;
17
+ let devtoolsApi: any;
19
18
  let trackId = 0;
20
19
  // biome-ignore lint: not used plugin for now, ignoring type errors
21
20
  let currentSharedState: any = null;