Skip to content

Commit 9337a9c

Browse files
committed
fix: add variant name and overrides for JSON LD
1 parent 2f1f284 commit 9337a9c

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

src/templates/json/JSONTemplate.js

+1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ export class JSONTemplate {
134134
'@type': 'Offer',
135135
sku: v.sku,
136136
mpn,
137+
name: v.name,
137138
url: offerUrl,
138139
image: v.images?.[0]?.url ?? image,
139140
availability: v.inStock ? 'InStock' : 'OutOfStock',

src/templates/json/overrides/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@
1616
export default {
1717
'thepixel--bul-eds': (await import('./thepixel--bul-eds.js')).default,
1818
'wilson-ecommerce--wilson': (await import('./wilson-ecommerce--wilson.js')).default,
19+
'visualcomfort--adobe-edge': (await import('./visualcomfort--adobe-edge.js')).default,
20+
'visualcomfort--adobe-edge-stage': (await import('./visualcomfort--adobe-edge.js')).default,
1921
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2024 Adobe. All rights reserved.
3+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License. You may obtain a copy
5+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
* OF ANY KIND, either express or implied. See the License for the specific language
10+
* governing permissions and limitations under the License.
11+
*/
12+
13+
import { JSONTemplate } from '../JSONTemplate.js';
14+
15+
export default class extends JSONTemplate {
16+
// eslint-disable-next-line class-methods-use-this
17+
renderBrand() {
18+
return {
19+
brand: {
20+
'@type': 'Brand',
21+
name: this.product.attributeMap?.brand ?? 'Visual Comfort',
22+
},
23+
};
24+
}
25+
26+
renderOffers() {
27+
const baseOffers = super.renderOffers();
28+
return baseOffers.map((o) => ({
29+
...o,
30+
shippingDetails: {
31+
'@type': 'OfferShippingDetails',
32+
shippingDestination: {
33+
'@type': 'DefinedRegion',
34+
addressCountry: {
35+
'@type': 'Country',
36+
name: 'US',
37+
},
38+
},
39+
deliveryTime: {
40+
'@type': 'ShippingDeliveryTime',
41+
businessDays: {
42+
'@type': 'OpeningHoursSpecification',
43+
},
44+
},
45+
},
46+
}));
47+
}
48+
}

test/templates/html/index.test.js

+2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ describe('Render Product HTML', () => {
9494
assert.strictEqual(offer.sku, variant.sku, `Offer SKU for variant ${variant.sku} does not match`);
9595
assert.strictEqual(offer.url, productTemplate.constructProductURL(variant), 'JSON-LD offer URL does not match');
9696
assert.strictEqual(offer.price, variant.prices.final.amount, `Offer price for variant ${variant.sku} does not match`);
97+
assert.strictEqual(offer.name, variant.name, `Offer name for variant ${variant.sku} does not match`);
9798
assert.strictEqual(offer.priceCurrency, variant.prices.final.currency, `Offer priceCurrency for variant ${variant.sku} does not match`);
9899
assert.strictEqual(offer.availability, variant.inStock ? 'InStock' : 'OutOfStock', `Offer availability for variant ${variant.sku} does not match`);
99100
assert.strictEqual(offer.image, variant.images[0].url || '', `Offer image for variant ${variant.sku} does not match`);
@@ -129,6 +130,7 @@ describe('Render Product HTML', () => {
129130
assert.strictEqual(offer.sku, product.sku, `Offer SKU for variant ${product.sku} does not match`);
130131
assert.strictEqual(offer.url, productTemplate.constructProductURL(), 'JSON-LD offer URL does not match');
131132
assert.strictEqual(offer.price, product.prices.final.amount, `Offer price for variant ${product.sku} does not match`);
133+
assert.strictEqual(offer.name, product.name, `Offer name for variant ${product.sku} does not match`);
132134
assert.strictEqual(offer.priceCurrency, product.prices.final.currency, `Offer priceCurrency for variant ${product.sku} does not match`);
133135
assert.strictEqual(offer.availability, product.inStock ? 'InStock' : 'OutOfStock', `Offer availability for variant ${product.sku} does not match`);
134136
assert.strictEqual(offer.image, product.images[0].url || '', `Offer image for variant ${product.sku} does not match`);

0 commit comments

Comments
 (0)