Пример #1
0
 public void removeVariant(Variant variant) {
   if (variant != null) {
     selected.getVariants().remove(variant);
     // If there is only one variant left, reset its name/code and make it the default
     if (selected.getVariants().size() == 1) {
       Variant v = selected.getDefaultVariant();
       v.setName("");
       v.setDefaultChoice(true);
     }
   }
 }
Пример #2
0
 public void addVariant() {
   Variant v = new Variant();
   // If this is not the first variant, re-use price, weight and stock values
   if (selected.getVariants().size() > 0) {
     Variant prev = selected.getVariantsAsList().get(selected.getVariants().size() - 1);
     v.setPrice(prev.getPrice());
     v.setWeight(prev.getWeight());
     v.setStock(prev.getStock());
     v.setDefaultChoice(false);
   } else {
     v.setName("");
     v.setDefaultChoice(true);
   }
   selected.getVariants().add(v);
 }