Author Topic: Problem with product options out of order  (Read 1135 times)

paulh

  • Jr. Member
  • **
  • Posts: 18
    • View Profile
Problem with product options out of order
« on: September 05, 2007, 02:23:25 PM »

If u insert your product attributes and ur options are not contiguous ull end up with more selects that u bargain for - Im sure it will be fixed in the next release but heres a quick hack in the meantime - should be inserted before the product attributes are rendered in the productdetailsbody.jsp

<%
                  
                  ArrayList options = (ArrayList) selectedOpts;
                  Collections.sort(options, new Comparator() {
                  
                   public int compare(Object arg0, Object arg1) {
                      String  s1 = "" + ((ProdOptionContainer) arg0).getId();
                      String  s2 = "" + ((ProdOptionContainer) arg1).getId();
                      return s1.compareTo(s2);
                   }
                  });

                  ArrayList newOptions = new ArrayList(options);
                  
                  ProdOptionContainer current =  null;                  
                  for (int j=0; j < newOptions.size(); j++) {
                     
                     ProdOptionContainer prodOptionContainer =  (ProdOptionContainer) newOptions.get(j);
                     if (current!=null && current.getName().equals(prodOptionContainer.getName())) {
                        List values = prodOptionContainer.getOptValues();
                        for (int k=0; k < values.size(); k++) {
                           current.getOptValues().add(values.get(k));
                        }
                        options.remove(j);
                     } else {
                        current = prodOptionContainer;
                     }
                     
                  }
                                    
                  %>