From f8d360c956a609c1f80347509f24b5029c1f5479 Mon Sep 17 00:00:00 2001
From: "Carlos A. Cabrera" <316104+fnhipster@users.noreply.github.com>
Date: Thu, 5 Dec 2024 10:58:43 -0600
Subject: [PATCH 01/10] Fixes non-existing product 404 (#234)
---
blocks/product-details/product-details.js | 7 +------
scripts/initializers/pdp.js | 13 +++++++++++--
2 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/blocks/product-details/product-details.js b/blocks/product-details/product-details.js
index f6f120183..4125f0e99 100644
--- a/blocks/product-details/product-details.js
+++ b/blocks/product-details/product-details.js
@@ -21,7 +21,7 @@ import ProductAttributes from '@dropins/storefront-pdp/containers/ProductAttribu
import ProductGallery from '@dropins/storefront-pdp/containers/ProductGallery.js';
// Libs
-import { setJsonLd, loadErrorPage } from '../../scripts/commerce.js';
+import { setJsonLd } from '../../scripts/commerce.js';
import { fetchPlaceholders } from '../../scripts/aem.js';
// Initializers
@@ -33,11 +33,6 @@ export default async function decorate(block) {
const product = events._lastEvent?.['pdp/data']?.payload ?? null;
const labels = await fetchPlaceholders();
- if (!product) {
- await loadErrorPage();
- return Promise.reject();
- }
-
// Layout
const fragment = document.createRange().createContextualFragment(`
diff --git a/scripts/initializers/pdp.js b/scripts/initializers/pdp.js
index 016c593cb..eee1a9c94 100644
--- a/scripts/initializers/pdp.js
+++ b/scripts/initializers/pdp.js
@@ -10,7 +10,12 @@ import {
fetchProductData,
} from '@dropins/storefront-pdp/api.js';
import { initializeDropin } from './index.js';
-import { commerceEndpointWithQueryParams, getOptionsUIDsFromUrl, getSkuFromUrl } from '../commerce.js';
+import {
+ commerceEndpointWithQueryParams,
+ getOptionsUIDsFromUrl,
+ getSkuFromUrl,
+ loadErrorPage,
+} from '../commerce.js';
import { getConfigValue } from '../configs.js';
import { fetchPlaceholders } from '../aem.js';
@@ -37,6 +42,10 @@ await initializeDropin(async () => {
fetchPlaceholders(),
]);
+ if (!product?.sku) {
+ return loadErrorPage();
+ }
+
const langDefinitions = {
default: {
...labels,
@@ -50,7 +59,7 @@ await initializeDropin(async () => {
};
// Initialize Dropins
- await initializers.mountImmediately(initialize, {
+ return initializers.mountImmediately(initialize, {
sku,
optionsUIDs,
langDefinitions,
From ac4ec7939660ab37826666d0cc6c40c95cb4863e Mon Sep 17 00:00:00 2001
From: "Carlos A. Cabrera" <316104+fnhipster@users.noreply.github.com>
Date: Thu, 5 Dec 2024 13:31:48 -0600
Subject: [PATCH 02/10] Fix 404 styles (#236)
---
404.html | 10 +++++++---
scripts/commerce.js | 4 ++++
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/404.html b/404.html
index 50b497e7a..ded917dd8 100644
--- a/404.html
+++ b/404.html
@@ -11,7 +11,7 @@
"@dropins/storefront-auth/": "/scripts/__dropins__/storefront-auth/"
}
}
-
+