Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CIF-1638 - Add client-side support for staged catalog data #407

Merged
merged 3 commits into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -287,7 +288,7 @@ public List<VariantAttribute> getVariantAttributes() {

@Override
public Boolean loadClientPrice() {
return loadClientPrice;
return loadClientPrice && !LaunchUtils.isLaunchBasedPath(currentPage.getPath());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -94,7 +95,7 @@ public Integer calculateCurrentPageCursor(final String currentPageIndexCandidate

@Override
public boolean loadClientPrice() {
return loadClientPrice;
return loadClientPrice && !LaunchUtils.isLaunchBasedPath(currentPage.getPath());
}

protected Map<String, String> createFilterMap(final Map<String, String[]> parameterMap) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 -> {
Expand All @@ -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, Launch>) 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");
Expand Down
4 changes: 4 additions & 0 deletions bundles/core/src/test/resources/context/jcr-content.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@
}
}
}
},
"pageH": {
"jcr:primaryType": "cq:Page",
"jcr:content": {}
}
}
}
Expand Down