From 4fa7c7eede992a4a40054ba6563184a9d0bc89d1 Mon Sep 17 00:00:00 2001 From: Stephen Rugh Date: Fri, 20 Dec 2024 14:50:37 -0600 Subject: [PATCH] initial Signed-off-by: Stephen Rugh --- scripts/commerce.js | 13 +++++++------ scripts/initializers/pdp.js | 1 + 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/scripts/commerce.js b/scripts/commerce.js index b88527107..4a5a3c869 100644 --- a/scripts/commerce.js +++ b/scripts/commerce.js @@ -1,5 +1,5 @@ /* eslint-disable import/prefer-default-export, import/no-cycle */ -import { getConfigValue, getCookie } from './configs.js'; +import { getConfigValue, getCookie, getHeaders } from './configs.js'; import { getConsent } from './scripts.js'; /* Common query fragments */ @@ -22,11 +22,12 @@ export const priceFieldsFragment = `fragment priceFields on ProductViewPrice { export async function commerceEndpointWithQueryParams() { // Set Query Parameters so they can be appended to the endpoint const urlWithQueryParams = new URL(await getConfigValue('commerce-endpoint')); - urlWithQueryParams.searchParams.append('Magento-Environment-Id', await getConfigValue('commerce-environment-id')); - urlWithQueryParams.searchParams.append('Magento-Website-Code', await getConfigValue('commerce-website-code')); - urlWithQueryParams.searchParams.append('Magento-Store-View-Code', await getConfigValue('commerce-store-view-code')); - urlWithQueryParams.searchParams.append('Magento-Store-Code', await getConfigValue('commerce-store-code')); - urlWithQueryParams.searchParams.append('Magento-Customer-Group', await getConfigValue('commerce-customer-group')); + await getHeaders('pdp').then((headers) => { + Object.keys(headers).forEach((key) => { + // TODO: is it OK to apply all headers as query param even if they include things like api-key and content-type which was not previously a query param? + urlWithQueryParams.searchParams.append(key, headers[key]); + }); + }); return urlWithQueryParams; } diff --git a/scripts/initializers/pdp.js b/scripts/initializers/pdp.js index 6476ecffd..8664c7f5e 100644 --- a/scripts/initializers/pdp.js +++ b/scripts/initializers/pdp.js @@ -29,6 +29,7 @@ await initializeDropin(async () => { setEndpoint(await commerceEndpointWithQueryParams()); // Set Fetch Headers (Service) + // TODO: is it OK to apply all headers even though the commerceEndpointWithQueryParams also applies them? setFetchGraphQlHeaders(await getHeaders('pdp')); const sku = getSkuFromUrl();