예제 #1
0
  // goes to summary page
  public String subscribe() {

    try {

      preparePage();
      validateCustomer();

      SessionUtil.setCustomer(customer, getServletRequest());

      prepareZones();

      if (this.getPaymentMethod() == null
          || this.getPaymentMethod().getPaymentModuleName() == null) {
        super.addActionError("error.nopaymentmethod");
        return INPUT;
      }

      super.getServletRequest().setAttribute("SELECTEDPAYMENT", this.getPaymentMethod());

      MerchantStore store = SessionUtil.getMerchantStore(getServletRequest());

      // check if payment method is credit card type
      if (com.salesmanager.core.util.PaymentUtil.isPaymentModuleCreditCardType(
          this.getPaymentMethod().getPaymentModuleName())) {
        super.validateCreditCard(this.getPaymentMethod(), store.getMerchantId());
      } else {
        super.setCreditCard(null); // reset credit card information
      }

      if (getFieldErrors().size() > 0) {
        return INPUT;
      }

      SessionUtil.setPaymentMethod(this.getPaymentMethod(), getServletRequest());

    } catch (Exception e) {
      log.error(e);
      super.addActionError(getText("error.process.notransaction"));
      return "GLOBALERROR";
    }

    return SUCCESS;
  }
예제 #2
0
  /**
   * This methhod is for subscription step 1
   *
   * @return
   */
  public String displaySubscriptionForm() {

    try {

      // check if the session is still active
      Order o = SessionUtil.getOrder(getServletRequest());
      if (o == null) {
        super.addActionError(getText("error.sessionexpired"));
        return "GLOBALERROR";
      }

      // This is for the progress bar
      getServletRequest().setAttribute("STEP", "1");
      prepareZones();

      /*
       * //STUB CUSTOMER
       * customer=ShoppingCartUtil.getCustomer(getServletRequest());
       * customer.setCustomerEmailAddress("*****@*****.**");
       * customer.setCustomerFirstname("Carlito");
       * customer.setCustomerLastname("Samsonos");
       * customer.setCustomerBillingStreetAddress("358 Du Languedoc");
       * customer.setCustomerBillingCity("Boucherville");
       * customer.setCustomerBillingState("Quebec");
       * customer.setCustomerBillingZoneId(76);
       * customer.setCustomerBillingCountryId(38);
       * customer.setCustomerBillingPostalCode("J4B8J9");
       * customer.setCustomerTelephone("4504497181");
       * ShoppingCartUtil.setCustomer(customer, getServletRequest());
       */

      preparePage();
      return SUCCESS;
    } catch (Exception e) {
      super.addActionError(getText("error.process.notransaction"));
      log.error(e);
      return "GLOBALERROR";
    }
  }
예제 #3
0
  private void preparePage() throws Exception {

    Map ccmap = com.salesmanager.core.service.cache.RefCache.getSupportedCreditCards();
    if (ccmap != null) {
      creditCards = new ArrayList();
      Iterator i = ccmap.keySet().iterator();

      while (i.hasNext()) {
        int key = (Integer) i.next();
        creditCards.add((CentralCreditCard) ccmap.get(key));
      }
    }

    paymentMethods = PaymentUtil.getPaymentMethods(1, super.getLocale());

    // too complex to be handled with webwork, will store the object in http
    super.getServletRequest().setAttribute("PAYMENTS", paymentMethods);
  }
예제 #4
0
  /**
   * Invoked after addSubscriptionItem
   *
   * @throws Exception
   */
  public void addItem() throws Exception {

    boolean quantityUpdated = false;

    // get store country
    Map lcountries =
        RefCache.getAllcountriesmap(LanguageUtil.getLanguageNumberCode(value.getLang()));
    if (lcountries != null) {
      Country country = (Country) lcountries.get(store.getCountry());
      getServletRequest().getSession().setAttribute("COUNTRY", country);
    }

    // check if language is supported by the store
    if (lcountries != null) {
      Country country = (Country) lcountries.get(store.getCountry());
      getServletRequest().getSession().setAttribute("COUNTRY", country);
    }

    // store can not be null, if it is the case, generic error page
    if (store == null) {
      throw new Exception("Invalid Store!");
    }

    // check if order product already exist. If that orderproduct already
    // exist
    // and has no ptoperties, so just update the quantity
    if (value.getAttributeId() == null
        || (value.getAttributeId() != null && value.getAttributeId().size() == 0)) {
      Map savedProducts = SessionUtil.getOrderProducts(getServletRequest());
      if (savedProducts != null) {
        Iterator it = savedProducts.keySet().iterator();
        while (it.hasNext()) {
          String line = (String) it.next();
          OrderProduct op = (OrderProduct) savedProducts.get(line);
          if (op.getProductId() == value.getProductId()) {
            Set attrs = op.getOrderattributes();
            if (attrs.size() == 0) {
              int qty = op.getProductQuantity();
              qty = qty + value.getQty();
              op.setProductQuantity(qty);
              quantityUpdated = true;
              break;
            }
          }
        }
      }
    }

    // create an order with merchantId and all dates
    // will need to create a new order id when submited
    Order order = SessionUtil.getOrder(getServletRequest());
    if (order == null) {
      order = new Order();
    }

    order.setMerchantId(store.getMerchantId());
    order.setDatePurchased(new Date());
    SessionUtil.setOrder(order, getServletRequest());

    if (!StringUtils.isBlank(value.getReturnUrl())) {
      // Return to merchant site Url is set from store.
      value.setReturnUrl(store.getContinueshoppingurl());
    }
    SessionUtil.setMerchantStore(store, getServletRequest());

    if (!quantityUpdated) { // new submission

      // Prepare order
      OrderProduct orderProduct =
          com.salesmanager.core.util.CheckoutUtil.createOrderProduct(
              value.getProductId(), getLocale(), store.getCurrency());
      orderProduct.setProductQuantity(value.getQty());
      orderProduct.setProductId(value.getProductId());

      List<OrderProductAttribute> attributes = new ArrayList<OrderProductAttribute>();
      if (value.getAttributeId() != null && value.getAttributeId().size() > 0) {
        for (Long attrId : value.getAttributeId()) {
          if (attrId != null && attrId != 0) {
            ProductAttribute pAttr =
                cservice.getProductAttributeByOptionValueAndProduct(value.getProductId(), attrId);
            if (pAttr != null && pAttr.getProductId() == value.getProductId()) {
              OrderProductAttribute orderAttr = new OrderProductAttribute();
              orderAttr.setProductOptionValueId(pAttr.getOptionValueId());

              attributes.add(orderAttr);
            } else {
              LogMerchantUtil.log(
                  value.getMerchantId(),
                  getText(
                      "error.validation.product.attributes.ids",
                      new String[] {String.valueOf(attrId), String.valueOf(value.getProductId())}));
            }
          }
        }
      }

      if (!attributes.isEmpty()) {
        // ShoppingCartUtil.addAttributesFromRawObjects(attributes,
        // orderProduct, store.getCurrency(), getServletRequest());
        com.salesmanager.core.util.CheckoutUtil.addAttributesToProduct(
            attributes, orderProduct, store.getCurrency(), getLocale());
      }

      Set attributesSet = new HashSet(attributes);
      orderProduct.setOrderattributes(attributesSet);

      SessionUtil.addOrderProduct(orderProduct, getServletRequest());
    }

    // because this is a submission, cannot continue browsing, so that's it
    // for the OrderProduct
    Map orderProducts = SessionUtil.getOrderProducts(super.getServletRequest());
    // transform to a list
    List products = new ArrayList();

    if (orderProducts != null) {
      Iterator i = orderProducts.keySet().iterator();
      while (i.hasNext()) {
        String line = (String) i.next();
        OrderProduct op = (OrderProduct) orderProducts.get(line);
        products.add(op);
      }
      super.getServletRequest().getSession().setAttribute("ORDER_PRODUCT_LIST", products);
    }

    // for displaying the order summary, need to create an OrderSummary
    // entity
    OrderTotalSummary summary =
        oservice.calculateTotal(order, products, store.getCurrency(), super.getLocale());

    Map totals =
        OrderUtil.getOrderTotals(
            order.getOrderId(), summary, store.getCurrency(), super.getLocale());

    HttpSession session = getServletRequest().getSession();

    // transform totals to a list
    List totalsList = new ArrayList();
    if (totals != null) {
      Iterator totalsIterator = totals.keySet().iterator();
      while (totalsIterator.hasNext()) {
        String key = (String) totalsIterator.next();
        OrderTotal total = (OrderTotal) totals.get(key);
        totalsList.add(total);
      }
    }

    SessionUtil.setOrderTotals(totalsList, getServletRequest());

    value.setLangId(LanguageUtil.getLanguageNumberCode(value.getLang()));
    prepareZones();

    // set locale according to the language passed in parameters and store
    // information
    Locale locale = LocaleUtil.getLocaleFromStoreEntity(store, value.getLang());
    setLocale(locale);
  }
예제 #5
0
  public void validateCustomer() {

    if (StringUtils.isBlank(customer.getCustomerEmailAddress())) {
      addFieldError("customer.customerEmailAddress", getText("messages.required.email"));
      super.addFieldMessage("customer.customerEmailAddress", "messages.required.email");
    } else {
      if (!CustomerUtil.validateEmail(customer.getCustomerEmailAddress())) {
        addFieldError("customer.customerEmailAddress", getText("messages.invalid.email"));
        super.addFieldMessage("customer.customerEmailAddress", "messages.invalid.email");
      }
    }
    /*
     * if(StringUtils.isBlank(customer.getCustomerPassword())) {
     * addFieldError("customer.customerPassword",
     * getText("messages.required.password")); }
     * if(StringUtils.isBlank(getConfirmEmailAddress())) {
     * addFieldError("confirmEmailAddress",
     * getText("messages.required.email.confirm")); }else{
     * if(!getConfirmEmailAddress
     * ().equals(customer.getCustomerEmailAddress())){
     * addFieldError("confirmEmailAddress",
     * getText("messages.unequal.email.confirm")); } }
     * if(StringUtils.isBlank(getConfirmPassword())) {
     * addFieldError("confirmPassword",
     * getText("messages.required.password.confirm")); }else{
     * if(!getConfirmPassword().equals(customer.getCustomerPassword())){
     * addFieldError("confirmPassword",
     * getText("messages.unequal.password.confirm")); } }
     */
    if (StringUtils.isBlank(customer.getCustomerFirstname())) {
      addFieldError("customer.customerFirstname", getText("messages.required.firstname"));
      super.addFieldMessage("customer.customerFirstname", "messages.required.firstname");
    }
    if (StringUtils.isBlank(customer.getCustomerLastname())) {
      addFieldError("customer.customerLastname", getText("messages.required.lastname"));
      super.addFieldMessage("customer.customerLastname", "messages.required.lastname");
    }
    if (StringUtils.isBlank(customer.getCustomerBillingStreetAddress())) {
      addFieldError(
          "customer.customerBillingStreetAddress", getText("messages.required.streetaddress"));
      super.addFieldMessage(
          "customer.customerBillingStreetAddress", "messages.required.streetaddress");
    }
    if (StringUtils.isBlank(customer.getCustomerBillingCity())) {
      addFieldError("customer.customerBillingCity", getText("messages.required.city"));
      super.addFieldMessage("customer.customerBillingCity", "messages.required.city");
    }
    if (!StringUtils.isBlank(this.getFormstate()) && this.getFormstate().equals("text")) {
      if (StringUtils.isBlank(customer.getCustomerBillingState())) {
        addFieldError("customer.customerBillingState", getText("messages.required.stateprovince"));
        super.addFieldMessage("customer.customerBillingState", "messages.required.stateprovince");
      }
    }
    if (StringUtils.isBlank(customer.getCustomerBillingPostalCode())) {
      addFieldError("customer.customerBillingPostalCode", getText("messages.required.postalcode"));
      super.addFieldMessage("customer.customerBillingPostalCode", "messages.required.postalcode");
    }

    if (StringUtils.isBlank(customer.getCustomerTelephone())) {
      addFieldError("customer.customerTelephone", getText("messages.required.phone"));
      super.addFieldMessage("customer.customerTelephone", "messages.required.phone");
    }
    /**
     * else if(!CustomerUtil.ValidatePhoneNumber(customer.getCustomerTelephone ())){
     * addFieldError("customer.customerTelephone", getText("messages.invalid.phone"));
     * super.addFieldMessage("customer.customerTelephone", "messages.invalid.phone"); }
     */
    String cName = "";
    Map lcountries = RefCache.getCountriesMap();
    if (lcountries != null) {
      Country country = (Country) lcountries.get(customer.getCustomerBillingCountryId());
      Set descriptions = country.getDescriptions();
      if (descriptions != null) {
        Iterator cIterator = descriptions.iterator();
        while (cIterator.hasNext()) {
          CountryDescription desc = (CountryDescription) cIterator.next();
          cName = desc.getCountryName();
          if (desc.getId().getLanguageId()
              == LanguageUtil.getLanguageNumberCode(super.getLocale().getLanguage())) {
            cName = desc.getCountryName();
            break;
          }
        }
      }
    }

    if (StringUtils.isBlank(customer.getCustomerBillingState())) {
      Map lzones =
          RefCache.getAllZonesmap(
              LanguageUtil.getLanguageNumberCode(super.getLocale().getLanguage()));
      if (lzones != null) {
        Zone z = (Zone) lzones.get(customer.getCustomerBillingZoneId());
        if (z != null) {
          customer.setCustomerBillingState(z.getZoneName());
          customer.setCustomerState(z.getZoneName());
        }
      }
    }

    String lang = super.getLocale().getLanguage();

    customer.setCountryName(cName);
    customer.setCustomerBillingCountryName(cName);
    customer.setCustomerLang(lang);

    customer.setCountryName(customer.getBillingCountry());
    customer.setCustomerCity(customer.getCustomerBillingCity());
    customer.setCustomerCountryId(customer.getCustomerBillingCountryId());
    customer.setCustomerLang(super.getLocale().getLanguage());
    customer.setCustomerPostalCode(customer.getCustomerBillingPostalCode());
    customer.setCustomerStreetAddress(customer.getCustomerBillingStreetAddress());
    customer.setCustomerState(customer.getBillingState());
    customer.setCustomerZoneId(customer.getCustomerBillingZoneId());
  }