@scayle/storefront-nuxt 8.25.5 → 8.26.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/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # @scayle/storefront-nuxt
2
2
 
3
+ ## 8.26.0
4
+
5
+ ### Minor Changes
6
+
7
+ - **\[Utilities\]** Added `useProductPrice` composable to simplify accessing price data like total price, strike-through prices, and applied reductions.
8
+
9
+ ### Patch Changes
10
+
11
+ **Dependencies**
12
+
13
+ **@scayle/storefront-core v8.26.0**
14
+
15
+ - No changes in this release.
16
+
17
+ ## 8.25.6
18
+
19
+ ### Patch Changes
20
+
21
+ **Dependencies**
22
+
23
+ **@scayle/storefront-core v8.25.6**
24
+
25
+ - No changes in this release.
26
+
3
27
  ## 8.25.5
4
28
 
5
29
  ### Patch Changes
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/storefront-nuxt",
3
- "version": "8.25.5",
3
+ "version": "8.26.0",
4
4
  "configKey": "storefront",
5
5
  "compatibility": {
6
6
  "nuxt": "^3.9.0"
package/dist/module.mjs CHANGED
@@ -54,7 +54,7 @@ export default {
54
54
  }`;
55
55
  }
56
56
  const PACKAGE_NAME = "@scayle/storefront-nuxt";
57
- const PACKAGE_VERSION = "8.25.5";
57
+ const PACKAGE_VERSION = "8.26.0";
58
58
  const logger = createConsola({
59
59
  fancy: true,
60
60
  formatOptions: {
@@ -387,6 +387,7 @@ const module = defineNuxtModule({
387
387
  });
388
388
  addImportsDir(resolve("runtime/composables/storefront"));
389
389
  addImportsDir(resolve("runtime/composables/core"));
390
+ addImportsDir(resolve("runtime/composables"));
390
391
  addImportsDir(resolve("runtime/utils"));
391
392
  const keyedComposables = [
392
393
  "useBrand",
@@ -31,3 +31,4 @@ export * from './storefront/useStorefrontSearch.js';
31
31
  export * from './storefront/useUserAddresses.js';
32
32
  export * from './storefront/useVariant.js';
33
33
  export * from './storefront/useWishlist.js';
34
+ export * from './useProductPrice.js';
@@ -31,3 +31,4 @@ export * from "./storefront/useStorefrontSearch.js";
31
31
  export * from "./storefront/useUserAddresses.js";
32
32
  export * from "./storefront/useVariant.js";
33
33
  export * from "./storefront/useWishlist.js";
34
+ export * from "./useProductPrice.js";
@@ -0,0 +1,26 @@
1
+ import type { ComputedRef, MaybeRefOrGetter } from 'vue';
2
+ import type { AppliedReduction, BasketItem, CentAmount, OrderItem, Price } from '@scayle/storefront-core';
3
+ type RelativeReductions = {
4
+ value: number;
5
+ category: 'promotion' | 'sale' | 'campaign' | 'voucher';
6
+ };
7
+ export type BasketItemPrice = BasketItem['price']['total'];
8
+ export type OrderPrice = OrderItem['price'];
9
+ export interface UseProductPriceReturn {
10
+ /** Ordered applied reductions. The first applied reduction will be in the first position of the array. */
11
+ appliedReductions: ComputedRef<AppliedReduction[]>;
12
+ /** Strike through prices, calculated by adding the reduction prices to the original price. */
13
+ strikeThroughPrices: ComputedRef<CentAmount[]>;
14
+ /** Reductions representing the relative amount and their respective categories. */
15
+ relativeReductions: ComputedRef<RelativeReductions[]>;
16
+ /** Total price with tax. */
17
+ totalPrice: ComputedRef<CentAmount>;
18
+ }
19
+ /**
20
+ * Composable for extracted product price data.
21
+ *
22
+ * @param price - Product or basket item price object containing all price relevant data.
23
+ * @returns An {@link UseProductPriceReturn} object containing product price reactive data.
24
+ */
25
+ export declare function useProductPrice(price: MaybeRefOrGetter<Price | BasketItemPrice | OrderPrice>): UseProductPriceReturn;
26
+ export {};
@@ -0,0 +1,36 @@
1
+ import { computed, toValue } from "vue";
2
+ export function useProductPrice(price) {
3
+ const appliedReductions = computed(() => {
4
+ const reductions = toValue(price).appliedReductions ?? [];
5
+ return reductions.toReversed();
6
+ });
7
+ const strikeThroughPrices = computed(() => {
8
+ return appliedReductions.value.reduce(
9
+ ({ prices, currentPrice }, { amount }) => {
10
+ currentPrice += amount.absoluteWithTax;
11
+ return {
12
+ currentPrice,
13
+ prices: [...prices, currentPrice]
14
+ };
15
+ },
16
+ {
17
+ prices: [],
18
+ currentPrice: toValue(price).withTax
19
+ }
20
+ ).prices;
21
+ });
22
+ const relativeReductions = computed(
23
+ () => appliedReductions.value.map(({ amount, category }) => {
24
+ return { value: Math.round(amount.relative * 100), category };
25
+ })
26
+ );
27
+ const totalPrice = computed(() => {
28
+ return toValue(price).withTax;
29
+ });
30
+ return {
31
+ appliedReductions,
32
+ strikeThroughPrices,
33
+ relativeReductions,
34
+ totalPrice
35
+ };
36
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@scayle/storefront-nuxt",
3
3
  "type": "module",
4
- "version": "8.25.5",
4
+ "version": "8.26.0",
5
5
  "description": "Nuxt integration for the SCAYLE Commerce Engine and Storefront API",
6
6
  "author": "SCAYLE Commerce Engine",
7
7
  "license": "MIT",
@@ -81,7 +81,7 @@
81
81
  "dependencies": {
82
82
  "@opentelemetry/api": "^1.9.0",
83
83
  "@scayle/h3-session": "0.6.1",
84
- "@scayle/storefront-core": "8.25.5",
84
+ "@scayle/storefront-core": "8.26.0",
85
85
  "@scayle/unstorage-compression-driver": "^0.2.7",
86
86
  "@vercel/nft": "0.29.3",
87
87
  "@vueuse/core": "13.2.0",
@@ -102,18 +102,18 @@
102
102
  "devDependencies": {
103
103
  "@arethetypeswrong/cli": "0.18.1",
104
104
  "@eslint/eslintrc": "3.3.1",
105
- "@nuxt/eslint": "1.3.1",
105
+ "@nuxt/eslint": "1.4.0",
106
106
  "@nuxt/kit": "3.16.2",
107
107
  "@nuxt/module-builder": "1.0.1",
108
108
  "@nuxt/schema": "3.16.2",
109
- "@nuxt/test-utils": "3.18.0",
109
+ "@nuxt/test-utils": "3.19.0",
110
110
  "@scayle/eslint-config-storefront": "4.5.2",
111
111
  "@scayle/eslint-plugin-vue-composable": "0.2.1",
112
112
  "@scayle/unstorage-scayle-kv-driver": "0.1.2",
113
113
  "@types/node": "22.15.18",
114
114
  "dprint": "0.49.1",
115
115
  "eslint-formatter-gitlab": "6.0.0",
116
- "eslint": "9.26.0",
116
+ "eslint": "9.27.0",
117
117
  "fishery": "2.3.1",
118
118
  "h3": "1.15.3",
119
119
  "nitropack": "2.11.12",