Beispiel #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);
     }
   }
 }
Beispiel #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);
 }
Beispiel #3
0
 /**
  * Utility that deletes any temporary uploads that were performed during editing, but were not
  * saved.
  *
  * @throws IOException if there was a problem reading the uploads directory or deleting any
  *     temporary uploads
  */
 private void deleteTempUploads() throws IOException {
   if (selected != null) {
     for (Variant variant : selected.getVariants()) {
       Collection<File> tmpFiles =
           FileUtils.listFiles(
               UploadsServlet.getUploadsDirectory(),
               FileFilterUtils.prefixFileFilter("tmp-" + variant.getUuid()),
               null);
       for (File tmpFile : tmpFiles) {
         FileUtils.forceDelete(tmpFile);
       }
     }
   }
 }
Beispiel #4
0
 /** Bean initialisation. */
 @PostConstruct
 public void init() {
   try {
     // Load the selected item, if an ID is passed as a query parameter
     FacesContext fc = FacesContext.getCurrentInstance();
     String uuid = fc.getExternalContext().getRequestParameterMap().get("uuid");
     if (uuid != null && !uuid.isEmpty()) {
       selected = ProductManager.findByUuid(uuid);
       editing = true;
     } else {
       selected = new Product();
     }
     // Must have as least one variant
     if (selected.getVariants().size() == 0) {
       addVariant();
     }
   } catch (ProductException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }