@dylandepass/helix-product-pipeline 1.2.0 → 1.2.2
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 +14 -0
- package/package.json +1 -1
- package/src/product-json-pipe.js +1 -1
- package/src/steps/render-jsonld.js +32 -24
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [1.2.2](https://github.com/adobe-rnd/helix-product-pipeline/compare/v1.2.1...v1.2.2) (2025-06-02)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* format json ([0322d2d](https://github.com/adobe-rnd/helix-product-pipeline/commit/0322d2da7507e1ea65352e8ed81ef1d3d8eb1113))
|
|
7
|
+
|
|
8
|
+
## [1.2.1](https://github.com/adobe-rnd/helix-product-pipeline/compare/v1.2.0...v1.2.1) (2025-05-31)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* always render at least one offer ([141b29d](https://github.com/adobe-rnd/helix-product-pipeline/commit/141b29d6c2426cc6ca65f0d4b872bc9a7e00cc18))
|
|
14
|
+
|
|
1
15
|
# [1.2.0](https://github.com/adobe-rnd/helix-product-pipeline/compare/v1.1.0...v1.2.0) (2025-05-23)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
package/src/product-json-pipe.js
CHANGED
|
@@ -19,6 +19,33 @@ function sanitizeJsonLd(jsonLd) {
|
|
|
19
19
|
return JSON.stringify(JSON.parse(sanitizedJsonLd.trim()), null, 2);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
function renderOffer(variant) {
|
|
23
|
+
const offer = { '@type': 'Offer' };
|
|
24
|
+
|
|
25
|
+
if (variant.sku) offer.sku = variant.sku;
|
|
26
|
+
if (variant.name) offer.name = variant.name;
|
|
27
|
+
|
|
28
|
+
if (variant.images && variant.images.length) {
|
|
29
|
+
const variantImages = [];
|
|
30
|
+
for (const img of variant.images) {
|
|
31
|
+
if (img.url) variantImages.push(img.url);
|
|
32
|
+
}
|
|
33
|
+
if (variantImages.length) offer.image = variantImages;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const { price } = variant;
|
|
37
|
+
if (price) {
|
|
38
|
+
if (price.currency) offer.priceCurrency = price.currency;
|
|
39
|
+
if (price.final) offer.price = price.final;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (variant.availability) offer.availability = `https://schema.org/${variant.availability}`;
|
|
43
|
+
if (variant.itemCondition) offer.itemCondition = `https://schema.org/${variant.itemCondition}`;
|
|
44
|
+
if (variant.url) offer.url = variant.url;
|
|
45
|
+
|
|
46
|
+
return offer;
|
|
47
|
+
}
|
|
48
|
+
|
|
22
49
|
function convertToJsonLD(product) {
|
|
23
50
|
const jsonld = {
|
|
24
51
|
'@context': 'https://schema.org',
|
|
@@ -50,32 +77,13 @@ function convertToJsonLD(product) {
|
|
|
50
77
|
if (product.variants && product.variants.length) {
|
|
51
78
|
const offers = [];
|
|
52
79
|
for (const variant of product.variants) {
|
|
53
|
-
const offer =
|
|
54
|
-
|
|
55
|
-
if (variant.sku) offer.sku = variant.sku;
|
|
56
|
-
if (variant.name) offer.name = variant.name;
|
|
57
|
-
|
|
58
|
-
if (variant.images && variant.images.length) {
|
|
59
|
-
const variantImages = [];
|
|
60
|
-
for (const img of variant.images) {
|
|
61
|
-
if (img.url) variantImages.push(img.url);
|
|
62
|
-
}
|
|
63
|
-
if (variantImages.length) offer.image = variantImages;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const { price } = variant;
|
|
67
|
-
if (price) {
|
|
68
|
-
if (price.currency) offer.priceCurrency = price.currency;
|
|
69
|
-
if (price.final) offer.price = price.final;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (variant.availability) offer.availability = `https://schema.org/${variant.availability}`;
|
|
73
|
-
if (variant.itemCondition) offer.itemCondition = `https://schema.org/${variant.itemCondition}`;
|
|
74
|
-
if (variant.url) offer.url = variant.url;
|
|
75
|
-
|
|
76
|
-
if (Object.keys(offer).length > 1) offers.push(offer);
|
|
80
|
+
const offer = renderOffer(variant);
|
|
81
|
+
offers.push(offer);
|
|
77
82
|
}
|
|
78
83
|
if (offers.length) jsonld.offers = offers;
|
|
84
|
+
} else {
|
|
85
|
+
const offer = renderOffer(product);
|
|
86
|
+
jsonld.offers = [offer];
|
|
79
87
|
}
|
|
80
88
|
|
|
81
89
|
if (product.custom && typeof product.custom === 'object') {
|