@shopware/composables 1.8.1 → 1.9.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.
@@ -1,7 +1,7 @@
1
1
  import { createSharedComposable } from "@vueuse/core";
2
2
  import { computed, ref, watch } from "vue";
3
3
  import type { ComputedRef } from "vue";
4
- import { useSessionContext } from "#imports";
4
+ import { useSessionContext, useShopwareContext } from "#imports";
5
5
 
6
6
  export type UsePriceReturn = {
7
7
  /**
@@ -12,13 +12,17 @@ export type UsePriceReturn = {
12
12
  * Update configuration
13
13
  */
14
14
  update(params: {
15
- localeCode: string | undefined;
15
+ localeCode?: string | undefined;
16
16
  currencyCode: string;
17
17
  }): void;
18
18
  /**
19
19
  * Currency code
20
20
  */
21
21
  currencyCode: ComputedRef<string>;
22
+ /**
23
+ * Currency locale
24
+ */
25
+ currencyLocale: ComputedRef<string>;
22
26
  };
23
27
 
24
28
  /**
@@ -29,16 +33,17 @@ export type UsePriceReturn = {
29
33
  * @category Product
30
34
  */
31
35
  function _usePrice(params?: {
32
- localeCode: string | undefined;
36
+ localeCode?: string | undefined;
33
37
  currencyCode: string;
34
38
  }): UsePriceReturn {
35
39
  const { sessionContext } = useSessionContext();
36
- const currencyLocale = ref<string | undefined>();
40
+ const { browserLocale } = useShopwareContext();
41
+ const currencyLocale = ref<string>(browserLocale);
37
42
  const currencyCode = ref<string>("");
38
43
 
39
44
  if (params) {
40
45
  currencyCode.value = params.currencyCode;
41
- currencyLocale.value = params.localeCode;
46
+ _setLocaleCode(params.localeCode);
42
47
  }
43
48
 
44
49
  function update(params: {
@@ -46,20 +51,15 @@ function _usePrice(params?: {
46
51
  currencyCode: string;
47
52
  }) {
48
53
  _setCurrencyCode(params.currencyCode);
49
- _setLocaleCode(
50
- params.localeCode ||
51
- currencyLocale.value ||
52
- (typeof navigator !== "undefined" && navigator?.language) ||
53
- "en-US",
54
- );
54
+ _setLocaleCode(params.localeCode);
55
55
  }
56
56
 
57
57
  function _setCurrencyCode(code: string) {
58
58
  currencyCode.value = code;
59
59
  }
60
60
 
61
- function _setLocaleCode(locale: string) {
62
- currencyLocale.value = locale;
61
+ function _setLocaleCode(locale: string | undefined) {
62
+ currencyLocale.value = locale || currencyLocale.value;
63
63
  }
64
64
 
65
65
  /**
@@ -70,10 +70,9 @@ function _usePrice(params?: {
70
70
  return "";
71
71
  }
72
72
 
73
- if (!currencyLocale.value) {
73
+ if (!currencyLocale.value || !currencyCode.value) {
74
74
  return value.toString();
75
75
  }
76
-
77
76
  return new Intl.NumberFormat(currencyLocale.value, {
78
77
  style: "currency",
79
78
  currency: currencyCode.value,
@@ -98,6 +97,7 @@ function _usePrice(params?: {
98
97
  getFormattedPrice,
99
98
  update,
100
99
  currencyCode: computed(() => currencyCode.value),
100
+ currencyLocale: computed(() => currencyLocale.value),
101
101
  };
102
102
  }
103
103
  /**
@@ -107,6 +107,7 @@ export function useProductConfigurator(): UseProductConfiguratorReturn {
107
107
  return response.data.elements?.[0]; // return first matching product
108
108
  } catch (e) {
109
109
  console.error("SwProductDetails:findVariantForSelectedOptions", e);
110
+ return undefined;
110
111
  }
111
112
  }
112
113
 
@@ -37,7 +37,7 @@ describe("useProductPrice", () => {
37
37
  productTierPrices.product.calculatedPrices[2],
38
38
  );
39
39
  expect(vm.referencePrice).toStrictEqual(
40
- productTierPrices.product.calculatedPrices[0].referencePrice,
40
+ productTierPrices.product.calculatedPrices?.[0]?.referencePrice,
41
41
  );
42
42
  expect(vm.displayFrom).toBe(true);
43
43
  expect(vm.displayFromVariants).toBe(20);
@@ -8,6 +8,11 @@ export type ShopwareContext = {
8
8
  * Shopware API client
9
9
  */
10
10
  apiClient: ApiClient;
11
+ /**
12
+ * Browser locale, working in SSR
13
+ * If not provided, it will be "en-US"
14
+ */
15
+ browserLocale: string;
11
16
  };
12
17
 
13
18
  /**
@@ -27,5 +32,6 @@ export function useShopwareContext(): ShopwareContext {
27
32
  return {
28
33
  apiClient,
29
34
  devStorefrontUrl: shopwareContext.devStorefrontUrl,
35
+ browserLocale: shopwareContext.browserLocale || "en-US",
30
36
  };
31
37
  }
@@ -100,6 +100,8 @@ export type UseUserReturn = {
100
100
  updateEmailData: operations["changeEmail post /account/change-email"]["body"],
101
101
  ): Promise<void>;
102
102
  /**
103
+ * @deprecated API endpoint is removed in Shopware 6.7
104
+ *
103
105
  * Sets the default payment method for given id
104
106
  * @param paymentMethodId
105
107
  * @returns
@@ -281,6 +283,7 @@ export function useUser(): UseUserReturn {
281
283
  },
282
284
  );
283
285
  }
286
+
284
287
  const defaultBillingAddressId = computed(
285
288
  () => user.value?.defaultBillingAddressId || null,
286
289
  );
@@ -307,7 +310,6 @@ export function useUser(): UseUserReturn {
307
310
  logout,
308
311
  updateEmail,
309
312
  updatePersonalInfo,
310
- setDefaultPaymentMethod,
311
313
  loadSalutation,
312
314
  salutation,
313
315
  loadCountry,
@@ -316,6 +318,7 @@ export function useUser(): UseUserReturn {
316
318
  defaultShippingAddressId,
317
319
  userDefaultPaymentMethod,
318
320
  userDefaultBillingAddress,
321
+ setDefaultPaymentMethod,
319
322
  userDefaultShippingAddress,
320
323
  };
321
324
  }