Skip to content

Commit

Permalink
always uses headers unless query params are defined
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Rugh <[email protected]>
  • Loading branch information
sirugh committed Jan 14, 2025
1 parent 95e8869 commit 8b39b5f
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 23 deletions.
10 changes: 5 additions & 5 deletions blocks/header/searchbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { getConfigValue } from '../../scripts/configs.js';
await loadScript(widgetProd);

const storeDetails = {
environmentId: await getConfigValue('commerce.queryparam.cs.Magento-Environment-Id'),
environmentId: await getConfigValue('commerce.headers.cs.Magento-Environment-Id'),
environmentType: (await getConfigValue('commerce-endpoint')).includes('sandbox') ? 'testing' : '',
apiKey: await getConfigValue('commerce.headers.cs.x-api-key'),
apiUrl: await getConfigValue('commerce-endpoint'),
websiteCode: await getConfigValue('commerce.queryparam.cs.Magento-Website-Code'),
storeCode: await getConfigValue('commerce.queryparam.cs.Magento-Store-Code'),
storeViewCode: await getConfigValue('commerce.queryparam.cs.Magento-Store-View-Code'),
websiteCode: await getConfigValue('commerce.headers.cs.Magento-Website-Code'),
storeCode: await getConfigValue('commerce.headers.cs.Magento-Store-Code'),
storeViewCode: await getConfigValue('commerce.headers.cs.Magento-Store-View-Code'),
config: {
pageSize: 8,
perPageConfig: {
Expand All @@ -26,7 +26,7 @@ import { getConfigValue } from '../../scripts/configs.js';
allowAllProducts: false,
},
context: {
customerGroup: await getConfigValue('commerce.queryparam.cs.Magento-Customer-Group'),
customerGroup: await getConfigValue('commerce.headers.cs.Magento-Customer-Group'),
},
route: ({ sku, urlKey }) => `/products/${urlKey}/${sku}`,
searchRoute: {
Expand Down
10 changes: 5 additions & 5 deletions blocks/product-list-page/product-list-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ export default async function decorate(block) {
block.textContent = '';

const storeDetails = {
environmentId: await getConfigValue('commerce.queryparam.cs.Magento-Environment-Id'),
environmentId: await getConfigValue('commerce.headers.cs.Magento-Environment-Id'),
environmentType: (await getConfigValue('commerce-endpoint')).includes('sandbox') ? 'testing' : '',
apiKey: await getConfigValue('commerce.headers.cs.x-api-key'),
apiUrl: await getConfigValue('commerce-endpoint'),
websiteCode: await getConfigValue('commerce.queryparam.cs.Magento-Website-Code'),
storeCode: await getConfigValue('commerce.queryparam.cs.Magento-Store-Code'),
storeViewCode: await getConfigValue('commerce.queryparam.cs.Magento-Store-View-Code'),
websiteCode: await getConfigValue('commerce.headers.cs.Magento-Website-Code'),
storeCode: await getConfigValue('commerce.headers.cs.Magento-Store-Code'),
storeViewCode: await getConfigValue('commerce.headers.cs.Magento-Store-View-Code'),
config: {
pageSize: 8,
perPageConfig: {
Expand All @@ -42,7 +42,7 @@ export default async function decorate(block) {
},
},
context: {
customerGroup: await getConfigValue('commerce.queryparam.cs.Magento-Customer-Group'),
customerGroup: await getConfigValue('commerce.headers.cs.Magento-Customer-Group'),
},
route: ({ sku, urlKey }) => {
const a = new URL(window.location.origin);
Expand Down
2 changes: 1 addition & 1 deletion blocks/product-recommendations/product-recommendations.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ async function loadRecommendation(block, context, visibility, filters) {
return;
}

const storeViewCode = await getConfigValue('commerce.queryparam.cs.Magento-Store-View-Code');
const storeViewCode = await getConfigValue('commerce.headers.cs.Magento-Store-View-Code');

if (unitsPromise) {
return;
Expand Down
4 changes: 2 additions & 2 deletions scripts/commerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export async function performMonolithGraphQLQuery(query, variables, GET = true,

const headers = {
'Content-Type': 'application/json',
Store: await getConfigValue('commerce.queryparam.cs.Magento-Store-View-Code'),
Store: await getConfigValue('commerce.headers.cs.Magento-Store-View-Code'),
};

if (USE_TOKEN) {
Expand Down Expand Up @@ -163,7 +163,7 @@ export async function trackHistory() {
return;
}
// Store product view history in session storage
const storeViewCode = await getConfigValue('commerce.queryparam.cs.Magento-Store-View-Code');
const storeViewCode = await getConfigValue('commerce.headers.cs.Magento-Store-View-Code');
window.adobeDataLayer.push((dl) => {
dl.addEventListener('adobeDataLayer:change', (event) => {
if (!event.productContext) {
Expand Down
8 changes: 4 additions & 4 deletions scripts/delayed.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ async function initAnalytics() {
// Load Commerce events SDK and collector
if (getConsent('commerce-collection')) {
const config = {
environmentId: await getConfigValue('commerce.queryparam.cs.Magento-Environment-Id'),
environmentId: await getConfigValue('commerce.headers.cs.Magento-Environment-Id'),
environment: await getConfigValue('commerce-environment'),
storeUrl: await getConfigValue('commerce-store-url'),
websiteId: parseInt(await getConfigValue('commerce-website-id'), 10),
websiteCode: await getConfigValue('commerce.queryparam.cs.Magento-Website-Code'),
websiteCode: await getConfigValue('commerce.headers.cs.Magento-Website-Code'),
storeId: parseInt(await getConfigValue('commerce-store-id'), 10),
storeCode: await getConfigValue('commerce.queryparam.cs.Magento-Store-Code'),
storeCode: await getConfigValue('commerce.headers.cs.Magento-Store-Code'),
storeViewId: parseInt(await getConfigValue('commerce-store-view-id'), 10),
storeViewCode: await getConfigValue('commerce.queryparam.cs.Magento-Store-View-Code'),
storeViewCode: await getConfigValue('commerce.headers.cs.Magento-Store-View-Code'),
websiteName: await getConfigValue('commerce-website-name'),
storeName: await getConfigValue('commerce-store-name'),
storeViewName: await getConfigValue('commerce-store-view-name'),
Expand Down
17 changes: 11 additions & 6 deletions tools/picker/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,18 @@ async function performCatalogServiceQuery(query, config, variables) {
'Content-Type': 'application/json',
};

// Set Query Parameters so they can be appended to the endpoint
// set query params if provided, or fall back to header value
const apiCall = new URL(config['commerce-endpoint']);
apiCall.searchParams.append("Magento-Environment-Id", config['commerce.queryparam.cs.Magento-Environment-Id']);
apiCall.searchParams.append("Magento-Website-Code", config['commerce.queryparam.cs.Magento-Website-Code']);
apiCall.searchParams.append("Magento-Store-View-Code", config['commerce.queryparam.cs.Magento-Store-View-Code']);
apiCall.searchParams.append("Magento-Store-Code", config['commerce.queryparam.cs.Magento-Store-Code']);
apiCall.searchParams.append("Magento-Customer-Group", config['commerce.queryparam.cs.Magento-Customer-Group']);
apiCall.searchParams.append("Magento-Environment-Id",
config['commerce.queryparam.cs.Magento-Environment-Id'] || config['commerce.headers.cs.Magento-Environment-Id']);
apiCall.searchParams.append("Magento-Website-Code",
config['commerce.queryparam.cs.Magento-Website-Code']) || config['commerce.headers.cs.Magento-Website-Code']);
apiCall.searchParams.append("Magento-Store-View-Code",
config['commerce.queryparam.cs.Magento-Store-View-Code']) || config['commerce.headers.cs.Magento-Store-View-Code']);
apiCall.searchParams.append("Magento-Store-Code",
config['commerce.queryparam.cs.Magento-Store-Code']) || config['commerce.headers.cs.Magento-Store-Code']);
apiCall.searchParams.append("Magento-Customer-Group",
config['commerce.headers.cs.Magento-Customer-Group']) || config['commerce.headers.cs.Magento-Customer-Group']);
apiCall.searchParams.append('query', query.replace(/(?:\r\n|\r|\n|\t|[\s]{4})/g, ' ')
.replace(/\s\s+/g, ' '));
apiCall.searchParams.append('variables', variables ? JSON.stringify(variables) : null);
Expand Down

0 comments on commit 8b39b5f

Please sign in to comment.