@scayle/storefront-product-detail 0.3.0 → 0.4.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.
@@ -8,6 +8,7 @@ interface ProductInfo {
8
8
  brand: string;
9
9
  productDescription: string;
10
10
  variants: Variant[];
11
+ images: string[];
11
12
  }
12
13
  export interface UseProductSeoDataReturn {
13
14
  title: ComputedRef<string>;
@@ -21,12 +22,12 @@ export interface UseProductSeoDataReturn {
21
22
  *
22
23
  * @param {MaybeRefOrGetter<BreadcrumbItem[]>} breadcrumbs - Array of breadcrumb items representing the navigation path to the product.
23
24
  * @param {MaybeRefOrGetter<UrlParams>} urlParams - Object containing baseUrl and fullPath to build and sanitize canonicalUrl.
24
- * @param {MaybeRefOrGetter<string[]>} images - Array of image URLs for the product.
25
25
  * @param {MaybeRefOrGetter<ProductInfo>} productInfo - Object containing product information including name, brand, description, and variants.
26
26
  * @property {string} name - The name of the product.
27
27
  * @property {string} brand - The brand of the product.
28
28
  * @property {string} productDescription - A description of the product.
29
29
  * @property {Variant[]} variants - Array of product variants.
30
+ * @property {string[]} images - Array of image URLs for the product.
30
31
  *
31
32
  * @returns {UseProductSeoDataReturn} An object containing SEO data for the product page with following properties:
32
33
  * @property {string} robots - Robots meta tag value, typically "index, follow".
@@ -35,5 +36,5 @@ export interface UseProductSeoDataReturn {
35
36
  * @property {ComputedRef<WithContext<Product>>} productJsonLd - Computed ref containing JSON-LD structured data for the product.
36
37
  * @property {ComputedRef<WithContext<BreadcrumbList>>} productBreadcrumbJsonLd - Computed ref containing JSON-LD structured data for product breadcrumbs.
37
38
  */
38
- export declare function useProductSeoData(breadcrumbs: MaybeRefOrGetter<BreadcrumbItem[]>, urlParams: MaybeRefOrGetter<UrlParams>, images: MaybeRefOrGetter<string[]>, productInfo: MaybeRefOrGetter<ProductInfo>): UseProductSeoDataReturn;
39
+ export declare function useProductSeoData(breadcrumbs: MaybeRefOrGetter<BreadcrumbItem[]>, urlParams: MaybeRefOrGetter<UrlParams>, productInfo: MaybeRefOrGetter<ProductInfo>): UseProductSeoDataReturn;
39
40
  export {};
@@ -4,7 +4,7 @@ import {
4
4
  sanitizeCanonicalURL
5
5
  } from "@scayle/storefront-nuxt";
6
6
  import { generateProductSchema } from "../utils/seo.js";
7
- export function useProductSeoData(breadcrumbs, urlParams, images, productInfo) {
7
+ export function useProductSeoData(breadcrumbs, urlParams, productInfo) {
8
8
  const canonicalUrl = computed(() => {
9
9
  const url = `${toValue(urlParams).baseUrl}${toValue(urlParams).fullPath}`;
10
10
  return sanitizeCanonicalURL(url, []);
@@ -15,11 +15,11 @@ export function useProductSeoData(breadcrumbs, urlParams, images, productInfo) {
15
15
  const robots = "index, follow";
16
16
  const productJsonLd = computed(() => {
17
17
  return generateProductSchema({
18
- productName: toValue(productInfo).name || "",
19
- brandName: toValue(productInfo).brand || "",
18
+ productName: toValue(productInfo).name,
19
+ brandName: toValue(productInfo).brand,
20
20
  url: canonicalUrl.value,
21
- variants: toValue(productInfo).variants || [],
22
- images: toValue(images),
21
+ variants: toValue(productInfo).variants,
22
+ images: toValue(productInfo).images,
23
23
  description: toValue(productInfo).productDescription
24
24
  });
25
25
  });
@@ -13,12 +13,12 @@ describe("useProductSeoData", () => {
13
13
  } = useProductSeoData(
14
14
  [{ value: "value", to: "/" }],
15
15
  { baseUrl: "baseUrl", fullPath: "fullPath" },
16
- [],
17
16
  {
18
17
  name: "name",
19
18
  variants: [variantFactory.build({ id: 1 })],
20
19
  brand: "brand",
21
- productDescription: "description"
20
+ productDescription: "description",
21
+ images: []
22
22
  }
23
23
  );
24
24
  expect(title.value).toBe("name");
@@ -73,7 +73,8 @@ describe("useProductSeoData", () => {
73
73
  name: "name",
74
74
  variants: [variantFactory.build({ id: 1 })],
75
75
  brand: "brand",
76
- productDescription: "description"
76
+ productDescription: "description",
77
+ images: []
77
78
  });
78
79
  const {
79
80
  title,
@@ -83,7 +84,6 @@ describe("useProductSeoData", () => {
83
84
  } = useProductSeoData(
84
85
  breadcrubs,
85
86
  urlParams,
86
- [],
87
87
  productInfo
88
88
  );
89
89
  expect(title.value).toBe("name");
@@ -1,2 +1,22 @@
1
1
  import type { Attributes } from '@scayle/storefront-nuxt';
2
- export declare const getFilteredAttributeGroups: (attributes: Attributes, filterTypes: string[]) => Map<string, string[]>;
2
+ /**
3
+ * Filters and formats attribute groups based on specified types.
4
+ *
5
+ * @param {Attributes} attributes - The object containing attribute groups, where each key maps to an attribute group.
6
+ * @param {string[]} filterTypes - An array of attribute types to include in the filtered results.
7
+ * @param {string[]} [singleValueType] - An array of attribute types that should have simplified formatting for their values. Default includes 'extras'.
8
+ * @returns {Map<string, string[]>} A map where the keys are attribute types and the values are arrays of formatted labels.
9
+ *
10
+ * @example
11
+ * const attributes = {
12
+ * color: { type: 'color', values: [{ label: 'Red' }, { label: 'Blue' }] },
13
+ * size: { type: 'size', values: [{ label: 'S' }, { label: 'M' }] },
14
+ * };
15
+ * const filterTypes = ['color', 'size'];
16
+ * const result = getFilteredAttributeGroups(attributes, filterTypes);
17
+ * // Result: Map {
18
+ * // 'color' => ['Red', 'Blue'],
19
+ * // 'size' => ['S', 'M']
20
+ * // }
21
+ */
22
+ export declare const getFilteredAttributeGroups: (attributes: Attributes, filterTypes: string[], singleValueType?: string[]) => Map<string, string[]>;
@@ -1,18 +1,18 @@
1
- const getFormattedLabel = (attributeGroup) => {
1
+ const getFormattedLabel = (attributeGroup, singleValueType) => {
2
2
  if (!attributeGroup) {
3
3
  return [];
4
4
  }
5
5
  const attributeGroupValues = Array.isArray(attributeGroup.values) ? attributeGroup.values : [attributeGroup.values];
6
6
  return attributeGroupValues.map(
7
- (value) => attributeGroup.type === "extras" ? value.label : `${attributeGroup.label}: ${value.label}`
7
+ (value) => attributeGroup.type && singleValueType.includes(attributeGroup.type) ? value.label : `${attributeGroup.label}: ${value.label}`
8
8
  );
9
9
  };
10
- export const getFilteredAttributeGroups = (attributes, filterTypes) => {
10
+ export const getFilteredAttributeGroups = (attributes, filterTypes, singleValueType = ["extras"]) => {
11
11
  return Object.values(attributes).filter(
12
12
  (attribute) => attribute?.type && filterTypes.includes(attribute.type)
13
13
  ).reduce((map, attributeValue) => {
14
14
  const key = attributeValue?.type || "";
15
- const value = getFormattedLabel(attributeValue);
15
+ const value = getFormattedLabel(attributeValue, singleValueType);
16
16
  map.set(key, (map.get(key) || []).concat(value));
17
17
  return map;
18
18
  }, /* @__PURE__ */ new Map());
@@ -1,2 +1,66 @@
1
1
  import { type AdvancedAttribute } from '@scayle/storefront-nuxt';
2
+ /**
3
+ * Extracts and returns an array of product IDs from an advanced attribute.
4
+ *
5
+ * This function processes an `AdvancedAttribute` object, extracts its values,
6
+ * parses them as integers, and filters out any invalid values. It is
7
+ * commonly used to handle product recommendations.
8
+ *
9
+ * @param {AdvancedAttribute} [attribute] - The advanced attribute containing values to extract product IDs from. This attribute is sourced from a product's advanced attributes.
10
+ * @returns {number[]} An array of valid product IDs extracted from the attribute values. Returns an empty array if the input is undefined or invalid.
11
+ *
12
+ * @example
13
+ * // Example usage within a Vue.js/Nuxt computed property
14
+ * const recommendedProductIds = computed(() => {
15
+ * return getCombineWithProductIds(
16
+ * product.value?.advancedAttributes?.['combineWith'],
17
+ * );
18
+ * });
19
+ *
20
+ * // Result: If 'combineWith' object built like:
21
+ * {
22
+ * "id": 7394,
23
+ * "key": "combineWith",
24
+ * "label": "Kombiniere mit",
25
+ * "type": "",
26
+ * "values": [
27
+ * {
28
+ * "fieldSet": [
29
+ * [
30
+ * {
31
+ * "value": "206131"
32
+ * }
33
+ * ]
34
+ * ],
35
+ * "groupSet": []
36
+ * },
37
+ * {
38
+ * "fieldSet": [
39
+ * [
40
+ * {
41
+ * "value": "206017"
42
+ * }
43
+ * ]
44
+ * ],
45
+ * "groupSet": []
46
+ * },
47
+ * {
48
+ * "fieldSet": [
49
+ * [
50
+ * {
51
+ * "value": "206012"
52
+ * }
53
+ * ]
54
+ * ],
55
+ * "groupSet": []
56
+ * }
57
+ * ]
58
+ * }
59
+ *
60
+ * // Then: recommendedProductIds.value => [ 206131, 206017, 206012 ]
61
+ *
62
+ * More information about recommended products and attributes groups please visit our SCAYLE Resource Center:
63
+ * https://scayle.dev/en/storefront-guide/developer-guide/features/product-recommendation
64
+ * https://scayle.dev/en/user-guide/settings/product-structure/attribute-groups
65
+ */
2
66
  export declare const getCombineWithProductIds: (attribute?: AdvancedAttribute) => number[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/storefront-product-detail",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Collection of essential composables and utilities to work with product detail",
5
5
  "author": "SCAYLE Commerce Engine",
6
6
  "license": "MIT",
@@ -50,9 +50,9 @@
50
50
  "@nuxt/kit": "3.13.2",
51
51
  "@nuxt/module-builder": "0.8.4",
52
52
  "@nuxt/schema": "3.13.2",
53
- "@nuxt/test-utils": "3.14.4",
53
+ "@nuxt/test-utils": "3.15.1",
54
54
  "@scayle/eslint-config-storefront": "4.3.2",
55
- "@scayle/storefront-nuxt": "8.0.0",
55
+ "@scayle/storefront-nuxt": "8.1.1",
56
56
  "@types/node": "22.10.1",
57
57
  "@vue/test-utils": "2.4.6",
58
58
  "@vueuse/core": "12.0.0",