[ 
https://issues.apache.org/jira/browse/OFBIZ-12303?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Alexander Tzvetanov updated OFBIZ-12303:
----------------------------------------
    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.

{noformat}
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());
        }
{noformat}
 

  was:
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.



FIle: 
pplications/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()); 

         } 

 


> ShoppingCart object does not recognize two products with different 
> configurations
> ---------------------------------------------------------------------------------
>
>                 Key: OFBIZ-12303
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-12303
>             Project: OFBiz
>          Issue Type: Bug
>          Components: ecommerce
>    Affects Versions: 17.12.04
>         Environment: Centos Linux 8;
> openjdk version "11.0.9" 2020-10-20 LTS;
> PostgreSQL 12.1
>            Reporter: Alexander Tzvetanov
>            Priority: Critical
>              Labels: easyfix
>
> 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.
> {noformat}
> 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());
>         }
> {noformat}
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to