public String setEditable(Vara vara) throws SQLException {
   for (int i = 0; i < kundvagn.getVara().size(); i++) {
     if (kundvagn.getVara().get(i).getId() == vara.getId()) {
       kundvagn.getVara().get(i).setEditable(true);
     }
   }
   return null;
 }
 public String deleteAction(Vara vara) throws SQLException {
   for (Vara v : kundvagn.getVara()) {
     if (vara.getId() == v.getId()) {
       kundvagn.getVara().remove(v);
     }
   }
   setAll();
   return null;
 }
 public double getSum() {
   int sum = 0;
   for (int i = 0; i < kundvagn.getVara().size(); i++) {
     int antal = kundvagn.getVara().get(i).getAntal();
     int pris = kundvagn.getVara().get(i).getPris();
     sum = sum + (antal * pris);
   }
   summa = (double) sum;
   return summa;
 }
  public String sendKundvagn() throws SQLException {

    dbcon.createOrder(kundvagn);
    String to = user.geteMail();
    String password = "******";
    String from = "Javaiskolan";
    String host = "smtp.gmail.com";
    Properties props = System.getProperties();
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.host", "smtp.gmail.com");
    props.put("mail.smtp.port", "587");
    Session session =
        Session.getInstance(
            props,
            new javax.mail.Authenticator() {
              protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(to, password);
              }
            });

    try {
      // skapar upp en medelande och sätter vart det kommer ifrån
      MimeMessage message = new MimeMessage(session);
      message.setFrom(new InternetAddress(from, "h12augde"));
      message.addRecipient(Message.RecipientType.TO, new InternetAddress(to, "h12augde"));

      message.setSubject("Thanks for your order");
      StringBuilder sb = new StringBuilder();
      for (Vara v : kundvagn.getVara()) {
        sb.append(v.getNamn() + "\t");
        sb.append(v.getAntal() + "\t");
        sb.append(v.getPris() + "kr \n");
      }
      sb.append("Sum: " + getSum() + "kr");
      message.setText(sb.toString());
      // skrickar medeleandet
      Transport.send(message);
    } catch (MessagingException ex) {
      ex.printStackTrace();
      ;
    } catch (UnsupportedEncodingException ex) {
      Logger.getLogger(VarorDB.class.getName()).log(Level.SEVERE, null, ex);
    }
    return "paypal.xhtml";
  }
  public String addVaraToKundvagn(Vara vara) throws SQLException {
    if (isLogedin()) {
      if (kundvagn.getVara().size() != 0) {
        boolean index = true;
        for (int i = 0; i < kundvagn.getVara().size(); i++) {
          if (kundvagn.getVara().get(i).getId() == vara.getId()) {
            index = false;
            kundvagn.getVara().get(i).setAntal(kundvagn.getVara().get(i).getAntal() + 1);
          }
        }
        if (index) {
          vara.setAntal(1);
          kundvagn.getVara().add(vara);
        }

      } else {
        vara.setAntal(1);
        kundvagn.getVara().add(vara);
      }
      return null;
    } else {
      return "index.xhtml";
    }
  }
 public ArrayList<Vara> getKundvagn() throws SQLException {
   setAll();
   return kundvagn.getVara();
 }