Exemplo n.º 1
0
  private void prepareZones() {

    if (value != null && value.getProductId() > 0) {
      setCountries(RefUtil.getCountries(value.getLang()));

      if (this.customer == null) {

        customer = SessionUtil.getCustomer(getServletRequest());

        if (customer == null) {

          customer = new Customer();
          customer.setCustomerBillingCountryId(value.getCountryId());
        }
      }

      customer.setLocale(getLocale());

      SessionUtil.setCustomer(customer, getServletRequest());

      Collection zones =
          RefUtil.getZonesByCountry(customer.getCustomerBillingCountryId(), value.getLang());

      if (zones != null && zones.size() > 0) {
        setZonesByCountry(zones);
      } else {
        setZone(customer.getBillingState());
      }

    } else {

      if (this.customer == null) {

        customer = SessionUtil.getCustomer(getServletRequest());
      }
      if (customer != null) {

        customer.setLocale(super.getLocale());

        setCountries(RefUtil.getCountries(super.getLocale().getLanguage()));

        Collection zones =
            RefUtil.getZonesByCountry(
                customer.getCustomerBillingCountryId(),
                LocaleUtil.getDefaultLocale().getLanguage());

        if (zones != null && zones.size() > 0) {
          setZonesByCountry(zones);
        } else {
          setZone(customer.getBillingState());
        }
      } else {

        setCountries(RefUtil.getCountries(LocaleUtil.getDefaultLocale().getLanguage()));

        Configuration conf = PropertiesUtil.getConfiguration();
        int defaultCountry = conf.getInt("core.system.defaultcountryid");
        customer = new Customer();
        customer.setCustomerBillingCountryId(defaultCountry);
        customer.setLocale(super.getLocale());

        Collection zones =
            RefUtil.getZonesByCountry(
                customer.getCustomerBillingCountryId(),
                LocaleUtil.getDefaultLocale().getLanguage());

        if (zones != null && zones.size() > 0) {
          setZonesByCountry(zones);
        } else {
          setZone(customer.getBillingState());
        }

        SessionUtil.setCustomer(customer, getServletRequest());
      }
    }
  }
  /** Creates a new Customer */
  @WebMethod
  public @WebResult CreateCustomerWebServiceResponse createCustomer(
      @WebParam(name = "credentials") WebServiceCredentials credentials,
      @WebParam(name = "customer") Customer customer) {
    MessageSource messageSource = (MessageSource) SpringUtil.getBean("messageSource");

    Locale locale = LocaleUtil.getDefaultLocale();
    if (StringUtils.isNotBlank(customer.getCustomerLang())) {
      locale = LocaleUtil.getLocale(customer.getCustomerLang());
    }

    CreateCustomerWebServiceResponse response = new CreateCustomerWebServiceResponse();
    try {

      // check credentials
      validateCredentials(locale, credentials);

      String[] validationErrorList = validate(customer, locale, messageSource);
      if (validationErrorList != null && validationErrorList.length > 0) {
        response.setMessages(validationErrorList);
        response.setStatus(2);
        return response;
      }

      CustomerService cservice =
          (CustomerService) ServiceFactory.getService(ServiceFactory.CustomerService);

      // if customer has customer id >0 check that it belongs to this merchant id
      com.salesmanager.core.entity.customer.Customer tmpCustomer = null;
      if (customer.getCustomerId() > 0) {
        tmpCustomer = cservice.getCustomer(customer.getCustomerId());
        if (tmpCustomer != null) {
          if (tmpCustomer.getMerchantId() != credentials.getMerchantId()) {
            response.setMessages(
                new String[] {messageSource.getMessage("messages.authorization", null, locale)});
            response.setStatus(0);
          }
        }
      }

      com.salesmanager.core.entity.customer.Customer newCustomer =
          new com.salesmanager.core.entity.customer.Customer();

      if (tmpCustomer != null) { // modify existing customer
        newCustomer = tmpCustomer;
      }
      BeanUtils.copyProperties(newCustomer, customer);

      // copy properties to billing
      newCustomer.setCustomerBillingCity(customer.getCustomerCity());
      newCustomer.setCustomerBillingCountryId(customer.getCustomerCountryId());
      newCustomer.setCustomerBillingCountryName(newCustomer.getBillingCountry());
      newCustomer.setCustomerBillingFirstName(customer.getCustomerFirstname());
      newCustomer.setCustomerBillingLastName(customer.getCustomerLastname());
      newCustomer.setCustomerBillingPostalCode(customer.getCustomerPostalCode());
      newCustomer.setCustomerBillingState(newCustomer.getStateProvinceName());
      newCustomer.setCustomerBillingStreetAddress(customer.getCustomerStreetAddress());
      newCustomer.setCustomerBillingZoneId(customer.getCustomerZoneId());

      newCustomer.setLocale(locale);
      newCustomer.setMerchantId(credentials.getMerchantId());

      if (StringUtils.isBlank(customer.getZoneName()) && customer.getCustomerZoneId() > 0) {
        java.util.Map zones =
            (java.util.Map)
                RefCache.getAllZonesmap(LanguageUtil.getLanguageNumberCode(locale.getLanguage()));
        if (zones != null) {
          Zone z = (Zone) zones.get(customer.getCustomerZoneId());
          if (z != null) {
            newCustomer.setCustomerState(z.getZoneName());
          }
        }
      }

      if (StringUtils.isBlank(newCustomer.getBillingState())
          && newCustomer.getCustomerZoneId() > 0) {
        java.util.Map zones =
            (java.util.Map)
                RefCache.getAllZonesmap(LanguageUtil.getLanguageNumberCode(locale.getLanguage()));
        if (zones != null) {
          Zone z = (Zone) zones.get(newCustomer.getCustomerZoneId());
          if (z != null) {
            newCustomer.setCustomerBillingState(z.getZoneName());
          }
        }
      }

      cservice.saveOrUpdateCustomer(newCustomer, SystemUrlEntryType.WEB, locale);

      response.setMessages(
          new String[] {
            messageSource.getMessage("messages.customer.customerregistered", null, locale)
          });
      response.setStatus(1);
      response.setCustomerId(newCustomer.getCustomerId());

    } catch (Exception e) {

      if (e instanceof ServiceException) {
        String msg[] = {((ServiceException) e).getMessage()};
        response.setMessages(msg);
        response.setStatus(0);
      } else {

        log.error("Exception occurred while creating Customer", e);
        response.setMessages(
            new String[] {messageSource.getMessage("errors.technical", null, locale)});
        response.setStatus(0);
      }
    }
    return response;
  }
Exemplo n.º 3
0
  public String execute(HttpServletRequest request) throws Exception {

    Customer customer = null;

    if (!validateCustomerLogon(request)) {

      LabelUtil l = LabelUtil.getInstance();
      Locale locale = LocaleUtil.getLocale(request);
      l.setLocale(locale);
      MessageUtil.addErrorMessage(request, l.getText(locale, "login.invalid"));
      return "redirect:/home.html";
    }
    try {

      CustomerLogonModule logon =
          (CustomerLogonModule) com.salesmanager.core.util.SpringUtil.getBean("customerLogon");

      // get merchantId
      int merchantId = 1;
      HttpSession session = request.getSession();
      MerchantStore store = (MerchantStore) session.getAttribute("STORE");
      if (store != null) {
        merchantId = store.getMerchantId();
      }

      customer = logon.logon(request, merchantId);

      if (customer == null) {

        MessageUtil.addErrorMessage(request, super.getText(request, "login.invalid"));
        return "redirect:/home.html";
      }

      Locale locale = LocaleUtil.getLocale(request);
      customer.setLocale(locale);

      // get CustomerInfo
      CustomerService cservice =
          (CustomerService) ServiceFactory.getService(ServiceFactory.CustomerService);
      CustomerInfo customerInfo = cservice.findCustomerInfoById(customer.getCustomerId());

      if (customerInfo == null) {
        customerInfo = new CustomerInfo();
        customerInfo.setCustomerInfoId(customer.getCustomerId());
      }

      Integer login = customerInfo.getCustomerInfoNumberOfLogon();
      login = login + 1;
      customerInfo.setCustomerInfoNumberOfLogon(login);
      cservice.saveOrUpdateCustomerInfo(customerInfo);

      SessionUtil.setCustomer(customer, request);
      request.setAttribute("CUSTOMER", customer);

      return "redirect:/profile/profile.html";

    } catch (ServiceException e) {

      MessageUtil.addErrorMessage(request, super.getText(request, "login.invalid"));
      return "redirect:/home.html";

    } catch (Exception ex) {
      log.error(ex);
      throw ex;
    }
  }