Skip to content

Commit

Permalink
show price api call integrated in commerce js
Browse files Browse the repository at this point in the history
  • Loading branch information
lakshmithi committed Dec 21, 2024
1 parent 2bd9e21 commit 5acebd1
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
17 changes: 14 additions & 3 deletions blocks/product-hero/product-hero.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
a, div, p, span, hr, h1,
a, div, p, span, hr, h1, h4,
} from '../../scripts/dom-builder.js';
import {
getAuthorization, getCommerceBase,
getProductResponse,
getProductResponse, getProductPriceDetails
} from '../../scripts/commerce.js';
import { createOptimizedS7Picture, decorateModals } from '../../scripts/scripts.js';
import { getMetadata } from '../../scripts/lib-franklin.js';
Expand Down Expand Up @@ -147,7 +147,7 @@ async function addToQuote(product) {
referrer: window.location.href,
referrerTitle: document.title.replace('| Danaher Lifesciences', '').replace('| Danaher Life Sciences', '').trim(),
}),
});
});console.log('phquote ', quote);
const { default: getToast } = await import('../../scripts/toast.js');
if (quote.status === 200) {
const responseJson = await quote.json();
Expand All @@ -163,12 +163,23 @@ async function addToQuote(product) {
}
}

async function addToCart(product){
try {
const baseURL = getCommerceBase();
const sku = getSKU();
const showURL = `${baseURL} + /?product=${sku} `;
console.log('phshowURL ', showURL);

}catch (error) {}
}

export default async function decorate(block) {
const titleEl = block.querySelector('h1');
const h1Value = getMetadata('h1');
titleEl?.classList.add('title');
titleEl?.parentElement.parentElement.remove();
const response = await getProductResponse();
const cartResponse = await getProductPriceDetails();
if (response?.length > 0) {
const allImages = response[0]?.raw.images;
const verticalImageGallery = imageSlider(allImages, response[0]?.Title);
Expand Down
41 changes: 40 additions & 1 deletion scripts/commerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
export function getCommerceBase() {
return window.DanaherConfig !== undefined ? window.DanaherConfig.intershopDomain + window.DanaherConfig.intershopPath : 'https://shop.lifesciences.danaher.com/INTERSHOP/rest/WFS/DANAHERLS-LSIG-Site/-';
}

console.log('brl ', getCommerceBase());
/**
* Returns the user authorization used for commerce API calls
*/
Expand Down Expand Up @@ -138,6 +138,45 @@ export async function getProductResponse() {
}
}

export async function getProductPriceDetails() {
try{
let response = JSON.parse(localStorage.getItem('product-details'));
const sku = getSKU();
if (response && response.at(0)?.raw.sku === sku) {
return response;
}
localStorage.removeItem('product-details');

const host = `https://${window.DanaherConfig.host}/us/en/product-data`;
const url = window.location.search
? `${host}/${window.location.search}&product=${sku}`
: `${host}/?product=${sku}`;

const baseURL = getCommerceBase();
let showURL = `${baseURL}/products/${sku} `;
showURL = showURL.replace(/-abcam/g, "");
console.log('cshowURL ', showURL);

const mockURL = 'https://stage.shop.lifesciences.danaher.com/INTERSHOP/rest/WFS/DANAHERLS-LSIG-Site/-/products/ab150686';
const priceResponse = await fetch(mockURL)
.then((res) => {
if (res.ok) {
return res.json();
}
throw new Error('Sorry, network error, not able to render response.');
});

if (priceResponse.results.length > 0) {
response = priceResponse.results;
localStorage.setItem('product-details', JSON.stringify(priceResponse.results));
return response;
}
} catch (error) {
// eslint-disable-next-line no-console
console.error(error);
}
}

function getWorkflowFamily() {
if (window.location.pathname.match(/\/us\/en\/solutions\//)) {
const pageUrl = window.location.pathname.replace(/^\/us\/en\/solutions\//, '').replace(/\.html$/, '').split('/');
Expand Down

0 comments on commit 5acebd1

Please sign in to comment.