protected void updateShippingCalculation(
      ActionRequest actionRequest, ShoppingPreferences preferences) throws Exception {

    String shippingFormula = ParamUtil.getString(actionRequest, "shippingFormula");

    String[] shipping = new String[5];

    for (int i = 0; i < shipping.length; i++) {
      shipping[i] = String.valueOf(ParamUtil.getDouble(actionRequest, "shipping" + i));
    }

    preferences.setShippingFormula(shippingFormula);
    preferences.setShipping(shipping);
  }
  protected void updateInsuranceCalculation(
      ActionRequest actionRequest, ShoppingPreferences preferences) throws Exception {

    String insuranceFormula = ParamUtil.getString(actionRequest, "insuranceFormula");

    String[] insurance = new String[5];

    for (int i = 0; i < insurance.length; i++) {
      insurance[i] = String.valueOf(ParamUtil.getDouble(actionRequest, "insurance" + i));
    }

    preferences.setInsuranceFormula(insuranceFormula);
    preferences.setInsurance(insurance);
  }
  protected void updateEmailFrom(ActionRequest actionRequest, ShoppingPreferences preferences)
      throws Exception {

    String emailFromName = ParamUtil.getString(actionRequest, "emailFromName");
    String emailFromAddress = ParamUtil.getString(actionRequest, "emailFromAddress");

    if (Validator.isNull(emailFromName)) {
      SessionErrors.add(actionRequest, "emailFromName");
    } else if (!Validator.isEmailAddress(emailFromAddress)) {
      SessionErrors.add(actionRequest, "emailFromAddress");
    } else {
      preferences.setEmailFromName(emailFromName);
      preferences.setEmailFromAddress(emailFromAddress);
    }
  }
  protected void updateEmailOrderShipping(
      ActionRequest actionRequest, ShoppingPreferences preferences) throws Exception {

    boolean emailOrderShippingEnabled =
        ParamUtil.getBoolean(actionRequest, "emailOrderShippingEnabled");
    String emailOrderShippingSubject =
        ParamUtil.getString(actionRequest, "emailOrderShippingSubject");
    String emailOrderShippingBody = ParamUtil.getString(actionRequest, "emailOrderShippingBody");

    if (Validator.isNull(emailOrderShippingSubject)) {
      SessionErrors.add(actionRequest, "emailOrderShippingSubject");
    } else if (Validator.isNull(emailOrderShippingBody)) {
      SessionErrors.add(actionRequest, "emailOrderShippingBody");
    } else {
      preferences.setEmailOrderShippingEnabled(emailOrderShippingEnabled);
      preferences.setEmailOrderShippingSubject(emailOrderShippingSubject);
      preferences.setEmailOrderShippingBody(emailOrderShippingBody);
    }
  }
  @Override
  public void processAction(
      PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    if (!cmd.equals(Constants.UPDATE)) {
      return;
    }

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

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

    String tabs2 = ParamUtil.getString(actionRequest, "tabs2");
    String tabs3 = ParamUtil.getString(actionRequest, "tabs3");

    if (tabs2.equals("payment-settings")) {
      updatePayment(actionRequest, preferences);
    } else if (tabs2.equals("shipping-calculation")) {
      updateShippingCalculation(actionRequest, preferences);
    } else if (tabs2.equals("insurance-calculation")) {
      updateInsuranceCalculation(actionRequest, preferences);
    } else if (tabs2.equals("emails")) {
      if (tabs3.equals("email-from")) {
        updateEmailFrom(actionRequest, preferences);
      } else if (tabs3.equals("confirmation-email")) {
        updateEmailOrderConfirmation(actionRequest, preferences);
      } else if (tabs3.equals("shipping-email")) {
        updateEmailOrderShipping(actionRequest, preferences);
      }
    }

    if (SessionErrors.isEmpty(actionRequest)) {
      preferences.store();

      SessionMessages.add(actionRequest, portletConfig.getPortletName() + ".doConfigure");
    }
  }
Exemplo n.º 6
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);
    }
  }
  protected void updatePayment(ActionRequest actionRequest, ShoppingPreferences preferences)
      throws Exception {

    String payPalEmailAddress = ParamUtil.getString(actionRequest, "payPalEmailAddress");
    String[] ccTypes = StringUtil.split(ParamUtil.getString(actionRequest, "ccTypes"));
    String currencyId = ParamUtil.getString(actionRequest, "currencyId");
    String taxState = ParamUtil.getString(actionRequest, "taxState");
    double taxRate = ParamUtil.getDouble(actionRequest, "taxRate") / 100;
    double minOrder = ParamUtil.getDouble(actionRequest, "minOrder");

    preferences.setPayPalEmailAddress(payPalEmailAddress);
    preferences.setCcTypes(ccTypes);
    preferences.setCurrencyId(currencyId);
    preferences.setTaxState(taxState);
    preferences.setTaxRate(taxRate);
    preferences.setMinOrder(minOrder);
  }