From 59834f89b3a1de1b2f9543d970059f6af7ca919d Mon Sep 17 00:00:00 2001 From: "Carlos A. Cabrera" <316104+fnhipster@users.noreply.github.com> Date: Thu, 7 Nov 2024 14:42:23 -0600 Subject: [PATCH] fixed placeholders (#172) --- blocks/product-details/product-details.js | 35 +---------------------- scripts/aem.js | 16 +++++++---- 2 files changed, 12 insertions(+), 39 deletions(-) diff --git a/blocks/product-details/product-details.js b/blocks/product-details/product-details.js index 10ae60e9d5..b61405d12a 100644 --- a/blocks/product-details/product-details.js +++ b/blocks/product-details/product-details.js @@ -136,40 +136,7 @@ export default async function decorate(block) { const langDefinitions = { default: { - PDP: { - Product: { - Incrementer: { label: placeholders.pdpProductIncrementer }, - OutOfStock: { label: placeholders.pdpProductOutofstock }, - AddToCart: { label: placeholders.pdpProductAddtocart }, - Details: { label: placeholders.pdpProductDetails }, - RegularPrice: { label: placeholders.pdpProductRegularprice }, - SpecialPrice: { label: placeholders.pdpProductSpecialprice }, - PriceRange: { - From: { label: placeholders.pdpProductPricerangeFrom }, - To: { label: placeholders.pdpProductPricerangeTo }, - }, - Image: { label: placeholders.pdpProductImage }, - }, - Swatches: { - Required: { label: placeholders.pdpSwatchesRequired }, - }, - Carousel: { - label: placeholders.pdpCarousel, - Next: { label: placeholders.pdpCarouselNext }, - Previous: { label: placeholders.pdpCarouselPrevious }, - Slide: { label: placeholders.pdpCarouselSlide }, - Controls: { - label: placeholders.pdpCarouselControls, - Button: { label: placeholders.pdpCarouselControlsButton }, - }, - }, - Overlay: { - Close: { label: placeholders.pdpOverlayClose }, - }, - }, - Custom: { - AddingToCart: { label: placeholders.pdpCustomAddingtocart }, - }, + ...placeholders, }, }; diff --git a/scripts/aem.js b/scripts/aem.js index 40662e6148..e75c0b1ac2 100644 --- a/scripts/aem.js +++ b/scripts/aem.js @@ -511,11 +511,17 @@ async function fetchPlaceholders(prefix = 'default') { }) .then((json) => { const placeholders = {}; - json.data - .filter((placeholder) => placeholder.Key) - .forEach((placeholder) => { - placeholders[toCamelCase(placeholder.Key)] = placeholder.Text; - }); + json.data.forEach(({ Key, Value }) => { + if (Key) { + const keys = Key.split('.'); + const lastKey = keys.pop(); + const target = keys.reduce((obj, key) => { + obj[key] = obj[key] || {}; + return obj[key]; + }, placeholders); + target[lastKey] = Value; + } + }); window.placeholders[prefix] = placeholders; resolve(window.placeholders[prefix]); })