@teamnovu/kit-shopware-composables 0.0.12 → 0.0.14
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,5 +1,6 @@
|
|
|
1
|
-
import { Schemas
|
|
1
|
+
import { Schemas } from '../../query/types/operations';
|
|
2
2
|
import { ComputedRef, Ref } from 'vue';
|
|
3
|
+
import { BrandedSchema } from '../types/schema';
|
|
3
4
|
import { TierPrice } from '@shopware/helpers';
|
|
4
5
|
/**
|
|
5
6
|
* The purpose of the `useProductPrice` function is to abstract the logic
|
|
@@ -9,53 +10,13 @@ import { TierPrice } from '@shopware/helpers';
|
|
|
9
10
|
* @category Product
|
|
10
11
|
*/
|
|
11
12
|
export declare function useProductPrice(product: Ref<Schemas['Product'] | undefined>): {
|
|
12
|
-
price: ComputedRef<
|
|
13
|
-
apiAlias: "calculated_price";
|
|
14
|
-
calculatedTaxes: {
|
|
15
|
-
apiAlias: "cart_tax_calculated";
|
|
16
|
-
price: number;
|
|
17
|
-
tax: number;
|
|
18
|
-
taxRate: number;
|
|
19
|
-
}[];
|
|
20
|
-
hasRange: boolean;
|
|
21
|
-
listPrice: components["schemas"]["CartListPrice"] | null;
|
|
22
|
-
netPrice: number;
|
|
23
|
-
positionPrice: number;
|
|
24
|
-
quantity: number;
|
|
25
|
-
rawTotal: number;
|
|
26
|
-
referencePrice: components["schemas"]["CartPriceReference"] | null;
|
|
27
|
-
regulationPrice: {
|
|
28
|
-
apiAlias?: "cart_regulation_price";
|
|
29
|
-
price?: number;
|
|
30
|
-
} | null;
|
|
31
|
-
taxRules: {
|
|
32
|
-
name?: string;
|
|
33
|
-
taxRate?: number;
|
|
34
|
-
}[];
|
|
35
|
-
taxStatus: "net" | "tax-free";
|
|
36
|
-
totalPrice: number;
|
|
37
|
-
unitPrice: number;
|
|
38
|
-
variantId?: string | null;
|
|
39
|
-
} | undefined>;
|
|
13
|
+
price: ComputedRef<BrandedSchema<"CalculatedPrice"> | undefined>;
|
|
40
14
|
totalPrice: ComputedRef<number | undefined>;
|
|
41
15
|
unitPrice: ComputedRef<number | undefined>;
|
|
42
16
|
displayFromVariants: ComputedRef<number | false | undefined>;
|
|
43
17
|
displayFrom: ComputedRef<boolean>;
|
|
44
18
|
tierPrices: ComputedRef< TierPrice[]>;
|
|
45
|
-
referencePrice: ComputedRef<
|
|
46
|
-
apiAlias: "cart_price_reference";
|
|
47
|
-
hasRange: boolean;
|
|
48
|
-
listPrice: components["schemas"]["CartListPrice"] | null;
|
|
49
|
-
price?: number;
|
|
50
|
-
purchaseUnit?: number;
|
|
51
|
-
referenceUnit?: number;
|
|
52
|
-
regulationPrice: {
|
|
53
|
-
apiAlias?: "cart_regulation_price";
|
|
54
|
-
price?: number;
|
|
55
|
-
} | null;
|
|
56
|
-
unitName: string;
|
|
57
|
-
variantId?: string | null;
|
|
58
|
-
} | null | undefined>;
|
|
19
|
+
referencePrice: ComputedRef<BrandedSchema<"CartPriceReference"> | null | undefined>;
|
|
59
20
|
isListPrice: ComputedRef<boolean>;
|
|
60
21
|
regulationPrice: ComputedRef<number | undefined>;
|
|
61
22
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Schemas
|
|
1
|
+
import { Schemas } from '../../query/types/operations';
|
|
2
2
|
import { MaybeRef, ComputedRef } from 'vue';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { components, GenericRecord } from '../../../api-types/storeApiTypes';
|
|
4
|
+
type DetailProduct = Schemas['CustomProductDetailResponse']['product'];
|
|
5
|
+
export declare function getProductVariantForOptions<S extends DetailProduct>(product: S, optionIds: string[]): {
|
|
5
6
|
active?: boolean;
|
|
6
7
|
apiAlias: "product";
|
|
7
8
|
readonly available?: boolean;
|
|
@@ -137,7 +138,7 @@ export declare function getProductVariantForOptions<S extends Schemas>(product:
|
|
|
137
138
|
weight?: number;
|
|
138
139
|
width?: number;
|
|
139
140
|
} | undefined;
|
|
140
|
-
export declare function useProductVariantForOptions<S extends
|
|
141
|
+
export declare function useProductVariantForOptions<S extends DetailProduct>(product: MaybeRef<S>, optionIds: MaybeRef<string[]>): ComputedRef<{
|
|
141
142
|
active?: boolean;
|
|
142
143
|
apiAlias: "product";
|
|
143
144
|
readonly available?: boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teamnovu/kit-shopware-composables",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"description": "A collection of composables for the Shopware API",
|
|
5
5
|
"main": "dist/index.mjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"peerDependencies": {
|
|
18
18
|
"@tanstack/vue-query": "^5.85.3",
|
|
19
19
|
"vue": "^3.0.0",
|
|
20
|
-
"@teamnovu/kit-shopware-api-client": "0.0.
|
|
20
|
+
"@teamnovu/kit-shopware-api-client": "0.0.11"
|
|
21
21
|
},
|
|
22
22
|
"repository": {
|
|
23
23
|
"type": "git",
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
* https://github.com/shopware/frontends/blob/main/packages/composables/src/useProductPrice/useProductPrice.ts
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import type { Schemas } from '
|
|
6
|
+
import type { Schemas } from '../../query/types/operations'
|
|
7
7
|
import { getProductTierPrices } from '@shopware/helpers'
|
|
8
8
|
import type { ComputedRef, Ref } from 'vue'
|
|
9
9
|
import { computed } from 'vue'
|
|
10
|
+
import type { BrandedSchema } from '../types/schema'
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* The purpose of the `useProductPrice` function is to abstract the logic
|
|
@@ -19,20 +20,20 @@ export function useProductPrice(
|
|
|
19
20
|
product: Ref<Schemas['Product'] | undefined>,
|
|
20
21
|
) {
|
|
21
22
|
const _cheapest: ComputedRef<
|
|
22
|
-
|
|
23
|
+
BrandedSchema<'Product'>['calculatedCheapestPrice'] | undefined
|
|
23
24
|
> = computed(() => product.value?.calculatedCheapestPrice)
|
|
24
25
|
|
|
25
26
|
/**
|
|
26
27
|
* calculatedPrices are used for product with tier prices
|
|
27
28
|
*/
|
|
28
|
-
const _real: ComputedRef<
|
|
29
|
+
const _real: ComputedRef<BrandedSchema<'CalculatedPrice'> | undefined> = computed(
|
|
29
30
|
() =>
|
|
30
31
|
(product.value?.calculatedPrices?.length ?? 0) > 0
|
|
31
32
|
? product.value?.calculatedPrices?.[0]
|
|
32
33
|
: product.value?.calculatedPrice,
|
|
33
34
|
)
|
|
34
35
|
const referencePrice: ComputedRef<
|
|
35
|
-
|
|
36
|
+
BrandedSchema<'CartPriceReference'> | null | undefined
|
|
36
37
|
> = computed(() => _real?.value?.referencePrice)
|
|
37
38
|
|
|
38
39
|
const displayFrom: ComputedRef<boolean> = computed(() => {
|
|
@@ -50,7 +51,7 @@ export function useProductPrice(
|
|
|
50
51
|
},
|
|
51
52
|
)
|
|
52
53
|
|
|
53
|
-
const _price: ComputedRef<
|
|
54
|
+
const _price: ComputedRef<BrandedSchema<'CalculatedPrice'> | undefined> = computed(
|
|
54
55
|
() => {
|
|
55
56
|
if (displayFrom.value && getProductTierPrices(product.value).length > 1) {
|
|
56
57
|
return product.value?.calculatedPrices?.reduce((previous, current) => {
|
|
@@ -67,7 +68,7 @@ export function useProductPrice(
|
|
|
67
68
|
const totalPrice: ComputedRef<number | undefined> = computed(
|
|
68
69
|
() => _price.value?.totalPrice,
|
|
69
70
|
)
|
|
70
|
-
const price: ComputedRef<
|
|
71
|
+
const price: ComputedRef<BrandedSchema<'CalculatedPrice'> | undefined> = computed(
|
|
71
72
|
() => _price.value,
|
|
72
73
|
)
|
|
73
74
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { Schemas } from '
|
|
1
|
+
import type { Schemas } from '../../query/types/operations'
|
|
2
2
|
import type { MaybeRef } from 'vue'
|
|
3
3
|
import { computed, unref } from 'vue'
|
|
4
4
|
|
|
5
|
-
type DetailProduct
|
|
5
|
+
type DetailProduct = Schemas['CustomProductDetailResponse']['product']
|
|
6
6
|
|
|
7
|
-
export function getProductVariantForOptions<S extends
|
|
8
|
-
product:
|
|
7
|
+
export function getProductVariantForOptions<S extends DetailProduct>(
|
|
8
|
+
product: S,
|
|
9
9
|
optionIds: string[],
|
|
10
10
|
) {
|
|
11
11
|
const variants = product.extensions?.variants
|
|
@@ -19,8 +19,8 @@ export function getProductVariantForOptions<S extends Schemas>(
|
|
|
19
19
|
return variants?.find(v => v.optionIds?.every(optId => optionIds.includes(optId)))
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export function useProductVariantForOptions<S extends
|
|
23
|
-
product: MaybeRef<
|
|
22
|
+
export function useProductVariantForOptions<S extends DetailProduct>(
|
|
23
|
+
product: MaybeRef<S>,
|
|
24
24
|
optionIds: MaybeRef<string[]>,
|
|
25
25
|
) {
|
|
26
26
|
return computed(() => getProductVariantForOptions(unref(product), unref(optionIds)))
|