@@ -68,6 +68,15 @@ export class JSONTemplate {
68
68
return productUrl ;
69
69
}
70
70
71
+ /**
72
+ * @param {Variant } [variant]
73
+ */
74
+ constructMPN ( variant ) {
75
+ return variant
76
+ ? variant . attributes . find ( ( attr ) => attr . name . toLowerCase ( ) === 'mpn' ) ?. value ?? this . constructMPN ( )
77
+ : this . product . attributes . find ( ( attr ) => attr . name . toLowerCase ( ) === 'mpn' ) ?. value ?? this . product . sku ;
78
+ }
79
+
71
80
renderBrand ( ) {
72
81
const { attributes } = this . product ;
73
82
const brandName = attributes ?. find ( ( attr ) => attr . name === 'brand' ) ?. value ;
@@ -90,13 +99,16 @@ export class JSONTemplate {
90
99
return {
91
100
offers : [
92
101
...offers . map ( ( v ) => {
93
- const offerUrl = this . constructProductURL ( configurableProduct ? v : undefined ) ;
94
102
const { prices : variantPrices } = v ;
103
+ const offerUrl = this . constructProductURL ( configurableProduct ? v : undefined ) ;
104
+ const mpn = this . constructMPN ( configurableProduct ? v : undefined ) ;
95
105
const finalPrice = variantPrices ?. final ?. amount ;
96
106
const regularPrice = variantPrices ?. regular ?. amount ;
107
+
97
108
const offer = {
98
109
'@type' : 'Offer' ,
99
110
sku : v . sku ,
111
+ mpn,
100
112
url : offerUrl ,
101
113
image : v . images ?. [ 0 ] ?. url ?? image ,
102
114
availability : v . inStock ? 'InStock' : 'OutOfStock' ,
@@ -116,7 +128,7 @@ export class JSONTemplate {
116
128
offer . priceValidUntil = v . specialToDate ;
117
129
}
118
130
119
- return offer ;
131
+ return pruneUndefined ( offer ) ;
120
132
} ) . filter ( Boolean ) ,
121
133
] ,
122
134
} ;
@@ -145,13 +157,15 @@ export class JSONTemplate {
145
157
} = this . product ;
146
158
147
159
const productUrl = this . constructProductURL ( ) ;
160
+ const mpn = this . constructMPN ( ) ;
148
161
const image = images ?. [ 0 ] ?. url ?? findProductImage ( this . product , this . variants ) ?. url ;
149
162
return JSON . stringify ( pruneUndefined ( {
150
163
'@context' : 'http://schema.org' ,
151
164
'@type' : 'Product' ,
152
165
'@id' : productUrl ,
153
166
name,
154
167
sku,
168
+ mpn,
155
169
description : metaDescription ,
156
170
image,
157
171
productID : sku ,
0 commit comments