Skip to content

Commit

Permalink
2.0.0 ee (#584)
Browse files Browse the repository at this point in the history
* CIF-1964 - Show staged flag in product component (#510)

* introduce product v2 for 'staged' Magento field
* adapt unit tests for component v2
* ensure the product and variant queries can be extended "multiple times"
* add @SInCE annotation to product interface
* add readme
* update Magento schema to 2.4.2 EE
* add mandatory "staged" field to the mock JSON responses
* extend unit tests to test both product v1 and v2 components
* fix POM dependencies and remove no longer needed picker implementation

Co-authored-by: Levente Santha <levente@adobe.com>

* CIF-1965 - Show staged flag in productlist component (#519)

* create productlist v2 component
* update unit tests and GraphQL mock server for Venia ITs

* CIF-1964 - Show staged flag in product component (#510)

* introduce product v2 for 'staged' Magento field
* adapt unit tests for component v2
* ensure the product and variant queries can be extended "multiple times"
* add @SInCE annotation to product interface
* add readme
* update Magento schema to 2.4.2 EE
* add mandatory "staged" field to the mock JSON responses
* extend unit tests to test both product v1 and v2 components
* fix POM dependencies and remove no longer needed picker implementation

Co-authored-by: Levente Santha <levente@adobe.com>

* CIF-1965 - Show staged flag in productlist component (#519)

* create productlist v2 component
* update unit tests and GraphQL mock server for Venia ITs

* trivial - update on lastest master branch, fix failing tests

* trivial - update on lastest master branch, fix failing tests

* CIF-1965 - fix test and cleanup test data

* CIF-1965 - fix failing example tests

* CIF-1965 - fix failing ITs

* trivial - fix baseline check

Co-authored-by: Christophe Jelger <jelger@adobe.com>
Co-authored-by: Levente Santha <levente@adobe.com>
  • Loading branch information
3 people authored Jun 21, 2021
1 parent 38c3ae6 commit 6907ca9
Show file tree
Hide file tree
Showing 48 changed files with 753 additions and 127 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ See our [wiki](https://github.com/adobe/aem-core-cif-components/wiki) for usage

## Available Components

- [Product](ui.apps/src/main/content/jcr_root/apps/core/cif/components/commerce/product/v1/product)
- [Product List](ui.apps/src/main/content/jcr_root/apps/core/cif/components/commerce/productlist/v1/productlist)
- [Product v1](ui.apps/src/main/content/jcr_root/apps/core/cif/components/commerce/product/v1/product)
- [Product v2](ui.apps/src/main/content/jcr_root/apps/core/cif/components/commerce/product/v2/product) - Magento EE only with version >= 2.4.2
- [Product List v1](ui.apps/src/main/content/jcr_root/apps/core/cif/components/commerce/productlist/v1/productlist)
- [Product List v2](ui.apps/src/main/content/jcr_root/apps/core/cif/components/commerce/productlist/v2/productlist) - Magento EE only with version >= 2.4.2
- [Product Teaser](ui.apps/src/main/content/jcr_root/apps/core/cif/components/commerce/productteaser/v1/productteaser)
- [Product Carousel](ui.apps/src/main/content/jcr_root/apps/core/cif/components/commerce/productcarousel/v1/productcarousel)
- [Related Products](ui.apps/src/main/content/jcr_root/apps/core/cif/components/commerce/relatedproducts/v1/relatedproducts)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ public class ProductListItemImpl extends DataLayerListItem implements ProductLis
private SlingHttpServletRequest request;
private UrlProvider urlProvider;
private CommerceIdentifier identifier;
private Boolean isStaged;

public ProductListItemImpl(String sku, String slug, String name, Price price, String imageURL, Page productPage,
String activeVariantSku, SlingHttpServletRequest request, UrlProvider urlProvider, String parentId) {
String activeVariantSku, SlingHttpServletRequest request, UrlProvider urlProvider, String parentId,
Boolean isStaged) {
super(parentId, productPage.getContentResource());
this.sku = sku;
this.slug = slug;
Expand All @@ -58,6 +60,7 @@ public ProductListItemImpl(String sku, String slug, String name, Price price, St
this.activeVariantSku = activeVariantSku;
this.request = request;
this.urlProvider = urlProvider;
this.isStaged = isStaged;
}

public ProductListItemImpl(CommerceIdentifier identifier, String parentId, Page productPage) {
Expand Down Expand Up @@ -143,6 +146,12 @@ public Price getPriceRange() {
return price;
}

@Override
@JsonIgnore
public Boolean isStaged() {
return Boolean.TRUE.equals(isStaged);
}

// DataLayer methods

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ public class ProductImpl extends DataLayerComponent implements Product {
private Boolean loadClientPrice;
private String canonicalUrl;

private AbstractProductRetriever productRetriever;
protected AbstractProductRetriever productRetriever;

private Locale locale;

@PostConstruct
private void initModel() {
protected void initModel() {
// Get product selection from dialog
String selection = properties.get(SELECTION_PROPERTY, String.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ public List<ProductListItem> getProducts() {
skus.getRight(),
request,
urlProvider,
this.getId()));
this.getId(),
product.getStaged()));
} catch (Exception e) {
LOGGER.error("Failed to instantiate product " + combinedSku, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ public class ProductListImpl extends ProductCollectionImpl implements ProductLis
@ScriptVariable(name = "wcmmode", injectionStrategy = InjectionStrategy.OPTIONAL)
private SightlyWCMMode wcmMode = null;

private AbstractCategoryRetriever categoryRetriever;
protected AbstractCategoryRetriever categoryRetriever;
private boolean usePlaceholderData;
private String canonicalUrl;

private Pair<CategoryInterface, SearchResultsSet> categorySearchResultsSet;

@PostConstruct
private void initModel() {
protected void initModel() {
// read properties
showTitle = properties.get(PN_SHOW_TITLE, currentStyle.get(PN_SHOW_TITLE, SHOW_TITLE_DEFAULT));
showImage = properties.get(PN_SHOW_IMAGE, currentStyle.get(PN_SHOW_IMAGE, SHOW_IMAGE_DEFAULT));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public List<ProductListItem> getProducts() {
Price price = new PriceImpl(product.getPriceRange(), locale);
carouselProductList.add(new ProductListItemImpl(product.getSku(), product.getUrlKey(),
product.getName(), price, product.getThumbnail().getUrl(), productPage, null, request,
urlProvider, this.getId()));
urlProvider, this.getId(), product.getStaged()));
} catch (Exception e) {
LOGGER.error("Failed to instantiate product " + (product != null ? product.getSku() : null), e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*******************************************************************************
*
* Copyright 2021 Adobe. All rights reserved.
* This file is licensed to you 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 REPRESENTATIONS
* 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.models.v2.product;

import javax.annotation.PostConstruct;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.models.annotations.Model;

import com.adobe.cq.commerce.core.components.models.product.Product;
import com.adobe.cq.commerce.magento.graphql.ConfigurableProduct;
import com.adobe.cq.commerce.magento.graphql.GroupedProduct;
import com.adobe.cq.commerce.magento.graphql.ProductInterface;

@Model(
adaptables = SlingHttpServletRequest.class,
adapters = Product.class,
resourceType = ProductImpl.RESOURCE_TYPE,
cache = true)
public class ProductImpl extends com.adobe.cq.commerce.core.components.internal.models.v1.product.ProductImpl implements Product {

public static final String RESOURCE_TYPE = "core/cif/components/commerce/product/v2/product";

@PostConstruct
protected void initModel() {
super.initModel();
if (productRetriever != null) {
productRetriever.extendProductQueryWith(p -> p.staged());
productRetriever.extendVariantQueryWith(v -> v.staged());
}
}

@Override
public Boolean isStaged() {
// A product is considered "staged" if the product itself or one of its variant or item is "staged"
ProductInterface product = productRetriever.fetchProduct();
if (Boolean.TRUE.equals(product.getStaged())) {
return true;
} else if (isConfigurable()) {
ConfigurableProduct cp = (ConfigurableProduct) product;
return cp.getVariants().stream().anyMatch(v -> Boolean.TRUE.equals(v.getProduct().getStaged()));
} else if (isGroupedProduct()) {
GroupedProduct gp = (GroupedProduct) product;
return gp.getItems().stream().anyMatch(i -> Boolean.TRUE.equals(i.getProduct().getStaged()));
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*******************************************************************************
*
* Copyright 2021 Adobe. All rights reserved.
* This file is licensed to you 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 REPRESENTATIONS
* 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.models.v2.productlist;

import javax.annotation.PostConstruct;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.models.annotations.Model;

import com.adobe.cq.commerce.core.components.models.productlist.ProductList;

@Model(
adaptables = SlingHttpServletRequest.class,
adapters = ProductList.class,
resourceType = ProductListImpl.RESOURCE_TYPE,
cache = true)
public class ProductListImpl extends com.adobe.cq.commerce.core.components.internal.models.v1.productlist.ProductListImpl implements
ProductList {

public static final String RESOURCE_TYPE = "core/cif/components/commerce/productlist/v2/productlist";

@PostConstruct
protected void initModel() {
super.initModel();
if (categoryRetriever != null) {
categoryRetriever.extendCategoryQueryWith(c -> c.staged());
categoryRetriever.extendProductQueryWith(p -> p.staged());
}
}

@Override
public Boolean isStaged() {
return getCategory() != null ? Boolean.TRUE.equals(getCategory().getStaged()) : false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,12 @@ default String getFormattedPrice() {
* @return Price range instance.
*/
Price getPriceRange();

/**
* @return <code>true</code> if the product data contains staged changes, <code>false</code> otherwise.
* @since com.adobe.cq.commerce.core.components.models.common 1.9.0
*/
default Boolean isStaged() {
return false;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
******************************************************************************/

@Version("1.8.0")
@Version("1.9.0")
package com.adobe.cq.commerce.core.components.models.common;

import org.osgi.annotation.versioning.Version;
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ public interface Product extends Component, PageMetadata {

Boolean isBundleProduct();

/**
* The version 1 of the product component always returns <code>false</code> as it does not support this feature.
* The version 2 of the product component does support this feature but it requires a Magento EE instance with
* at least Magento version 2.4.2.
*
* @return <code>true</code> if the product data contains staged changes, <code>false</code> otherwise.
* @since com.adobe.cq.commerce.core.components.models.product 3.1.0
*/
default Boolean isStaged() {
return false;
};

String getVariantsJson();

List<Variant> getVariants();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
******************************************************************************/

@Version("4.0.0")
@Version("4.1.0")
package com.adobe.cq.commerce.core.components.models.product;

import org.osgi.annotation.versioning.Version;
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,17 @@ public interface ProductList extends Component, ProductCollection, PageMetadata
*/
AbstractCategoryRetriever getCategoryRetriever();

/**
* The version 1 of the productlist component always returns <code>false</code> as it does not support this feature.
* The version 2 of the productlist component does support this feature but it requires a Magento EE instance with
* at least Magento version 2.4.2.
*
* @return <code>true</code> if the product data contains staged changes, <code>false</code> otherwise.
* @since com.adobe.cq.commerce.core.components.models.productlist 3.2.0
*/
default Boolean isStaged() {
return false;
};

CategoryStorefrontContext getStorefrontContext();
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
******************************************************************************/

@Version("4.0.0")
@Version("4.1.0")
package com.adobe.cq.commerce.core.components.models.productlist;

import org.osgi.annotation.versioning.Version;
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,16 @@ public void setIdentifier(CategoryIdentifierType categoryIdentifierType, String
* }
* </pre>
*
* If called multiple times, each hook will be "appended" to the previously registered hook(s).
*
* @param categoryQueryHook Lambda that extends the category query
*/
public void extendCategoryQueryWith(Consumer<CategoryTreeQuery> categoryQueryHook) {
this.categoryQueryHook = categoryQueryHook;
if (this.categoryQueryHook == null) {
this.categoryQueryHook = categoryQueryHook;
} else {
this.categoryQueryHook = this.categoryQueryHook.andThen(categoryQueryHook);
}
}

/**
Expand All @@ -213,10 +219,16 @@ public Consumer<CategoryTreeQuery> getCategoryQueryHook() {
* }
* </pre>
*
* If called multiple times, each hook will be "appended" to the previously registered hook(s).
*
* @param productQueryHook Lambda that extends the product query
*/
public void extendProductQueryWith(Consumer<ProductInterfaceQuery> productQueryHook) {
this.productQueryHook = productQueryHook;
if (this.productQueryHook == null) {
this.productQueryHook = productQueryHook;
} else {
this.productQueryHook = this.productQueryHook.andThen(productQueryHook);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,16 @@ public void setIdentifier(ProductIdentifierType productIdentifierType, String id
* }
* </pre>
*
* If called multiple times, each hook will be "appended" to the previously registered hook(s).
*
* @param productQueryHook Lambda that extends the product query
*/
public void extendProductQueryWith(Consumer<ProductInterfaceQuery> productQueryHook) {
this.productQueryHook = productQueryHook;
if (this.productQueryHook == null) {
this.productQueryHook = productQueryHook;
} else {
this.productQueryHook = this.productQueryHook.andThen(productQueryHook);
}
}

/**
Expand All @@ -156,10 +162,16 @@ public void extendProductQueryWith(Consumer<ProductInterfaceQuery> productQueryH
* }
* </pre>
*
* If called multiple times, each hook will be "appended" to the previously registered hook(s).
*
* @param variantQueryHook Lambda that extends the product variant query
*/
public void extendVariantQueryWith(Consumer<SimpleProductQuery> variantQueryHook) {
this.variantQueryHook = variantQueryHook;
if (this.variantQueryHook == null) {
this.variantQueryHook = variantQueryHook;
} else {
this.variantQueryHook = this.variantQueryHook.andThen(variantQueryHook);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public ProductListItem apply(final ProductInterface product) {
null, // search results aren't targeting specific variant
request,
urlProvider,
parentId);
parentId,
product.getStaged());

return productListItem;
} catch (Exception e) {
Expand Down
Loading

0 comments on commit 6907ca9

Please sign in to comment.