Skip to content

Commit

Permalink
test 6
Browse files Browse the repository at this point in the history
  • Loading branch information
KostiantynFandeliuk committed Dec 6, 2024
1 parent 644bf08 commit ea169cb
Showing 1 changed file with 38 additions and 42 deletions.
80 changes: 38 additions & 42 deletions scripts/initializers/order.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -14,17 +14,15 @@ 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 = {
Expand Down Expand Up @@ -56,7 +54,7 @@ await initializeDropin(async () => {
returnRef,
isTokenProvided,
langDefinitions,
orderNumber
orderNumber,
);
return;
}
Expand All @@ -75,40 +73,38 @@ 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;
window.location.href = targetPath;
} else {
await initializers.mountImmediately(initialize, {
langDefinitions,
Expand Down

0 comments on commit ea169cb

Please sign in to comment.