Skip to content

Commit c635a11

Browse files
authored
CIF-2720: improve linking to catalog specific product/category pages (#922)
* CIF-2289: create a v3 cif page * CIF-2289: fix navigation and breadcrumb * CIF-2720: support 1-many product/category pages per site * adding unit tests * improved unit tests * improved unit tests * improved unit tests * adapted breadcrumb * removed other usages of deprecated SiteNavigation * fix unit tests * fix ITs * fix ITs * pass the catalog page and navigation root page down stream * use urlPath as selection id for the root category in catalog page * Use catalog page setting in specific page test * support selection of search root with all parameters * get search results page only from navroot * refactored to make the site structure cacheable per request * adjusted breadcrumb to deal with catalog pages * move some logic from the url provider to the specific page strategy to reuse it * optimise breadcrumb link generation for product * sort imports * fix unit tests after merge * add deprecation notice * remove 'Magento' from the Catalogpage settings * simplified SiteStructure interface * CIF-2720: fix preview servlet
1 parent 4392f97 commit c635a11

92 files changed

Lines changed: 2468 additions & 774 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bundles/core/src/main/java/com/adobe/cq/commerce/core/components/internal/models/v1/breadcrumb/BreadcrumbImpl.java

Lines changed: 136 additions & 97 deletions
Large diffs are not rendered by default.

bundles/core/src/main/java/com/adobe/cq/commerce/core/components/internal/models/v1/breadcrumb/BreadcrumbRetriever.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.util.Collections;
1919
import java.util.List;
20+
import java.util.Optional;
2021

2122
import org.apache.commons.collections4.CollectionUtils;
2223

@@ -39,7 +40,7 @@
3940
class BreadcrumbRetriever extends AbstractRetriever {
4041

4142
private List<? extends CategoryInterface> categories;
42-
private String productName;
43+
private Optional<ProductInterface> product;
4344

4445
private String productIdentifier;
4546

@@ -69,11 +70,11 @@ protected List<? extends CategoryInterface> fetchCategoriesBreadcrumbs() {
6970
*
7071
* @return The product name.
7172
*/
72-
protected String fetchProductName() {
73-
if (productName == null) {
73+
protected ProductInterface fetchProduct() {
74+
if (product == null) {
7475
populate();
7576
}
76-
return productName;
77+
return product.orElse(null);
7778
}
7879

7980
/**
@@ -98,14 +99,16 @@ protected void setCategoryIdentifier(String categoryIdentifier) {
9899
@Override
99100
protected void populate() {
100101
if (productIdentifier == null && categoryIdentifier == null) {
102+
categories = Collections.emptyList();
103+
product = Optional.empty();
101104
return;
102105
}
103106

104107
GraphqlResponse<Query, Error> response = executeQuery();
105108

106109
if (CollectionUtils.isNotEmpty(response.getErrors())) {
107110
categories = Collections.emptyList();
108-
productName = null;
111+
product = Optional.empty();
109112
return;
110113
}
111114

@@ -117,9 +120,8 @@ protected void populate() {
117120
.getItems();
118121

119122
if (products.size() > 0) {
120-
ProductInterface product = products.get(0);
121-
productName = product.getName();
122-
categories = product.getCategories();
123+
product = Optional.of(products.get(0));
124+
categories = product.get().getCategories();
123125
}
124126
} else {
125127
categories = rootQuery.getCategoryList();
@@ -152,6 +154,8 @@ protected String generateProductQuery() {
152154
ProductsQueryDefinition queryArgs = q -> q.items(i -> i
153155
.sku()
154156
.urlKey()
157+
.urlPath()
158+
.urlRewrites(uq -> uq.url())
155159
.name()
156160
.categories(c -> c
157161
.uid()

bundles/core/src/main/java/com/adobe/cq/commerce/core/components/internal/models/v1/button/ButtonImpl.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import com.adobe.cq.commerce.core.components.services.urls.CategoryUrlFormat;
3939
import com.adobe.cq.commerce.core.components.services.urls.ProductUrlFormat;
4040
import com.adobe.cq.commerce.core.components.services.urls.UrlProvider;
41-
import com.adobe.cq.commerce.core.components.utils.SiteNavigation;
4241
import com.adobe.cq.commerce.magento.graphql.CategoryInterface;
4342
import com.adobe.cq.wcm.core.components.models.Button;
4443
import com.day.cq.wcm.api.Page;
@@ -106,8 +105,6 @@ public class ButtonImpl implements Button {
106105
@SlingObject
107106
protected Resource resource;
108107

109-
private Page productPage;
110-
private Page categoryPage;
111108
private String url;
112109

113110
@PostConstruct
@@ -121,14 +118,9 @@ private String assignUrl(final String linkType) {
121118
switch (linkType) {
122119
case PRODUCT: {
123120
if (!productSlug.equals(DEFAULT_LINK)) {
124-
productPage = SiteNavigation.getProductPage(currentPage);
125-
if (productPage == null) {
126-
productPage = currentPage;
127-
}
128-
129121
ProductUrlFormat.Params params = new ProductUrlFormat.Params();
130122
params.setUrlKey(productSlug);
131-
url = urlProvider.toProductUrl(request, productPage, params);
123+
url = urlProvider.toProductUrl(request, currentPage, params);
132124
} else {
133125
LOGGER.debug("Can not get Product Slug!");
134126
}
@@ -137,11 +129,6 @@ private String assignUrl(final String linkType) {
137129

138130
case CATEGORY: {
139131
if (!categoryId.equals(DEFAULT_LINK)) {
140-
categoryPage = SiteNavigation.getCategoryPage(currentPage);
141-
if (categoryPage == null) {
142-
categoryPage = currentPage;
143-
}
144-
145132
CategoryUrlFormat.Params params = null;
146133
if (magentoGraphqlClient != null) {
147134
CategoryRetriever categoryRetriever = new CategoryRetriever(magentoGraphqlClient);
@@ -151,7 +138,7 @@ private String assignUrl(final String linkType) {
151138
params = new CategoryUrlFormat.Params(category);
152139
}
153140
}
154-
url = urlProvider.toCategoryUrl(request, categoryPage, params != null ? params : new CategoryUrlFormat.Params());
141+
url = urlProvider.toCategoryUrl(request, currentPage, params != null ? params : new CategoryUrlFormat.Params());
155142
} else {
156143
LOGGER.debug("Can not get Category identifier!");
157144
}

bundles/core/src/main/java/com/adobe/cq/commerce/core/components/internal/models/v1/categorylist/FeaturedCategoryListImpl.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import com.adobe.cq.commerce.core.components.models.retriever.AbstractCategoriesRetriever;
5050
import com.adobe.cq.commerce.core.components.services.urls.CategoryUrlFormat;
5151
import com.adobe.cq.commerce.core.components.services.urls.UrlProvider;
52-
import com.adobe.cq.commerce.core.components.utils.SiteNavigation;
5352
import com.adobe.cq.commerce.magento.graphql.CategoryTree;
5453
import com.adobe.cq.export.json.ComponentExporter;
5554
import com.adobe.cq.export.json.ExporterConstants;
@@ -99,16 +98,10 @@ public class FeaturedCategoryListImpl extends DataLayerComponent implements Feat
9998
protected String linkTarget;
10099

101100
private Map<String, Asset> assetOverride;
102-
private Page categoryPage;
103101
private AbstractCategoriesRetriever categoriesRetriever;
104102

105103
@PostConstruct
106104
private void initModel() {
107-
categoryPage = SiteNavigation.getCategoryPage(currentPage);
108-
if (categoryPage == null) {
109-
categoryPage = currentPage;
110-
}
111-
112105
// Each identifier list will be held under a specific key
113106
// After the identifier type has been determined, the specific list will be used further
114107
List<String> categoryIdentifiers = new ArrayList<>();
@@ -162,7 +155,7 @@ public List<CategoryTree> getCategories() {
162155
List<CategoryTree> categories = categoriesRetriever.fetchCategories();
163156
for (CategoryTree category : categories) {
164157
CategoryUrlFormat.Params params = new CategoryUrlFormat.Params(category);
165-
category.setPath(urlProvider.toCategoryUrl(request, categoryPage, params));
158+
category.setPath(urlProvider.toCategoryUrl(request, currentPage, params));
166159

167160
// Replace image if there is an asset override
168161
String uid = category.getUid().toString();

bundles/core/src/main/java/com/adobe/cq/commerce/core/components/internal/models/v1/contentfragment/CommerceContentFragmentImpl.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@
4242

4343
import com.adobe.cq.commerce.core.components.client.MagentoGraphqlClient;
4444
import com.adobe.cq.commerce.core.components.internal.services.UrlProviderImpl;
45+
import com.adobe.cq.commerce.core.components.models.common.SiteStructure;
4546
import com.adobe.cq.commerce.core.components.models.contentfragment.CommerceContentFragment;
4647
import com.adobe.cq.commerce.core.components.services.urls.UrlProvider;
47-
import com.adobe.cq.commerce.core.components.utils.SiteNavigation;
4848
import com.adobe.cq.dam.cfm.content.FragmentRenderService;
4949
import com.adobe.cq.export.json.ComponentExporter;
5050
import com.adobe.cq.wcm.core.components.models.contentfragment.ContentFragment;
@@ -116,6 +116,9 @@ public class CommerceContentFragmentImpl implements CommerceContentFragment {
116116
@ValueMapValue(name = CommerceContentFragment.PN_LINK_ELEMENT, injectionStrategy = InjectionStrategy.OPTIONAL)
117117
private String linkElement;
118118

119+
@Self
120+
private SiteStructure siteStructure;
121+
119122
private ContentFragment contentFragment = EMPTY_CONTENT_FRAGMENT;
120123
private String modelTitle = "";
121124

@@ -162,9 +165,9 @@ private Resource findContentFragment() {
162165
}
163166

164167
String linkValue = null;
165-
if (SiteNavigation.isProductPage(currentPage)) {
168+
if (siteStructure.isProductPage(currentPage)) {
166169
linkValue = findProductSku();
167-
} else if (SiteNavigation.isCategoryPage(currentPage)) {
170+
} else if (siteStructure.isCategoryPage(currentPage)) {
168171
linkValue = findCategoryIdentifier();
169172
}
170173

bundles/core/src/main/java/com/adobe/cq/commerce/core/components/internal/models/v1/experiencefragment/CommerceExperienceFragmentImpl.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343
import org.slf4j.LoggerFactory;
4444

4545
import com.adobe.cq.commerce.core.components.client.MagentoGraphqlClient;
46+
import com.adobe.cq.commerce.core.components.models.common.SiteStructure;
4647
import com.adobe.cq.commerce.core.components.models.experiencefragment.CommerceExperienceFragment;
4748
import com.adobe.cq.commerce.core.components.services.urls.UrlProvider;
48-
import com.adobe.cq.commerce.core.components.utils.SiteNavigation;
4949
import com.day.cq.wcm.api.LanguageManager;
5050
import com.day.cq.wcm.api.Page;
5151
import com.day.cq.wcm.api.PageManager;
@@ -91,15 +91,18 @@ public class CommerceExperienceFragmentImpl implements CommerceExperienceFragmen
9191
@OSGiService
9292
private LiveRelationshipManager relationshipManager;
9393

94+
@Self
95+
private SiteStructure siteNavigation;
96+
9497
private Resource xfResource;
9598
private String name;
9699

97100
@PostConstruct
98101
private void initModel() {
99102
String query = null;
100-
if (SiteNavigation.isProductPage(currentPage)) {
103+
if (siteNavigation.isProductPage(currentPage)) {
101104
query = getQueryForProduct();
102-
} else if (SiteNavigation.isCategoryPage(currentPage)) {
105+
} else if (siteNavigation.isCategoryPage(currentPage)) {
103106
query = getQueryForCategory();
104107
}
105108

bundles/core/src/main/java/com/adobe/cq/commerce/core/components/internal/models/v1/header/HeaderImpl.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@
2222
import org.apache.sling.api.resource.Resource;
2323
import org.apache.sling.models.annotations.Model;
2424
import org.apache.sling.models.annotations.injectorspecific.ScriptVariable;
25+
import org.apache.sling.models.annotations.injectorspecific.Self;
2526
import org.apache.sling.models.annotations.injectorspecific.SlingObject;
2627
import org.slf4j.Logger;
2728
import org.slf4j.LoggerFactory;
2829

30+
import com.adobe.cq.commerce.core.components.models.common.SiteStructure;
2931
import com.adobe.cq.commerce.core.components.models.header.Header;
30-
import com.adobe.cq.commerce.core.components.utils.SiteNavigation;
3132
import com.day.cq.wcm.api.Page;
3233

3334
/**
@@ -53,11 +54,14 @@ public class HeaderImpl implements Header {
5354
@SlingObject
5455
private Resource resource;
5556

57+
@Self
58+
private SiteStructure siteStructure;
59+
5660
private Page navigationRootPage;
5761

5862
@PostConstruct
5963
private void initModel() {
60-
navigationRootPage = SiteNavigation.getNavigationRootPage(currentPage);
64+
navigationRootPage = siteStructure.getLandingPage();
6165

6266
if (navigationRootPage == null) {
6367
LOGGER.warn("Navigation root page not found for page " + currentPage.getPath());

bundles/core/src/main/java/com/adobe/cq/commerce/core/components/internal/models/v1/navigation/GraphQLCategoryProvider.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.Collections;
1919
import java.util.Comparator;
2020
import java.util.List;
21+
import java.util.function.BiFunction;
2122
import java.util.function.Function;
2223
import java.util.stream.Collectors;
2324

@@ -50,7 +51,16 @@ class GraphQLCategoryProvider {
5051
this.magentoGraphqlClient = magentoGraphqlClient;
5152
}
5253

53-
List<CategoryTree> getChildCategories(String categoryIdentifier, Integer depth) {
54+
List<CategoryTree> getChildCategoriesByUrlPath(String categoryIdentifier, Integer depth) {
55+
return getChildCategories(categoryIdentifier, depth, CategoryFilterInput::setUrlPath);
56+
}
57+
58+
List<CategoryTree> getChildCategoriesByUid(String categoryIdentifier, Integer depth) {
59+
return getChildCategories(categoryIdentifier, depth, CategoryFilterInput::setCategoryUid);
60+
}
61+
62+
private List<CategoryTree> getChildCategories(String categoryIdentifier, Integer depth,
63+
BiFunction<CategoryFilterInput, FilterEqualTypeInput, CategoryFilterInput> filter) {
5464
if (magentoGraphqlClient == null) {
5565
LOGGER.debug("No Graphql client present, cannot retrieve top categories");
5666
return Collections.emptyList();
@@ -61,9 +71,8 @@ List<CategoryTree> getChildCategories(String categoryIdentifier, Integer depth)
6171
return Collections.emptyList();
6272
}
6373

64-
QueryQuery.CategoryListArgumentsDefinition searchArgs = d -> d.filters(new CategoryFilterInput().setCategoryUid(
65-
new FilterEqualTypeInput().setEq(
66-
categoryIdentifier)));
74+
QueryQuery.CategoryListArgumentsDefinition searchArgs = d -> d.filters(
75+
filter.apply(new CategoryFilterInput(), new FilterEqualTypeInput().setEq(categoryIdentifier)));
6776

6877
String queryString = Operations.query(query -> query.categoryList(searchArgs, defineCategoriesQuery(depth))).toString();
6978
GraphqlResponse<Query, Error> response = magentoGraphqlClient.execute(queryString);

0 commit comments

Comments
 (0)