Details
Description
By adding two equal products with different configurations in eCommerce cart it results in qty aggregation instead of adding 2 separate cart lines.
This is very easy to reproduce in Ofbiz demo site.
1. Select PC configuration as it is by default with 2 GB memory;
2. Add it to cart;
3. Change a little PC's - i.e. with different memory (1 GB);
4. Add to cart again.
In result of that in the cart appears the first config with 2 GB twice. The correct behavior is to add 2 different cart lines with 2 different prices.
I found that the issue is in the class ConfigItem - equals method.
In my site I've done a quick fix. I am attaching my code to this bug only for demonstration of the problem.
Please apply fix for the next Ofbiz version.
applications/product/src/main/java/org/apache/ofbiz/product/config/ProductConfigWrapper.java Original code: @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; ConfigItem that = (ConfigItem) o; return Objects.equals(getConfigItem(), that.getConfigItem()) && Objects.equals(getConfigItemAssoc(), that.getConfigItemAssoc()) && Objects.equals(getOptions(), that.getOptions()); } Changed code: private boolean isConfigOptionsSelectionEqual( List<ConfigOption> otherOptions) { List<ConfigOption> mineOptions = getOptions(); for (int i = 0; i < mineOptions.size(); i ++) { if (!(mineOptions.get(i).getId().equals(otherOptions.get(i).getId()) && mineOptions.get(i).isSelected()==otherOptions.get(i).isSelected())) { return false; } } return true; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; ConfigItem that = (ConfigItem) o; return Objects.equals(getConfigItem(), that.getConfigItem()) && Objects.equals(getConfigItemAssoc(), that.getConfigItemAssoc()) && // Objects.equals(getOptions(), that.getOptions() isConfigOptionsSelectionEqual(that.getOptions()); }