diff --git a/scripts/initializers/order.js b/scripts/initializers/order.js index 23f263c5d..2bc34d8d0 100644 --- a/scripts/initializers/order.js +++ b/scripts/initializers/order.js @@ -1,9 +1,9 @@ -import { events } from '@dropins/tools/event-bus.js'; -import { initializers } from '@dropins/tools/initializer.js'; -import { initialize } from '@dropins/storefront-order/api.js'; -import { checkIsAuthenticated } from '../configs.js'; -import { initializeDropin } from './index.js'; -import { fetchPlaceholders } from '../aem.js'; +import { events } from "@dropins/tools/event-bus.js"; +import { initializers } from "@dropins/tools/initializer.js"; +import { initialize } from "@dropins/storefront-order/api.js"; +import { checkIsAuthenticated } from "../configs.js"; +import { initializeDropin } from "./index.js"; +import { fetchPlaceholders } from "../aem.js"; import { CUSTOMER_ORDER_DETAILS_PATH, @@ -14,15 +14,17 @@ import { CREATE_RETURN_PATH, CUSTOMER_ORDERS_PATH, ORDER_STATUS_PATH, - CUSTOMER_PATH, SALES_GUEST_VIEW_PATH, SALES_ORDER_VIEW_PATH, -} from '../constants.js'; + CUSTOMER_PATH, + SALES_GUEST_VIEW_PATH, + SALES_ORDER_VIEW_PATH, +} from "../constants.js"; await initializeDropin(async () => { const { pathname, searchParams } = new URL(window.location.href); const isAccountPage = pathname.includes(CUSTOMER_PATH); - const orderRef = searchParams.get('orderRef'); - const returnRef = searchParams.get('returnRef'); - const orderNumber = searchParams.get('orderNumber'); + const orderRef = searchParams.get("orderRef"); + const returnRef = searchParams.get("returnRef"); + const orderNumber = searchParams.get("orderNumber"); const isTokenProvided = orderRef && orderRef.length > 20; const labels = await fetchPlaceholders(); const langDefinitions = { @@ -54,7 +56,7 @@ await initializeDropin(async () => { returnRef, isTokenProvided, langDefinitions, - orderNumber, + orderNumber ); return; } @@ -73,35 +75,37 @@ async function handleUserOrdersRedirects( returnRef, isTokenProvided, langDefinitions, - orderNumber, + orderNumber ) { let targetPath = null; - events.on('order/error', () => { - if (checkIsAuthenticated()) { - window.location.href = CUSTOMER_ORDERS_PATH; - } else if (isTokenProvided) { - window.location.href = orderNumber ? `${ORDER_STATUS_PATH}?orderRef=${orderNumber}` : ORDER_STATUS_PATH; - } else { - window.location.href = `${ORDER_STATUS_PATH}?orderRef=${orderRef}`; - } - }); + events.on("order/error", () => { + // if (checkIsAuthenticated()) { + // window.location.href = CUSTOMER_ORDERS_PATH; + // } else if (isTokenProvided) { + // window.location.href = orderNumber + // ? `${ORDER_STATUS_PATH}?orderRef=${orderNumber}` + // : ORDER_STATUS_PATH; + // } else { + // window.location.href = `${ORDER_STATUS_PATH}?orderRef=${orderRef}`; + // } + // }); - if (checkIsAuthenticated()) { - if (!orderRef) { - targetPath = CUSTOMER_ORDERS_PATH; - } else if (isAccountPage) { - targetPath = isTokenProvided - ? `${ORDER_DETAILS_PATH}?orderRef=${orderRef}` - : null; - } else { - targetPath = isTokenProvided - ? null - : `${CUSTOMER_ORDER_DETAILS_PATH}?orderRef=${orderRef}`; - } - } else { - targetPath = !orderRef ? ORDER_STATUS_PATH : null; - } + // if (checkIsAuthenticated()) { + // if (!orderRef) { + // targetPath = CUSTOMER_ORDERS_PATH; + // } else if (isAccountPage) { + // targetPath = isTokenProvided + // ? `${ORDER_DETAILS_PATH}?orderRef=${orderRef}` + // : null; + // } else { + // targetPath = isTokenProvided + // ? null + // : `${CUSTOMER_ORDER_DETAILS_PATH}?orderRef=${orderRef}`; + // } + // } else { + // targetPath = !orderRef ? ORDER_STATUS_PATH : null; + // } if (targetPath) { window.location.href = targetPath;