Uploaded image for project: 'OFBiz'
  1. OFBiz
  2. OFBIZ-12303

ShoppingCart object does not recognize two products with different configurations

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 17.12.04
    • None
    • ecommerce
    • Centos Linux 8;

      openjdk version "11.0.9" 2020-10-20 LTS;
      PostgreSQL 12.1

    • Important

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

       

      Attachments

        1. OFBIZ-12303.patch
          2 kB
          Nicolas Malin
        2. OFBIZ-12303.patch
          3 kB
          Nicolas Malin

        Activity

          People

            nmalin Nicolas Malin
            sashoran Alexander Tzvetanov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: