From 0ac03abb0bfea1e39510b6b4bfc6f07f72481a83 Mon Sep 17 00:00:00 2001 From: Christophe Jelger Date: Thu, 24 Sep 2020 14:31:31 +0200 Subject: [PATCH 1/2] CIF-1638 - Add client-side support for staged catalog data - disable client-side price loading on launches --- .../internal/models/v1/product/ProductImpl.java | 3 ++- .../v1/productcollection/ProductCollectionImpl.java | 3 ++- .../internal/models/v1/product/ProductImplTest.java | 9 +++++++++ .../models/v1/productlist/ProductListImplTest.java | 9 +++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/bundles/core/src/main/java/com/adobe/cq/commerce/core/components/internal/models/v1/product/ProductImpl.java b/bundles/core/src/main/java/com/adobe/cq/commerce/core/components/internal/models/v1/product/ProductImpl.java index 2713f5e22e..3fb7c6018e 100644 --- a/bundles/core/src/main/java/com/adobe/cq/commerce/core/components/internal/models/v1/product/ProductImpl.java +++ b/bundles/core/src/main/java/com/adobe/cq/commerce/core/components/internal/models/v1/product/ProductImpl.java @@ -65,6 +65,7 @@ import com.adobe.cq.commerce.magento.graphql.SimpleProduct; import com.adobe.cq.commerce.magento.graphql.VirtualProduct; import com.adobe.cq.sightly.SightlyWCMMode; +import com.adobe.cq.wcm.launches.utils.LaunchUtils; import com.day.cq.wcm.api.Page; import com.day.cq.wcm.api.designer.Style; import com.fasterxml.jackson.core.JsonProcessingException; @@ -287,7 +288,7 @@ public List getVariantAttributes() { @Override public Boolean loadClientPrice() { - return loadClientPrice; + return loadClientPrice && !LaunchUtils.isLaunchBasedPath(currentPage.getPath()); } @Override diff --git a/bundles/core/src/main/java/com/adobe/cq/commerce/core/components/internal/models/v1/productcollection/ProductCollectionImpl.java b/bundles/core/src/main/java/com/adobe/cq/commerce/core/components/internal/models/v1/productcollection/ProductCollectionImpl.java index d5a8cafd21..b59e1a416a 100644 --- a/bundles/core/src/main/java/com/adobe/cq/commerce/core/components/internal/models/v1/productcollection/ProductCollectionImpl.java +++ b/bundles/core/src/main/java/com/adobe/cq/commerce/core/components/internal/models/v1/productcollection/ProductCollectionImpl.java @@ -36,6 +36,7 @@ import com.adobe.cq.commerce.core.search.internal.models.SearchResultsSetImpl; import com.adobe.cq.commerce.core.search.models.SearchResultsSet; import com.adobe.cq.commerce.core.search.services.SearchResultsService; +import com.adobe.cq.wcm.launches.utils.LaunchUtils; import com.day.cq.wcm.api.Page; import com.day.cq.wcm.api.designer.Style; @@ -94,7 +95,7 @@ public Integer calculateCurrentPageCursor(final String currentPageIndexCandidate @Override public boolean loadClientPrice() { - return loadClientPrice; + return loadClientPrice && !LaunchUtils.isLaunchBasedPath(currentPage.getPath()); } protected Map createFilterMap(final Map parameterMap) { diff --git a/bundles/core/src/test/java/com/adobe/cq/commerce/core/components/internal/models/v1/product/ProductImplTest.java b/bundles/core/src/test/java/com/adobe/cq/commerce/core/components/internal/models/v1/product/ProductImplTest.java index 65438e70c8..a7cc923ceb 100644 --- a/bundles/core/src/test/java/com/adobe/cq/commerce/core/components/internal/models/v1/product/ProductImplTest.java +++ b/bundles/core/src/test/java/com/adobe/cq/commerce/core/components/internal/models/v1/product/ProductImplTest.java @@ -417,4 +417,13 @@ public void testProductNotFound() throws IOException { productModel = context.request().adaptTo(ProductImpl.class); Assert.assertFalse("Product is not found", productModel.getFound()); } + + @Test + public void testClientLoadingIsDisabledOnLaunchPage() { + productModel = context.request().adaptTo(ProductImpl.class); + Assert.assertTrue(productModel.loadClientPrice()); + Page launch = context.pageManager().getPage("/content/launches/2020/09/14/mylaunch" + PAGE); + Whitebox.setInternalState(productModel, "currentPage", launch); + Assert.assertFalse(productModel.loadClientPrice()); + } } diff --git a/bundles/core/src/test/java/com/adobe/cq/commerce/core/components/internal/models/v1/productlist/ProductListImplTest.java b/bundles/core/src/test/java/com/adobe/cq/commerce/core/components/internal/models/v1/productlist/ProductListImplTest.java index d3a4ccfa47..10d3eb5812 100644 --- a/bundles/core/src/test/java/com/adobe/cq/commerce/core/components/internal/models/v1/productlist/ProductListImplTest.java +++ b/bundles/core/src/test/java/com/adobe/cq/commerce/core/components/internal/models/v1/productlist/ProductListImplTest.java @@ -383,4 +383,13 @@ public void testSorting() { Assert.assertEquals("Product Name", otherKey.getLabel()); Assert.assertEquals(Sorter.Order.ASC, otherKey.getOrder()); } + + @Test + public void testClientLoadingIsDisabledOnLaunchPage() { + productListModel = context.request().adaptTo(ProductListImpl.class); + Assert.assertTrue(productListModel.loadClientPrice()); + Page launch = context.pageManager().getPage("/content/launches/2020/09/14/mylaunch" + PAGE); + Whitebox.setInternalState(productListModel, "currentPage", launch); + Assert.assertFalse(productListModel.loadClientPrice()); + } } From d52af8f6df94dfebc14f706c6136ce8b8aaf6733 Mon Sep 17 00:00:00 2001 From: Christophe Jelger Date: Mon, 28 Sep 2020 09:51:10 +0200 Subject: [PATCH 2/2] CIF-1638 - Add client-side support for staged catalog data - adapted storeconfigexporter to also properly work on launches --- .../StoreConfigExporterImpl.java | 10 +++++++++- .../StoreConfigExporterTest.java | 14 +++++++++++--- .../src/test/resources/context/jcr-content.json | 4 ++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/bundles/core/src/main/java/com/adobe/cq/commerce/core/components/internal/models/v1/storeconfigexporter/StoreConfigExporterImpl.java b/bundles/core/src/main/java/com/adobe/cq/commerce/core/components/internal/models/v1/storeconfigexporter/StoreConfigExporterImpl.java index e9d320e2e0..176068e6c6 100644 --- a/bundles/core/src/main/java/com/adobe/cq/commerce/core/components/internal/models/v1/storeconfigexporter/StoreConfigExporterImpl.java +++ b/bundles/core/src/main/java/com/adobe/cq/commerce/core/components/internal/models/v1/storeconfigexporter/StoreConfigExporterImpl.java @@ -18,10 +18,12 @@ import javax.inject.Inject; import org.apache.sling.api.SlingHttpServletRequest; +import org.apache.sling.api.resource.Resource; import org.apache.sling.models.annotations.Model; import com.adobe.cq.commerce.core.components.models.storeconfigexporter.StoreConfigExporter; import com.adobe.cq.commerce.core.components.services.ComponentsConfiguration; +import com.adobe.cq.wcm.launches.utils.LaunchUtils; import com.day.cq.wcm.api.Page; @Model( @@ -43,7 +45,13 @@ public class StoreConfigExporterImpl implements StoreConfigExporter { @PostConstruct void initModel() { - ComponentsConfiguration properties = currentPage.getContentResource().adaptTo(ComponentsConfiguration.class); + Resource pageContent = currentPage.getContentResource(); + ComponentsConfiguration properties = null; + if (LaunchUtils.isLaunchBasedPath(currentPage.getPath())) { + properties = LaunchUtils.getTargetResource(pageContent, null).adaptTo(ComponentsConfiguration.class); + } else { + properties = pageContent.adaptTo(ComponentsConfiguration.class); + } storeView = properties.get(STORE_CODE_PROPERTY, "default"); graphqlEndpoint = properties.get(GRAPHQL_ENDPOINT_PROPERTY, "/magento/graphql"); diff --git a/bundles/core/src/test/java/com/adobe/cq/commerce/core/components/internal/models/v1/storeconfigexporter/StoreConfigExporterTest.java b/bundles/core/src/test/java/com/adobe/cq/commerce/core/components/internal/models/v1/storeconfigexporter/StoreConfigExporterTest.java index 1a8bf9a1a9..615219fbe3 100644 --- a/bundles/core/src/test/java/com/adobe/cq/commerce/core/components/internal/models/v1/storeconfigexporter/StoreConfigExporterTest.java +++ b/bundles/core/src/test/java/com/adobe/cq/commerce/core/components/internal/models/v1/storeconfigexporter/StoreConfigExporterTest.java @@ -18,13 +18,14 @@ import org.apache.sling.api.resource.ValueMap; import org.apache.sling.api.scripting.SlingBindings; import org.apache.sling.api.wrappers.ValueMapDecorator; -import org.apache.sling.caconfig.ConfigurationBuilder; import org.apache.sling.testing.mock.sling.ResourceResolverType; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; +import com.adobe.cq.commerce.core.components.client.MockLaunch; import com.adobe.cq.commerce.core.components.services.ComponentsConfiguration; +import com.adobe.cq.launches.api.Launch; import com.day.cq.wcm.api.Page; import com.day.cq.wcm.scripting.WCMBindingsConstants; import com.google.common.base.Function; @@ -41,8 +42,6 @@ public class StoreConfigExporterTest { @Rule public final AemContext context = createContext("/context/jcr-content.json"); - private ConfigurationBuilder configurationBuilder; - private static AemContext createContext(String contentPath) { return new AemContext( (AemContextCallback) context -> { @@ -62,6 +61,15 @@ public void testStoreView() { Assert.assertEquals("my-magento-store", storeConfigExporter.getStoreView()); } + @Test + public void testStoreViewOnLaunchPage() { + context.registerAdapter(Resource.class, Launch.class, (Function) resource -> new MockLaunch(resource)); + + setupWithPage("/content/launches/2020/09/14/mylaunch/content/pageH"); + StoreConfigExporterImpl storeConfigExporter = context.request().adaptTo(StoreConfigExporterImpl.class); + Assert.assertEquals("my-magento-store", storeConfigExporter.getStoreView()); + } + @Test public void testStoreViewDefault() { setupWithPage("/content/pageD"); diff --git a/bundles/core/src/test/resources/context/jcr-content.json b/bundles/core/src/test/resources/context/jcr-content.json index 0146192753..0e22fe357a 100644 --- a/bundles/core/src/test/resources/context/jcr-content.json +++ b/bundles/core/src/test/resources/context/jcr-content.json @@ -235,6 +235,10 @@ } } } + }, + "pageH": { + "jcr:primaryType": "cq:Page", + "jcr:content": {} } } }