Skip to content

Commit

Permalink
Merge branch 'master' into issue/CIF-2827
Browse files Browse the repository at this point in the history
  • Loading branch information
buuhuu committed Jul 15, 2022
2 parents bd6a171 + daa88fa commit 962f798
Show file tree
Hide file tree
Showing 14 changed files with 242 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
resourceType = {
com.adobe.cq.commerce.core.components.internal.models.v1.product.ProductImpl.RESOURCE_TYPE,
com.adobe.cq.commerce.core.components.internal.models.v2.product.ProductImpl.RESOURCE_TYPE,
com.adobe.cq.commerce.core.components.internal.models.v1.productcollection.ProductCollectionImpl.RESOURCE_TYPE
com.adobe.cq.commerce.core.components.internal.models.v1.productcollection.ProductCollectionImpl.RESOURCE_TYPE,
com.adobe.cq.commerce.core.components.internal.models.v1.productcollection.ProductCollectionImpl.RESOURCE_TYPE_V2
})
public class CurrentPageImpl extends AbstractPageDelegator {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
public class ProductCollectionImpl extends DataLayerComponent implements ProductCollection {

public static final String RESOURCE_TYPE = "core/cif/components/commerce/productcollection/v1/productcollection";
public static final String RESOURCE_TYPE_V2 = "core/cif/components/commerce/productcollection/v2/productcollection";

protected static final boolean LOAD_CLIENT_PRICE_DEFAULT = true;
protected static final boolean ENABLE_ADD_TO_CART_DEFAULT = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@
@Model(
adaptables = SlingHttpServletRequest.class,
adapters = SearchResults.class,
resourceType = SearchResultsImpl.RESOURCE_TYPE)
resourceType = { SearchResultsImpl.RESOURCE_TYPE, SearchResultsImpl.RESOURCE_TYPE_V2 })
public class SearchResultsImpl extends ProductCollectionImpl implements SearchResults {
private static final Logger LOGGER = LoggerFactory.getLogger(SearchResultsImpl.class);
static final String RESOURCE_TYPE = "core/cif/components/commerce/searchresults";
static final String RESOURCE_TYPE = "core/cif/components/commerce/searchresults/v1/searchresults";
static final String RESOURCE_TYPE_V2 = "core/cif/components/commerce/searchresults/v2/searchresults";

private String searchTerm;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Copyright 2022 Adobe
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
package com.adobe.cq.commerce.core.components.internal.servlets;

import java.io.IOException;

import javax.servlet.Servlet;
import javax.servlet.ServletException;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.jetbrains.annotations.NotNull;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

import com.adobe.cq.commerce.core.components.internal.services.site.SiteStructureFactory;
import com.adobe.cq.commerce.core.components.models.common.SiteStructure;
import com.adobe.granite.ui.components.rendercondition.RenderCondition;
import com.adobe.granite.ui.components.rendercondition.SimpleRenderCondition;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageManager;

/**
* {@code ShowNavRootRenderConditionServlet} implements a {@code granite:rendercondition} used to determine if the navRoot option should be
* displayed on the properties page of a page.
*/
@Component(
service = { Servlet.class },
property = {
"sling.servlet.resourceTypes=" + ShowNavRootRenderConditionServlet.RESOURCE_TYPE,
"sling.servlet.methods=GET",
"sling.servlet.extensions=html"
})
public class ShowNavRootRenderConditionServlet extends SlingSafeMethodsServlet {
public final static String RESOURCE_TYPE = "core/cif/components/renderconditions/showNavRoot";

@Reference
private SiteStructureFactory siteStructureFactory;

@Override
protected void doGet(@NotNull SlingHttpServletRequest request, @NotNull SlingHttpServletResponse response)
throws ServletException, IOException {
request.setAttribute(RenderCondition.class.getName(), new SimpleRenderCondition(showNavRoot(request)));
}

private boolean showNavRoot(SlingHttpServletRequest request) {
PageManager pageManager = request.getResourceResolver().adaptTo(PageManager.class);
if (pageManager == null) {
return false;
}

String pagePath = request.getParameter("item");
Page page = pageManager.getPage(pagePath);
if (page == null) {
return false;
}

SiteStructure siteStructure = siteStructureFactory.getSiteStructure(page);
Page landingPage = siteStructure.getLandingPage();

// Show navRoot option if there is no landing page or if the current page is the landing page.
return landingPage == null || landingPage.equals(page);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Copyright 2022 Adobe
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
package com.adobe.cq.commerce.core.components.internal.servlets;

import java.io.IOException;

import javax.servlet.ServletException;

import org.apache.sling.api.resource.Resource;
import org.apache.sling.servlethelpers.MockSlingHttpServletRequest;
import org.apache.sling.servlethelpers.MockSlingHttpServletResponse;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import com.adobe.granite.ui.components.rendercondition.RenderCondition;
import com.adobe.granite.ui.components.rendercondition.SimpleRenderCondition;
import io.wcm.testing.mock.aem.junit.AemContext;

import static com.adobe.cq.commerce.core.testing.TestContext.newAemContext;
import static org.mockito.Mockito.mock;

public class ShowNavRootRenderConditionServletTest {

@Rule
public final AemContext context = newAemContext("/context/SiteStructureImplTest/jcr-content.json");

private MockSlingHttpServletRequest request;
private MockSlingHttpServletResponse response;
private ShowNavRootRenderConditionServlet servlet;

@Before
public void setUp() {
response = new MockSlingHttpServletResponse();
request = new MockSlingHttpServletRequest(context.resourceResolver());
Resource resource = mock(Resource.class);
request.setResource(resource);
request.setPathInfo("/mnt/overlay/wcm/core/content/sites/properties.html");

servlet = context.registerInjectActivateService(new ShowNavRootRenderConditionServlet());
}

@Test
public void testReturnsTrueForLandingPageEqualsPage() throws ServletException, IOException {
request.setQueryString("item=/content/nav-root");
servlet.doGet(request, response);

SimpleRenderCondition condition = (SimpleRenderCondition) request.getAttribute(RenderCondition.class.getName());
Assert.assertTrue(condition.check());
}

@Test
public void testReturnsTrueForNoLandingPage() throws ServletException, IOException {
request.setQueryString("item=/content/no-nav-root");
servlet.doGet(request, response);

SimpleRenderCondition condition = (SimpleRenderCondition) request.getAttribute(RenderCondition.class.getName());
Assert.assertTrue(condition.check());
}

@Test
public void testReturnsFalseForDefinedLandingPage() throws ServletException, IOException {
request.setQueryString("item=/content/nav-root/content-page");
servlet.doGet(request, response);

SimpleRenderCondition condition = (SimpleRenderCondition) request.getAttribute(RenderCondition.class.getName());
Assert.assertFalse(condition.check());
}

@Test
public void testReturnsFalseForInvalidPage() throws ServletException, IOException {
request.setQueryString("item=/content/does-not-exist");
servlet.doGet(request, response);

SimpleRenderCondition condition = (SimpleRenderCondition) request.getAttribute(RenderCondition.class.getName());
Assert.assertFalse(condition.check());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{
"sku": "24-WG080",
"__typename": "BundleProduct",
"uid": "Zm9vYmFy",
"name": "Sprite Yoga Companion Kit",
"dynamic_sku": true,
"dynamic_price": true,
Expand All @@ -30,6 +31,7 @@
"can_change_quantity": true,
"label": "Sprite Stasis Ball 55 cm",
"product": {
"uid": "MQ==",
"__typename": "SimpleProduct",
"price_range": {
"maximum_price": {
Expand All @@ -51,6 +53,7 @@
"can_change_quantity": true,
"label": "Sprite Stasis Ball 65 cm",
"product": {
"uid": "Mg==",
"__typename": "SimpleProduct",
"price_range": {
"maximum_price": {
Expand All @@ -72,6 +75,7 @@
"can_change_quantity": true,
"label": "Sprite Stasis Ball 75 cm",
"product": {
"uid": "Mw==",
"__typename": "SimpleProduct",
"price_range": {
"maximum_price": {
Expand Down Expand Up @@ -103,6 +107,7 @@
"can_change_quantity": true,
"label": "Sprite Foam Yoga Brick",
"product": {
"uid": "NA==",
"__typename": "SimpleProduct",
"price_range": {
"maximum_price": {
Expand Down Expand Up @@ -134,6 +139,7 @@
"can_change_quantity": true,
"label": "Sprite Yoga Strap 6 foot",
"product": {
"uid": "NQ==",
"__typename": "SimpleProduct",
"price_range": {
"maximum_price": {
Expand All @@ -155,6 +161,7 @@
"can_change_quantity": true,
"label": "Sprite Yoga Strap 8 foot",
"product": {
"uid": "Ng==",
"__typename": "SimpleProduct",
"price_range": {
"maximum_price": {
Expand All @@ -176,6 +183,7 @@
"can_change_quantity": true,
"label": "Sprite Yoga Strap 10 foot",
"product": {
"uid": "Nw==",
"__typename": "SimpleProduct",
"price_range": {
"maximum_price": {
Expand Down Expand Up @@ -207,6 +215,7 @@
"can_change_quantity": true,
"label": "Sprite Foam Roller",
"product": {
"uid": "OA==",
"__typename": "SimpleProduct",
"price_range": {
"maximum_price": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{
"__typename": "BundleProduct",
"sku": "24-WG080",
"uid": "Zm9vYmFy",
"staged": false,
"name": "Sprite Yoga Companion Kit",
"description": {
Expand Down
2 changes: 1 addition & 1 deletion react-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
},
"peerDependencies": {
"@apollo/client": "^3.1.2",
"@magento/peregrine": "^11.0.0",
"@magento/peregrine": "^11.0.0 || ~12.5.0",
"braintree-web-drop-in": "^1.22.1",
"graphql": "~15.3.0",
"informed": "~3.29.4",
Expand Down
5 changes: 5 additions & 0 deletions react-components/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,10 @@ export { useAddToCart, useAddToCartEvent } from './talons/Cart';
// new since CIF-2539
export { useAddToWishlistEvent } from './talons/Wishlist';

// new since CIF-2826
export { default as useCustomUrlEvent } from './utils/useCustomUrlEvent';
export { default as useReferrerEvent } from './utils/useReferrerEvent';
export { default as usePageEvent } from './utils/usePageEvent';

// new since CIF-2865
export { default as dataLayerUtils } from './utils/dataLayerUtils';
2 changes: 2 additions & 0 deletions react-components/src/queries/query_bundle_product.graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default gql`
sku
__typename
id
uid
name
... on BundleProduct {
dynamic_sku
Expand All @@ -46,6 +47,7 @@ export default gql`
can_change_quantity
label
product {
uid
price_range {
maximum_price {
final_price {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export default gql`
query giftCardProduct($sku: String!) {
products(filter: { sku: { eq: $sku } }) {
items {
id
uid
sku
__typename
name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
<categoryPageCondition jcr:primaryType="nt:unstructured"
sling:resourceType="core/cif/components/renderconditions/pagetype"
pageType="category"/>
<navRootCondition jcr:primaryType="nt:unstructured"
sling:resourceType="core/cif/components/renderconditions/showNavRoot"/>
</granite:rendercondition>
<items jcr:primaryType="nt:unstructured">
<products
Expand Down Expand Up @@ -130,8 +132,21 @@
jcr:primaryType="nt:unstructured"
sling:resourceType="core/cif/components/renderconditions/pagetype"
pageType="product"/>
<navRootCondition jcr:primaryType="nt:unstructured"
sling:resourceType="core/cif/components/renderconditions/showNavRoot"/>
</granite:rendercondition>
<items jcr:primaryType="nt:unstructured">
<navRoot
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
fieldDescription="Make this page the landing page of your site."
name="./navRoot"
text="Landing Page"
uncheckedValue="false"
value="true">
<granite:rendercondition jcr:primaryType="nt:unstructured"
sling:resourceType="core/cif/components/renderconditions/showNavRoot"/>
</navRoot>
<categoryFilter jcr:primaryType="nt:unstructured"
sling:resourceType="commerce/gui/components/common/cifcategoryfield"
fieldDescription="Category ids for which this page will be used."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
<categoryPageCondition jcr:primaryType="nt:unstructured"
sling:resourceType="core/cif/components/renderconditions/pagetype"
pageType="category"/>
<navRootCondition jcr:primaryType="nt:unstructured"
sling:resourceType="core/cif/components/renderconditions/showNavRoot"/>
</granite:rendercondition>
<items jcr:primaryType="nt:unstructured">
<products
Expand Down Expand Up @@ -154,8 +156,21 @@
jcr:primaryType="nt:unstructured"
sling:resourceType="core/cif/components/renderconditions/pagetype"
pageType="product"/>
<navRootCondition jcr:primaryType="nt:unstructured"
sling:resourceType="core/cif/components/renderconditions/showNavRoot"/>
</granite:rendercondition>
<items jcr:primaryType="nt:unstructured">
<navRoot
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
fieldDescription="Make this page the landing page of your site."
name="./navRoot"
text="Landing Page"
uncheckedValue="false"
value="true">
<granite:rendercondition jcr:primaryType="nt:unstructured"
sling:resourceType="core/cif/components/renderconditions/showNavRoot"/>
</navRoot>
<productFilter jcr:primaryType="nt:unstructured"
sling:resourceType="commerce/gui/components/common/cifproductfield"
fieldDescription="Product slugs for which this page will be used."
Expand Down
Loading

0 comments on commit 962f798

Please sign in to comment.