Skip to content
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 @@ -268,10 +268,10 @@ public List<NavigationItem> getItems() {

List<NavigationItem> pages = new ArrayList<>();

String categoryPagePath = categoryPage.getPath();
SiteNavigation siteNavigation = new SiteNavigation(request);
for (CategoryTree child : children) {
String title = child.getName();
String url = categoryPagePath + "." + child.getId() + ".html";
String url = siteNavigation.toPageUrl(categoryPage, child.getId().toString());
boolean active = request.getRequestURI().equals(url);
pages.add(new CategoryNavigationItem(this, title, url, active, child, request, categoryPage));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.Optional;
import org.apache.sling.models.annotations.injectorspecific.Self;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -51,6 +52,9 @@ public class ProductCarouselImpl implements ProductCarousel {
protected static final String RESOURCE_TYPE = "core/cif/components/commerce/productcarousel/v1/productcarousel";
private static final Logger LOGGER = LoggerFactory.getLogger(ProductCarouselImpl.class);

@Self
private SlingHttpServletRequest request;

@Inject
private Resource resource;

Expand Down Expand Up @@ -130,7 +134,8 @@ public List<ProductListItem> getProducts() {
product.getPrice().getRegularPrice().getAmount().getCurrency().toString(),
product.getThumbnail().getUrl(),
productPage,
skus.getRight()));
skus.getRight(),
request));
}
}
return carouselProductList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ public Collection<ProductListItem> getProducts() {
product.getPrice().getRegularPrice().getAmount().getCurrency().toString(),
product.getSmallImage().getUrl(),
productPage,
null));
null,
request));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import javax.annotation.Nullable;

import org.apache.sling.api.SlingHttpServletRequest;

import com.adobe.cq.commerce.core.components.internal.models.v1.Utils;
import com.adobe.cq.commerce.core.components.models.productlist.ProductListItem;
import com.adobe.cq.commerce.core.components.utils.SiteNavigation;
Expand All @@ -33,12 +35,13 @@ public class ProductListItemImpl implements ProductListItem {
private final Double price;
private final String currency;
private final String activeVariantSku;
private final SiteNavigation siteNavigation;

private NumberFormat priceFormatter;
private Page productPage;

public ProductListItemImpl(String sku, String slug, String name, Double price, String currency, String imageURL, Page productPage,
String activeVariantSku) {
String activeVariantSku, SlingHttpServletRequest request) {
this.sku = sku;
this.slug = slug;
this.name = name;
Expand All @@ -47,6 +50,7 @@ public ProductListItemImpl(String sku, String slug, String name, Double price, S
this.currency = currency;
this.productPage = productPage;
this.activeVariantSku = activeVariantSku;
this.siteNavigation = new SiteNavigation(request);

// Initialize NumberFormatter with locale from current page.
// Alternatively, the locale can potentially be retrieved via
Expand Down Expand Up @@ -74,7 +78,7 @@ public String getImageURL() {
@Nullable
@Override
public String getURL() {
return SiteNavigation.toProductUrl(productPage.getPath(), this.getSlug(), activeVariantSku);
return siteNavigation.toProductUrl(productPage, this.getSlug(), activeVariantSku);
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.ScriptVariable;
import org.apache.sling.models.annotations.injectorspecific.Self;

import com.adobe.cq.commerce.core.components.client.MagentoGraphqlClient;
import com.adobe.cq.commerce.core.components.internal.models.v1.Utils;
Expand All @@ -46,6 +47,9 @@ public class ProductTeaserImpl implements ProductTeaser {
protected static final String RESOURCE_TYPE = "core/cif/components/commerce/productteaser/v1/productteaser";
private static final String SELECTION_PROPERTY = "selection";

@Self
private SlingHttpServletRequest request;

@Inject
private Resource resource;

Expand Down Expand Up @@ -125,7 +129,8 @@ public String getFormattedPrice() {
public String getUrl() {
if (getProduct() != null) {
// Get slug from base product
return SiteNavigation.toProductUrl(productPage.getPath(), productRetriever.fetchProduct().getUrlKey(), combinedSku.getRight());
SiteNavigation siteNavigation = new SiteNavigation(request);
return siteNavigation.toProductUrl(productPage, productRetriever.fetchProduct().getUrlKey(), combinedSku.getRight());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ public List<ProductListItem> getProducts() {
product.getPrice().getRegularPrice().getAmount().getCurrency().toString(),
product.getThumbnail().getUrl(),
productPage,
null));
null,
request));
}
return carouselProductList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ protected ProductListItem generateItemFromProductInterface(ProductInterface prod
product.getSmallImage()
.getUrl(),
productPage,
null);
null,
request);

return productListItem;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import javax.annotation.Nonnull;

import org.apache.sling.api.SlingHttpServletRequest;

import com.adobe.cq.commerce.core.components.utils.SiteNavigation;
import com.adobe.cq.wcm.core.components.models.ListItem;
import com.day.cq.wcm.api.Page;
Expand All @@ -25,11 +27,13 @@ public class CommerceTeaserActionItem implements ListItem {
private String title;
private String selector = "";
private Page page = null;
private final SiteNavigation siteNavigation;

public CommerceTeaserActionItem(String title, String selector, Page page) {
public CommerceTeaserActionItem(String title, String selector, Page page, SlingHttpServletRequest request) {
this.title = title;
this.selector = selector;
this.page = page;
this.siteNavigation = new SiteNavigation(request);
}

@Nonnull
Expand All @@ -42,6 +46,6 @@ public String getTitle() {
@Override
public String getURL() {
return (selector == null || selector.trim().equalsIgnoreCase("")) ? (page.getPath() + ".html")
: SiteNavigation.toProductUrl(page.getPath(), selector);
: siteNavigation.toPageUrl(page, selector);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ void initModel() {

if (actionsEnabled) {
populateActions();
if (actions.size() > 0) {
ListItem firstAction = actions.get(0);
}
}
}

Expand Down Expand Up @@ -95,7 +92,7 @@ void populateActions() {
page = currentPage;

}
actions.add(new CommerceTeaserActionItem(title, selector, page));
actions.add(new CommerceTeaserActionItem(title, selector, page, request));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package com.adobe.cq.commerce.core.components.internal.servlets;

import java.io.IOException;
import java.util.Iterator;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
Expand All @@ -25,16 +24,15 @@
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.metatype.annotations.Designate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.day.cq.commons.jcr.JcrConstants;
import com.day.cq.wcm.api.NameConstants;
import com.adobe.cq.commerce.core.components.utils.SiteNavigation;
import com.day.cq.wcm.api.WCMMode;

@Component(
property = {
Expand All @@ -47,8 +45,6 @@ public class SpecificPageFilterFactory implements Filter {

private static final Logger LOGGER = LoggerFactory.getLogger(SpecificPageFilterFactory.class);

private static final String SELECTOR_FILTER_PROPERTY = "selectorFilter";

@Override
public void init(FilterConfig filterConfig) throws ServletException {}

Expand All @@ -63,35 +59,21 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
return;
}

// Skip filter on AEM author
WCMMode wcmMode = WCMMode.fromRequest(request);
if (!WCMMode.DISABLED.equals(wcmMode)) {
chain.doFilter(request, response);
return;
}

Resource page = slingRequest.getResource();
LOGGER.debug("Checking sub-pages for {}", slingRequest.getRequestURI());

Iterator<Resource> children = page.listChildren();
while (children.hasNext()) {
Resource child = children.next();
if (!NameConstants.NT_PAGE.equals(child.getResourceType())) {
continue;
}

Resource jcrContent = child.getChild(JcrConstants.JCR_CONTENT);
if (jcrContent == null) {
continue;
}

Object filter = jcrContent.getValueMap().get(SELECTOR_FILTER_PROPERTY);
if (filter == null) {
continue;
}

// The property is saved as a String when it's a simple selection, or an array when a multi-selection is done
String[] selectors = filter.getClass().isArray() ? ((String[]) filter) : ArrayUtils.toArray((String) filter);

if (ArrayUtils.contains(selectors, selector)) {
LOGGER.debug("Page has a matching sub-page for selector {} at {}", selector, child.getPath());
RequestDispatcher dispatcher = slingRequest.getRequestDispatcher(child);
dispatcher.forward(slingRequest, response);
return;
}
Resource subPage = SiteNavigation.toSpecificPage(page, selector);
if (subPage != null) {
RequestDispatcher dispatcher = slingRequest.getRequestDispatcher(subPage);
dispatcher.forward(slingRequest, response);
return;
}

chain.doFilter(request, response);
Expand Down
Loading