Skip to content

Commit bdd366a

Browse files
authored
CIF-2407: Add Wish List functionality (#775)
1 parent 3fbb7a3 commit bdd366a

75 files changed

Lines changed: 3098 additions & 439 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/client/MagentoGraphqlClientImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public MagentoGraphqlClientImpl(Resource resource, Page page, SlingHttpServletRe
104104
}
105105

106106
@PostConstruct
107-
protected void postConstruct() {
107+
protected void initModel() {
108108
if (currentPage == null) {
109109
currentPage = getPageFromResource(resource);
110110
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
~ Copyright 2021 Adobe
3+
~
4+
~ Licensed under the Apache License, Version 2.0 (the "License");
5+
~ you may not use this file except in compliance with the License.
6+
~ You may obtain a copy of the License at
7+
~
8+
~ http://www.apache.org/licenses/LICENSE-2.0
9+
~
10+
~ Unless required by applicable law or agreed to in writing, software
11+
~ distributed under the License is distributed on an "AS IS" BASIS,
12+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
~ See the License for the specific language governing permissions and
14+
~ limitations under the License.
15+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
16+
package com.adobe.cq.commerce.core.components.internal.models.v1.account;
17+
18+
import javax.annotation.PostConstruct;
19+
20+
import org.apache.sling.api.SlingHttpServletRequest;
21+
import org.apache.sling.models.annotations.Model;
22+
import org.apache.sling.models.annotations.injectorspecific.ScriptVariable;
23+
24+
import com.adobe.cq.commerce.core.components.internal.datalayer.DataLayerComponent;
25+
import com.adobe.cq.commerce.core.components.models.account.MiniAccount;
26+
import com.day.cq.wcm.api.designer.Style;
27+
28+
@Model(
29+
adaptables = SlingHttpServletRequest.class,
30+
adapters = MiniAccount.class,
31+
resourceType = MiniAccountImpl.RT_MINIACCOUNT_V2)
32+
public class MiniAccountImpl extends DataLayerComponent implements MiniAccount {
33+
34+
protected static final String RT_MINIACCOUNT_V2 = "core/cif/components/content/miniaccount/v2/miniaccount";
35+
protected static final String PN_STYLE_ENABLE_WISH_LIST = "enableWishList";
36+
37+
@ScriptVariable
38+
private Style currentStyle;
39+
40+
private boolean wishListEnabled;
41+
42+
@PostConstruct
43+
protected void initModel() {
44+
wishListEnabled = currentStyle.get(PN_STYLE_ENABLE_WISH_LIST, MiniAccount.super.getWishListEnabled());
45+
}
46+
47+
@Override
48+
public boolean getWishListEnabled() {
49+
return wishListEnabled;
50+
}
51+
}

bundles/core/src/main/java/com/adobe/cq/commerce/core/components/internal/models/v1/page/CurrentPageImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class CurrentPageImpl extends AbstractPageDelegator {
5858
private com.adobe.cq.wcm.core.components.models.Page delegate;
5959

6060
@PostConstruct
61-
protected void postConstruct() {
61+
protected void initModel() {
6262
delegate = modelFactory.getModelFromWrappedRequest(request, currentPage.getContentResource(), Page.class);
6363
request = null;
6464
}

bundles/core/src/main/java/com/adobe/cq/commerce/core/components/internal/models/v1/product/ProductImpl.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ public class ProductImpl extends DataLayerComponent implements Product {
108108
private static final Logger LOGGER = LoggerFactory.getLogger(ProductImpl.class);
109109
private static final boolean LOAD_CLIENT_PRICE_DEFAULT = true;
110110
private static final String SELECTION_PROPERTY = "selection";
111+
/**
112+
* Name of the boolean policy property indicating if the product component should show an add to wish list button or not.
113+
*/
114+
private static final String PN_STYLE_ENABLE_ADD_TO_WISHLIST = "enableAddToWishList";
111115

112116
@Self
113117
private SlingHttpServletRequest request;
@@ -141,6 +145,7 @@ public class ProductImpl extends DataLayerComponent implements Product {
141145
private boolean usePlaceholderData = false;
142146
private boolean isAuthor = true;
143147
private String canonicalUrl;
148+
private boolean enableAddToWishList;
144149

145150
protected AbstractProductRetriever productRetriever;
146151

@@ -187,6 +192,7 @@ protected void initModel() {
187192
}
188193

189194
locale = currentPage.getLanguage(false);
195+
enableAddToWishList = currentStyle.get(PN_STYLE_ENABLE_ADD_TO_WISHLIST, Product.super.getAddToWishListEnabled());
190196
}
191197

192198
@Override
@@ -544,4 +550,9 @@ public AssetData[] getDataLayerAssets() {
544550
public ProductStorefrontContext getStorefrontContext() {
545551
return new ProductStorefrontContextImpl(productRetriever.fetchProduct(), resource);
546552
}
553+
554+
@Override
555+
public boolean getAddToWishListEnabled() {
556+
return enableAddToWishList;
557+
}
547558
}

bundles/core/src/main/java/com/adobe/cq/commerce/core/components/internal/models/v1/productteaser/ProductTeaserImpl.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.sling.api.resource.ValueMap;
2727
import org.apache.sling.models.annotations.Exporter;
2828
import org.apache.sling.models.annotations.Model;
29+
import org.apache.sling.models.annotations.Via;
2930
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy;
3031
import org.apache.sling.models.annotations.injectorspecific.OSGiService;
3132
import org.apache.sling.models.annotations.injectorspecific.ScriptVariable;
@@ -54,6 +55,8 @@
5455
import com.adobe.cq.export.json.ExporterConstants;
5556
import com.adobe.cq.wcm.core.components.models.datalayer.ComponentData;
5657
import com.day.cq.wcm.api.Page;
58+
import com.day.cq.wcm.api.designer.Style;
59+
import com.day.cq.wcm.scripting.WCMBindingsConstants;
5760
import com.fasterxml.jackson.annotation.JsonIgnore;
5861

5962
@Model(
@@ -69,32 +72,31 @@ public class ProductTeaserImpl extends DataLayerComponent implements ProductTeas
6972
static final String CALL_TO_ACTION_TEXT_ADD_TO_CART = "Add to Cart";
7073

7174
protected static final String RESOURCE_TYPE = "core/cif/components/commerce/productteaser/v1/productteaser";
75+
protected static final String PN_STYLE_ADD_TO_WISHLIST_ENABLED = "enableAddToWishList";
76+
7277
private static final String SELECTION_PROPERTY = "selection";
7378

7479
@Self
7580
private SlingHttpServletRequest request;
76-
7781
@Self(injectionStrategy = InjectionStrategy.OPTIONAL)
7882
private MagentoGraphqlClient magentoGraphqlClient;
79-
8083
@ScriptVariable
8184
private Page currentPage;
82-
8385
@OSGiService
8486
private UrlProvider urlProvider;
85-
86-
@ScriptVariable
87+
@Self
88+
@Via("resource")
8789
private ValueMap properties;
88-
8990
@ValueMapValue(
9091
name = "cta",
9192
injectionStrategy = InjectionStrategy.OPTIONAL)
9293
private String cta;
93-
9494
@ValueMapValue(
9595
name = "ctaText",
9696
injectionStrategy = InjectionStrategy.OPTIONAL)
9797
private String ctaText;
98+
@ScriptVariable(name = WCMBindingsConstants.NAME_CURRENT_STYLE)
99+
private Style currentStyle;
98100

99101
private Page productPage;
100102
private Pair<String, String> combinedSku;
@@ -103,6 +105,7 @@ public class ProductTeaserImpl extends DataLayerComponent implements ProductTeas
103105
private Locale locale;
104106
private Boolean isVirtualProduct;
105107
private boolean ctaOverride;
108+
private boolean enableAddToWishList;
106109

107110
@PostConstruct
108111
protected void initModel() {
@@ -126,6 +129,8 @@ protected void initModel() {
126129
ctaOverride = CALL_TO_ACTION_TYPE_ADD_TO_CART.equals(cta) && !oneClickShoppable(getProduct());
127130
}
128131
}
132+
133+
enableAddToWishList = currentStyle.get(PN_STYLE_ADD_TO_WISHLIST_ENABLED, ProductTeaser.super.getAddToWishListEnabled());
129134
}
130135

131136
private boolean oneClickShoppable(ProductInterface product) {
@@ -264,6 +269,12 @@ public String getExportedType() {
264269
return RESOURCE_TYPE;
265270
}
266271

272+
@Override
273+
@JsonIgnore
274+
public boolean getAddToWishListEnabled() {
275+
return enableAddToWishList;
276+
}
277+
267278
// DataLayer methods
268279

269280
@Override
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
~ Copyright 2021 Adobe
3+
~
4+
~ Licensed under the Apache License, Version 2.0 (the "License");
5+
~ you may not use this file except in compliance with the License.
6+
~ You may obtain a copy of the License at
7+
~
8+
~ http://www.apache.org/licenses/LICENSE-2.0
9+
~
10+
~ Unless required by applicable law or agreed to in writing, software
11+
~ distributed under the License is distributed on an "AS IS" BASIS,
12+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
~ See the License for the specific language governing permissions and
14+
~ limitations under the License.
15+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
16+
package com.adobe.cq.commerce.core.components.models.account;
17+
18+
import org.osgi.annotation.versioning.ConsumerType;
19+
20+
import com.adobe.cq.wcm.core.components.models.Component;
21+
22+
@ConsumerType
23+
public interface MiniAccount extends Component {
24+
25+
/**
26+
* Returns {@code true} when the wish list is enabled and should be shown in the account drop down.
27+
*
28+
* @return {@code true} if the wish list is enabled, {@code false} otherwise
29+
*/
30+
default boolean getWishListEnabled() {
31+
return false;
32+
}
33+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
~ Copyright 2021 Adobe
3+
~
4+
~ Licensed under the Apache License, Version 2.0 (the "License");
5+
~ you may not use this file except in compliance with the License.
6+
~ You may obtain a copy of the License at
7+
~
8+
~ http://www.apache.org/licenses/LICENSE-2.0
9+
~
10+
~ Unless required by applicable law or agreed to in writing, software
11+
~ distributed under the License is distributed on an "AS IS" BASIS,
12+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
~ See the License for the specific language governing permissions and
14+
~ limitations under the License.
15+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
16+
@Version("1.0.0")
17+
package com.adobe.cq.commerce.core.components.models.account;
18+
19+
import org.osgi.annotation.versioning.Version;

bundles/core/src/main/java/com/adobe/cq/commerce/core/components/models/product/Product.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,13 @@ default Boolean isStaged() {
9494
* @return context of the product
9595
*/
9696
ProductStorefrontContext getStorefrontContext();
97+
98+
/**
99+
* Returns true when the Add to Wish List button is enabled.
100+
*
101+
* @return
102+
*/
103+
default boolean getAddToWishListEnabled() {
104+
return false;
105+
}
97106
}

bundles/core/src/main/java/com/adobe/cq/commerce/core/components/models/product/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
~ See the License for the specific language governing permissions and
1414
~ limitations under the License.
1515
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
16-
@Version("5.2.0")
16+
@Version("5.3.0")
1717
package com.adobe.cq.commerce.core.components.models.product;
1818

1919
import org.osgi.annotation.versioning.Version;

bundles/core/src/main/java/com/adobe/cq/commerce/core/components/models/productteaser/ProductTeaser.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1616
package com.adobe.cq.commerce.core.components.models.productteaser;
1717

18+
import org.osgi.annotation.versioning.ConsumerType;
19+
1820
import com.adobe.cq.commerce.core.components.models.common.CommerceIdentifier;
1921
import com.adobe.cq.commerce.core.components.models.common.Price;
2022
import com.adobe.cq.commerce.core.components.models.retriever.AbstractProductRetriever;
@@ -23,6 +25,7 @@
2325
/**
2426
* Product Teaser is the sling model interface for the CIF Teaser component.
2527
*/
28+
@ConsumerType
2629
public interface ProductTeaser extends Component {
2730

2831
/**
@@ -107,4 +110,13 @@ public interface ProductTeaser extends Component {
107110
*/
108111
AbstractProductRetriever getProductRetriever();
109112

113+
/**
114+
* Returns true when the Add to Wish List button is enabled.
115+
*
116+
* @return
117+
*/
118+
default boolean getAddToWishListEnabled() {
119+
return false;
120+
}
121+
110122
}

0 commit comments

Comments
 (0)