Skip to content

Commit

Permalink
fix: json-ld tweaks (#49)
Browse files Browse the repository at this point in the history
* fix: mpn on product only

* fix: no trailing slash on offer links

* chore: fix test

* chore: fix post-deploy test
  • Loading branch information
maxakuru authored Nov 19, 2024
1 parent 75073c1 commit 45971c6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/templates/json/JSONTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class JSONTemplate {
if (variant) {
const offerVariantURLTemplate = matchedPathConfig?.offerVariantURLTemplate;
if (!offerVariantURLTemplate) {
return `${productUrl}/?optionsUIDs=${encodeURIComponent(variant.selections.join(','))}`;
return `${productUrl}?optionsUIDs=${encodeURIComponent(variant.selections.join(','))}`;
}

const variantPath = offerVariantURLTemplate
Expand Down
3 changes: 2 additions & 1 deletion src/templates/json/overrides/wilson-ecommerce--wilson.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export default class extends JSONTemplate {
* @param {Variant} [variant]
*/
constructMPN(variant) {
return variant ? variant.sku : this.product.sku;
// only include mpn on product-level
return variant ? undefined : this.product.sku;
}

renderOffers() {
Expand Down
30 changes: 15 additions & 15 deletions test/fixtures/post-deploy/bella-tank.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
{
"@type": "Offer",
"sku": "WT01-L-Black",
"url": "https://example.test/products/bella-tank/wt01/?optionsUIDs=Y29uZmlndXJhYmxlLzI3Ny8xNzI%3D%2CY29uZmlndXJhYmxlLzU1Ni81MzI%3D",
"url": "https://example.test/products/bella-tank/wt01?optionsUIDs=Y29uZmlndXJhYmxlLzI3Ny8xNzI%3D%2CY29uZmlndXJhYmxlLzU1Ni81MzI%3D",
"image": "https://www.aemshop.net/media/catalog/product/w/t/wt01-black_main_1.jpg",
"availability": "InStock",
"price": 29,
Expand All @@ -55,7 +55,7 @@
{
"@type": "Offer",
"sku": "WT01-L-Blue",
"url": "https://example.test/products/bella-tank/wt01/?optionsUIDs=Y29uZmlndXJhYmxlLzI3Ny8xNzU%3D%2CY29uZmlndXJhYmxlLzU1Ni81MzI%3D",
"url": "https://example.test/products/bella-tank/wt01?optionsUIDs=Y29uZmlndXJhYmxlLzI3Ny8xNzU%3D%2CY29uZmlndXJhYmxlLzU1Ni81MzI%3D",
"image": "https://www.aemshop.net/media/catalog/product/w/t/wt01-blue_main_1.jpg",
"availability": "InStock",
"price": 29,
Expand All @@ -64,7 +64,7 @@
{
"@type": "Offer",
"sku": "WT01-L-Orange",
"url": "https://example.test/products/bella-tank/wt01/?optionsUIDs=Y29uZmlndXJhYmxlLzI3Ny8xOTM%3D%2CY29uZmlndXJhYmxlLzU1Ni81MzI%3D",
"url": "https://example.test/products/bella-tank/wt01?optionsUIDs=Y29uZmlndXJhYmxlLzI3Ny8xOTM%3D%2CY29uZmlndXJhYmxlLzU1Ni81MzI%3D",
"image": "https://www.aemshop.net/media/catalog/product/w/t/wt01-orange_main_1.jpg",
"availability": "InStock",
"price": 29,
Expand All @@ -73,7 +73,7 @@
{
"@type": "Offer",
"sku": "WT01-M-Black",
"url": "https://example.test/products/bella-tank/wt01/?optionsUIDs=Y29uZmlndXJhYmxlLzI3Ny8xNzI%3D%2CY29uZmlndXJhYmxlLzU1Ni81Mjk%3D",
"url": "https://example.test/products/bella-tank/wt01?optionsUIDs=Y29uZmlndXJhYmxlLzI3Ny8xNzI%3D%2CY29uZmlndXJhYmxlLzU1Ni81Mjk%3D",
"image": "https://www.aemshop.net/media/catalog/product/w/t/wt01-black_main_1.jpg",
"availability": "InStock",
"price": 29,
Expand All @@ -82,7 +82,7 @@
{
"@type": "Offer",
"sku": "WT01-M-Blue",
"url": "https://example.test/products/bella-tank/wt01/?optionsUIDs=Y29uZmlndXJhYmxlLzI3Ny8xNzU%3D%2CY29uZmlndXJhYmxlLzU1Ni81Mjk%3D",
"url": "https://example.test/products/bella-tank/wt01?optionsUIDs=Y29uZmlndXJhYmxlLzI3Ny8xNzU%3D%2CY29uZmlndXJhYmxlLzU1Ni81Mjk%3D",
"image": "https://www.aemshop.net/media/catalog/product/w/t/wt01-blue_main_1.jpg",
"availability": "InStock",
"price": 29,
Expand All @@ -91,7 +91,7 @@
{
"@type": "Offer",
"sku": "WT01-M-Orange",
"url": "https://example.test/products/bella-tank/wt01/?optionsUIDs=Y29uZmlndXJhYmxlLzI3Ny8xOTM%3D%2CY29uZmlndXJhYmxlLzU1Ni81Mjk%3D",
"url": "https://example.test/products/bella-tank/wt01?optionsUIDs=Y29uZmlndXJhYmxlLzI3Ny8xOTM%3D%2CY29uZmlndXJhYmxlLzU1Ni81Mjk%3D",
"image": "https://www.aemshop.net/media/catalog/product/w/t/wt01-orange_main_1.jpg",
"availability": "InStock",
"price": 29,
Expand All @@ -100,7 +100,7 @@
{
"@type": "Offer",
"sku": "WT01-S-Black",
"url": "https://example.test/products/bella-tank/wt01/?optionsUIDs=Y29uZmlndXJhYmxlLzI3Ny8xNzI%3D%2CY29uZmlndXJhYmxlLzU1Ni81MjY%3D",
"url": "https://example.test/products/bella-tank/wt01?optionsUIDs=Y29uZmlndXJhYmxlLzI3Ny8xNzI%3D%2CY29uZmlndXJhYmxlLzU1Ni81MjY%3D",
"image": "https://www.aemshop.net/media/catalog/product/w/t/wt01-black_main_1.jpg",
"availability": "InStock",
"price": 29,
Expand All @@ -109,7 +109,7 @@
{
"@type": "Offer",
"sku": "WT01-S-Blue",
"url": "https://example.test/products/bella-tank/wt01/?optionsUIDs=Y29uZmlndXJhYmxlLzI3Ny8xNzU%3D%2CY29uZmlndXJhYmxlLzU1Ni81MjY%3D",
"url": "https://example.test/products/bella-tank/wt01?optionsUIDs=Y29uZmlndXJhYmxlLzI3Ny8xNzU%3D%2CY29uZmlndXJhYmxlLzU1Ni81MjY%3D",
"image": "https://www.aemshop.net/media/catalog/product/w/t/wt01-blue_main_1.jpg",
"availability": "InStock",
"price": 29,
Expand All @@ -118,7 +118,7 @@
{
"@type": "Offer",
"sku": "WT01-S-Orange",
"url": "https://example.test/products/bella-tank/wt01/?optionsUIDs=Y29uZmlndXJhYmxlLzI3Ny8xOTM%3D%2CY29uZmlndXJhYmxlLzU1Ni81MjY%3D",
"url": "https://example.test/products/bella-tank/wt01?optionsUIDs=Y29uZmlndXJhYmxlLzI3Ny8xOTM%3D%2CY29uZmlndXJhYmxlLzU1Ni81MjY%3D",
"image": "https://www.aemshop.net/media/catalog/product/w/t/wt01-orange_main_1.jpg",
"availability": "InStock",
"price": 29,
Expand All @@ -127,7 +127,7 @@
{
"@type": "Offer",
"sku": "WT01-XL-Black",
"url": "https://example.test/products/bella-tank/wt01/?optionsUIDs=Y29uZmlndXJhYmxlLzI3Ny8xNzI%3D%2CY29uZmlndXJhYmxlLzU1Ni81MzU%3D",
"url": "https://example.test/products/bella-tank/wt01?optionsUIDs=Y29uZmlndXJhYmxlLzI3Ny8xNzI%3D%2CY29uZmlndXJhYmxlLzU1Ni81MzU%3D",
"image": "https://www.aemshop.net/media/catalog/product/w/t/wt01-black_main_1.jpg",
"availability": "InStock",
"price": 29,
Expand All @@ -136,7 +136,7 @@
{
"@type": "Offer",
"sku": "WT01-XL-Blue",
"url": "https://example.test/products/bella-tank/wt01/?optionsUIDs=Y29uZmlndXJhYmxlLzI3Ny8xNzU%3D%2CY29uZmlndXJhYmxlLzU1Ni81MzU%3D",
"url": "https://example.test/products/bella-tank/wt01?optionsUIDs=Y29uZmlndXJhYmxlLzI3Ny8xNzU%3D%2CY29uZmlndXJhYmxlLzU1Ni81MzU%3D",
"image": "https://www.aemshop.net/media/catalog/product/w/t/wt01-blue_main_1.jpg",
"availability": "InStock",
"price": 29,
Expand All @@ -145,7 +145,7 @@
{
"@type": "Offer",
"sku": "WT01-XL-Orange",
"url": "https://example.test/products/bella-tank/wt01/?optionsUIDs=Y29uZmlndXJhYmxlLzI3Ny8xOTM%3D%2CY29uZmlndXJhYmxlLzU1Ni81MzU%3D",
"url": "https://example.test/products/bella-tank/wt01?optionsUIDs=Y29uZmlndXJhYmxlLzI3Ny8xOTM%3D%2CY29uZmlndXJhYmxlLzU1Ni81MzU%3D",
"image": "https://www.aemshop.net/media/catalog/product/w/t/wt01-orange_main_1.jpg",
"availability": "InStock",
"price": 29,
Expand All @@ -154,7 +154,7 @@
{
"@type": "Offer",
"sku": "WT01-XS-Black",
"url": "https://example.test/products/bella-tank/wt01/?optionsUIDs=Y29uZmlndXJhYmxlLzI3Ny8xNzI%3D%2CY29uZmlndXJhYmxlLzU1Ni81MjM%3D",
"url": "https://example.test/products/bella-tank/wt01?optionsUIDs=Y29uZmlndXJhYmxlLzI3Ny8xNzI%3D%2CY29uZmlndXJhYmxlLzU1Ni81MjM%3D",
"image": "https://www.aemshop.net/media/catalog/product/w/t/wt01-black_main_1.jpg",
"availability": "InStock",
"price": 29,
Expand All @@ -163,7 +163,7 @@
{
"@type": "Offer",
"sku": "WT01-XS-Blue",
"url": "https://example.test/products/bella-tank/wt01/?optionsUIDs=Y29uZmlndXJhYmxlLzI3Ny8xNzU%3D%2CY29uZmlndXJhYmxlLzU1Ni81MjM%3D",
"url": "https://example.test/products/bella-tank/wt01?optionsUIDs=Y29uZmlndXJhYmxlLzI3Ny8xNzU%3D%2CY29uZmlndXJhYmxlLzU1Ni81MjM%3D",
"image": "https://www.aemshop.net/media/catalog/product/w/t/wt01-blue_main_1.jpg",
"availability": "InStock",
"price": 29,
Expand All @@ -172,7 +172,7 @@
{
"@type": "Offer",
"sku": "WT01-XS-Orange",
"url": "https://example.test/products/bella-tank/wt01/?optionsUIDs=Y29uZmlndXJhYmxlLzI3Ny8xOTM%3D%2CY29uZmlndXJhYmxlLzU1Ni81MjM%3D",
"url": "https://example.test/products/bella-tank/wt01?optionsUIDs=Y29uZmlndXJhYmxlLzI3Ny8xOTM%3D%2CY29uZmlndXJhYmxlLzU1Ni81MjM%3D",
"image": "https://www.aemshop.net/media/catalog/product/w/t/wt01-orange_main_1.jpg",
"availability": "InStock",
"price": 29,
Expand Down
6 changes: 3 additions & 3 deletions test/templates/json/JSONTemplate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('JSONTemplate', () => {

// @ts-ignore
const url = template.constructProductURL(variant1);
const expectedUrl = 'https://www.example.com/products/utopia-small-pendant/kw5531/?optionsUIDs=Y29uZmlndXJhYmxlLzE2NTEvODI3MQ%3D%3D';
const expectedUrl = 'https://www.example.com/products/utopia-small-pendant/kw5531?optionsUIDs=Y29uZmlndXJhYmxlLzE2NTEvODI3MQ%3D%3D';
assert.strictEqual(url, expectedUrl, 'Variant URL without offerVariantURLTemplate does not match expected URL');
});

Expand All @@ -97,7 +97,7 @@ describe('JSONTemplate', () => {

// @ts-ignore
const url = template.constructProductURL(variantWithSpecialSelections);
const expectedUrl = 'https://www.example.com/products/summer-sun/kw%2055%2F31/?optionsUIDs=Y29uZmlndXJhYmxlLzE2NTEvODI3MQ%3D%3D%2CY29uZmlndXJhYmxlLzI0NjEvMzYzNDE%3D';
const expectedUrl = 'https://www.example.com/products/summer-sun/kw%2055%2F31?optionsUIDs=Y29uZmlndXJhYmxlLzE2NTEvODI3MQ%3D%3D%2CY29uZmlndXJhYmxlLzI0NjEvMzYzNDE%3D';
assert.strictEqual(url, expectedUrl, 'Variant URL with special characters does not match expected URL');
});

Expand All @@ -114,7 +114,7 @@ describe('JSONTemplate', () => {
}), product1, [variantEmptySelections]);
// @ts-ignore
const url = template.constructProductURL(variantEmptySelections);
const expectedUrl = 'https://www.example.com/products/utopia-small-pendant/kw5531/?optionsUIDs=';
const expectedUrl = 'https://www.example.com/products/utopia-small-pendant/kw5531?optionsUIDs=';
assert.strictEqual(url, expectedUrl, 'URL with empty variant selections does not match expected URL');
});

Expand Down

0 comments on commit 45971c6

Please sign in to comment.