protected void saveLatestOrder(ActionRequest actionRequest) throws Exception {

    ShoppingCart cart = ShoppingUtil.getCart(actionRequest);

    ShoppingOrder order = ShoppingOrderLocalServiceUtil.saveLatestOrder(cart);

    actionRequest.setAttribute(WebKeys.SHOPPING_ORDER, order);
  }
Exemple #2
0
  protected void forwardCheckout(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    ShoppingCart cart = ShoppingUtil.getCart(actionRequest);

    ShoppingOrder order = (ShoppingOrder) actionRequest.getAttribute(WebKeys.SHOPPING_ORDER);

    ShoppingPreferences preferences =
        ShoppingPreferences.getInstance(
            themeDisplay.getCompanyId(), themeDisplay.getScopeGroupId());

    String returnURL =
        ShoppingUtil.getPayPalReturnURL(
            ((ActionResponseImpl) actionResponse).createActionURL(), order);
    String notifyURL = ShoppingUtil.getPayPalNotifyURL(themeDisplay);

    if (preferences.usePayPal()) {
      double total =
          ShoppingUtil.calculateTotal(
              cart.getItems(),
              order.getBillingState(),
              cart.getCoupon(),
              cart.getAltShipping(),
              cart.isInsure());

      String redirectURL =
          ShoppingUtil.getPayPalRedirectURL(preferences, order, total, returnURL, notifyURL);

      actionResponse.sendRedirect(redirectURL);
    } else {
      ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

      ShoppingOrderLocalServiceUtil.sendEmail(order, "confirmation", serviceContext);

      actionResponse.sendRedirect(returnURL);
    }
  }