Skip to content

Commit

Permalink
CIF-1464 - The FeaturedCategoryList component does not use the UrlPro… (
Browse files Browse the repository at this point in the history
#309)

* CIF-1464 - The FeaturedCategoryList component does not use the UrlProvider service

- replaced hard-coded String format with urlProvider

* CIF-1464 - The FeaturedCategoryList component does not use the UrlProvider service

- also pass url_path to UrlProvider

Co-authored-by: Mark J. Becker <[email protected]>
  • Loading branch information
cjelger and herzog31 authored Jun 18, 2020
1 parent f374f88 commit 6356b21
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.Self;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.adobe.cq.commerce.core.components.client.MagentoGraphqlClient;
import com.adobe.cq.commerce.core.components.models.categorylist.FeaturedCategoryList;
import com.adobe.cq.commerce.core.components.models.retriever.AbstractCategoriesRetriever;
import com.adobe.cq.commerce.core.components.services.UrlProvider;
import com.adobe.cq.commerce.core.components.services.UrlProvider.ParamsBuilder;
import com.adobe.cq.commerce.core.components.utils.SiteNavigation;
import com.adobe.cq.commerce.magento.graphql.CategoryTree;
import com.day.cq.dam.api.Asset;
Expand Down Expand Up @@ -61,10 +64,14 @@ public class FeaturedCategoryListImpl implements FeaturedCategoryList {
@Inject
private Page currentPage;

private Map<String, Asset> assetOverride;
@Inject
private UrlProvider urlProvider;

private Page categoryPage;
@Self
private SlingHttpServletRequest request;

private Map<String, Asset> assetOverride;
private Page categoryPage;
private AbstractCategoriesRetriever categoriesRetriever;

@PostConstruct
Expand Down Expand Up @@ -120,7 +127,11 @@ public List<CategoryTree> getCategories() {
}
List<CategoryTree> categories = categoriesRetriever.fetchCategories();
for (CategoryTree category : categories) {
category.setPath(String.format("%s.%s.html", categoryPage.getPath(), category.getId()));
Map<String, String> params = new ParamsBuilder()
.id(category.getId().toString())
.urlPath(category.getUrlPath())
.map();
category.setPath(urlProvider.toCategoryUrl(request, categoryPage, params));

// Replace image if there is an asset override
String id = category.getId().toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
import org.junit.Test;
import org.mockito.Mockito;

import com.adobe.cq.commerce.core.components.internal.services.MockUrlProviderConfiguration;
import com.adobe.cq.commerce.core.components.internal.services.UrlProviderImpl;
import com.adobe.cq.commerce.core.components.services.UrlProvider;
import com.adobe.cq.commerce.core.components.testing.Utils;
import com.adobe.cq.commerce.graphql.client.GraphqlClient;
import com.adobe.cq.commerce.magento.graphql.CategoryTree;
Expand Down Expand Up @@ -201,6 +204,9 @@ public void verifyIgnoreInvalidAsset() {
private AemContext createContext(String contentPath) {
return new AemContext((AemContextCallback) context -> {
context.load().json(contentPath, "/content");
UrlProviderImpl urlProvider = new UrlProviderImpl();
urlProvider.activate(new MockUrlProviderConfiguration());
context.registerService(UrlProvider.class, urlProvider);
}, ResourceResolverType.JCR_MOCK);
}
}

0 comments on commit 6356b21

Please sign in to comment.