Exemplo n.º 1
0
  /**
   * Buying articles for business customers as employee.
   *
   * @param cart cart for the business customer, will be cleared
   * @param nickname nickname of the currently logged in employee
   * @param success notification of successfully buying articles
   * @return redirect to template "index" (home page)
   */
  @RequestMapping(value = "/checkout_employee", method = RequestMethod.POST)
  public String buyforbusinesscustomer(
      @ModelAttribute Cart cart,
      @RequestParam("bcustomer") String nickname,
      RedirectAttributes success) {

    Optional<UserAccount> businessCustomer = userAccountManager.findByUsername(nickname);
    return businessCustomer
        .map(
            account -> {
              Order order = new Order(account, Cash.CASH);

              cart.addItemsTo(order);

              orderManager.payOrder(order);
              orderManager.completeOrder(order);

              cart.clear();

              success.addFlashAttribute(
                  "success", "Die Bestellung für den Geschäftskunden ist abgeschlossen.");

              return "redirect:/";
            })
        .orElse("redirect:/cart");
  }
Exemplo n.º 2
0
  /**
   * Buying articles.
   *
   * @param cart the current cart of the user, will be cleared
   * @param userAccount currently logged in user
   * @param success notification of successfully buying articles
   * @return redirect to template "index" (home page)
   */
  @RequestMapping(value = "/checkout", method = RequestMethod.POST)
  public String buy(
      @ModelAttribute Cart cart,
      @LoggedIn Optional<UserAccount> userAccount,
      RedirectAttributes success) {

    return userAccount
        .map(
            account -> {
              Order order = new Order(account, Cash.CASH);

              cart.addItemsTo(order);

              orderManager.payOrder(order);
              orderManager.completeOrder(order);

              cart.clear();

              success.addFlashAttribute("success", "Vielen Dank für Ihre Bestellung.");

              return "redirect:/";
            })
        .orElse("redirect:/cart");
  }