This is an automated email from the ASF dual-hosted git repository. nmalin pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/trunk by this push: new b9c8938 Fixed: ShoppingCart object does not recognize two products with different configurations (OFBIZ-12303) b9c8938 is described below commit b9c8938bc13d28d2a8eaaad33856172f3c901803 Author: Nicolas Malin <nicolas.ma...@nereide.fr> AuthorDate: Tue Sep 28 17:17:17 2021 +0200 Fixed: ShoppingCart object does not recognize two products with different configurations (OFBIZ-12303) By adding two equal products with different configurations in eCommerce cart it results in qty aggregation instead of adding 2 separate cart lines. When we added a new configuration in cart, we analyze all configuration options already present to know if this configuration case is alredy load and merge the quantity added. Thanks: Alexander Tzvetanov for raise this issue --- .../ofbiz/product/config/ProductConfigWrapper.java | 23 ++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/applications/product/src/main/java/org/apache/ofbiz/product/config/ProductConfigWrapper.java b/applications/product/src/main/java/org/apache/ofbiz/product/config/ProductConfigWrapper.java index cdf1c19..e1ba46b 100644 --- a/applications/product/src/main/java/org/apache/ofbiz/product/config/ProductConfigWrapper.java +++ b/applications/product/src/main/java/org/apache/ofbiz/product/config/ProductConfigWrapper.java @@ -31,6 +31,7 @@ import java.util.Map; import java.util.Objects; import java.util.Set; +import java.util.stream.Collectors; import org.apache.ofbiz.base.util.Debug; import org.apache.ofbiz.base.util.GeneralException; import org.apache.ofbiz.base.util.UtilMisc; @@ -694,6 +695,22 @@ public class ProductConfigWrapper implements Serializable { return null; } + private boolean isConfigOptionsSelectionEqual(ConfigItem other) { + List<ConfigOption> mineOptions = getOptions().stream().filter(x -> x.isSelected()).collect(Collectors.toList()); + List<ConfigOption> otherOptions = other.getOptions().stream().filter(x -> x.isSelected()).collect(Collectors.toList()); + + if (otherOptions != null && mineOptions != null + && otherOptions.size() != mineOptions.size()) { + return false; + } + for (int i = 0; i < mineOptions.size(); i++) { + if (!mineOptions.get(i).equals(otherOptions.get(i))) { + return false; + } + } + return true; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -701,7 +718,7 @@ public class ProductConfigWrapper implements Serializable { ConfigItem that = (ConfigItem) o; return Objects.equals(getConfigItem(), that.getConfigItem()) && Objects.equals(getConfigItemAssoc(), that.getConfigItemAssoc()) - && Objects.equals(getOptions(), that.getOptions()); + && isConfigOptionsSelectionEqual(that); } @Override @@ -1074,7 +1091,9 @@ public class ProductConfigWrapper implements Serializable { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; ConfigOption that = (ConfigOption) o; - return Objects.equals(availabilityDate, that.availabilityDate) + return that.getId() == getId() + && that.isSelected() == isSelected() + && Objects.equals(availabilityDate, that.availabilityDate) && Objects.equals(componentList, that.componentList) && Objects.equals(getComponentOptions(), that.getComponentOptions()) && Objects.equals(configOption, that.configOption);