@Override public void manageCookiesLogin( @Nonnull HttpServletRequest request, @Nonnull HttpServletResponse response, @Nonnull KKAppEng kkAppEng) throws HstComponentException { if (!kkAppEng.isKkCookieEnabled()) { return; } CustomerIf currentCustomer = kkAppEng.getCustomerMgr().getCurrentCustomer(); if (currentCustomer != null) { setKKCookie( CUSTOMER_NAME, currentCustomer.getFirstName() + " " + currentCustomer.getLastName(), request, response, kkAppEng); } try { /* * Get customer preferences from customer tags. If the tag value exists, then set the * preference in the manager and set the cookie. */ String prodPageSizeStr = kkAppEng.getCustomerTagMgr().getCustomerTagValue(TAG_PROD_PAGE_SIZE); if (prodPageSizeStr != null && prodPageSizeStr.length() > 0) { int prodPageSize = Integer.parseInt(prodPageSizeStr); kkAppEng.getProductMgr().setMaxDisplaySearchResults(prodPageSize); setKKCookie(TAG_PROD_PAGE_SIZE, prodPageSizeStr, request, response, kkAppEng); } String orderPageSizeStr = kkAppEng.getCustomerTagMgr().getCustomerTagValue(TAG_ORDER_PAGE_SIZE); if (orderPageSizeStr != null && orderPageSizeStr.length() > 0) { int orderPageSize = Integer.parseInt(orderPageSizeStr); kkAppEng.getOrderMgr().setPageSize(orderPageSize); setKKCookie(TAG_ORDER_PAGE_SIZE, orderPageSizeStr, request, response, kkAppEng); } String reviewPageSizeStr = kkAppEng.getCustomerTagMgr().getCustomerTagValue(TAG_REVIEW_PAGE_SIZE); if (reviewPageSizeStr != null && reviewPageSizeStr.length() > 0) { int reviewPageSize = Integer.parseInt(reviewPageSizeStr); kkAppEng.getReviewMgr().setPageSize(reviewPageSize); setKKCookie(TAG_REVIEW_PAGE_SIZE, reviewPageSizeStr, request, response, kkAppEng); } } catch (KKAppException e) { throw new HstComponentException(e); } catch (KKException e) { throw new HstComponentException(e); } }
/** * Method called when a customer logs in or logs out. When logging in we need to decide whether to * update the customer's PRODUCTS_VIEWED tag value from the value of the guest customer's tag. * When logging out we need to make the same decision in the opposite direction. We only do the * updates if the tag value of the "oldTag" is more recent than the tag value of the "newTag". * * @param oldTag When logging in, it is the tag of the guest customer. When logging out, it is the * tag of the logged in customer. * @param newTag When logging in, it is the tag of the logged in customer. When logging out, it is * the tag of the guest customer. * @throws KKException * @throws KKAppException */ protected void updateRecentlyViewedProducts( KKAppEng kkAppEng, CustomerTagIf oldTag, CustomerTagIf newTag) throws KKAppException, KKException { if (oldTag != null && oldTag.getDateAdded() != null && oldTag.getValue() != null && oldTag.getValue().length() > 0) { if (newTag == null || newTag.getDateAdded() == null || newTag.getDateAdded().before(oldTag.getDateAdded())) { /* * If new tag doesn't exist or old tag is newer than new tag, then give newTag the * value of old tag */ kkAppEng.getCustomerTagMgr().insertCustomerTag(TAG_PRODUCTS_VIEWED, oldTag.getValue()); } } }
public String execute() { HttpServletRequest request = ServletActionContext.getRequest(); HttpServletResponse response = ServletActionContext.getResponse(); try { int custId; KKAppEng kkAppEng = this.getKKAppEng(request, response); custId = this.loggedIn(request, response, kkAppEng, null); // Ensure we are using the correct protocol. Redirect if not. String redirForward = checkSSL(kkAppEng, request, custId, /* forceSSL */ false); if (redirForward != null) { setupResponseForSSLRedirect(response, redirForward); return null; } /* * Save preferences in managers, cookies and tags */ kkAppEng.getReviewMgr().setPageSize(numRevs); setKKCookie(TAG_REVIEW_PAGE_SIZE, Integer.toString(numRevs), request, response, kkAppEng); kkAppEng .getCustomerTagMgr() .insertCustomerTag(TAG_REVIEW_PAGE_SIZE, Integer.toString(numRevs)); DataDescriptorIf dd = kkAppEng.getReviewMgr().getDataDesc(); if (dd != null) { dd.setLimit(numRevs + 1); dd.setOffset(0); kkAppEng.getReviewMgr().orderCurrentReviews(dd.getOrderBy(), t); } kkAppEng.getReviewMgr().setShowTab(true); return SUCCESS; } catch (Exception e) { return super.handleException(request, e); } }
public String execute() { HttpServletRequest request = ServletActionContext.getRequest(); HttpServletResponse response = ServletActionContext.getResponse(); try { int custId; KKAppEng kkAppEng = this.getKKAppEng(request, response); custId = this.loggedIn(request, response, kkAppEng, "EditCustomer"); // Check to see whether the user is logged in if (custId < 0) { return KKLOGIN; } // Ensure we are using the correct protocol. Redirect if not. String redirForward = checkSSL(kkAppEng, request, custId, /* forceSSL */ false); if (redirForward != null) { setupResponseForSSLRedirect(response, redirForward); return null; } // Copy the inputs from the form to a customer object CustomerIf cust = new Customer(); cust.setGender(escapeFormInput(getGender())); cust.setFirstName(escapeFormInput(getFirstName())); cust.setLastName(escapeFormInput(getLastName())); cust.setEmailAddr(escapeFormInput(getEmailAddr())); cust.setFaxNumber(escapeFormInput(getFaxNumber())); cust.setTelephoneNumber(escapeFormInput(getTelephoneNumber())); cust.setTelephoneNumber1(escapeFormInput(getTelephoneNumber1())); cust.setId(kkAppEng.getCustomerMgr().getCurrentCustomer().getId()); cust.setCustom1(escapeFormInput(getCustomerCustom1())); CustomerIf currentCustomer = kkAppEng.getCustomerMgr().getCurrentCustomer(); if (currentCustomer != null) { cust.setType(currentCustomer.getType()); } // Set the date if (getBirthDateString() != null && !getBirthDateString().equals("")) { SimpleDateFormat sdf = new SimpleDateFormat(kkAppEng.getMsg("date.format")); Date d = sdf.parse(getBirthDateString()); if (d != null) { GregorianCalendar gc = new GregorianCalendar(); gc.setTime(d); cust.setBirthDate(gc); // Set the customer tag CustomerTag ct = new CustomerTag(); ct.setValueAsDate(d); ct.setName(TAG_BIRTH_DATE); kkAppEng.getCustomerTagMgr().insertCustomerTag(ct); } } // Set the IS_MALE customer tag for this customer CustomerTag ct = new CustomerTag(); ct.setName(TAG_IS_MALE); ct.setValueAsBoolean(false); if (getGender() != null && getGender().equalsIgnoreCase("m")) { ct.setValueAsBoolean(true); } kkAppEng.getCustomerTagMgr().insertCustomerTag(ct); // Call the engine registration method try { kkAppEng.getCustomerMgr().editCustomer(cust); } catch (Exception e) { addActionError(kkAppEng.getMsg("edit.customer.body.user.exists")); return "ApplicationError"; } return SUCCESS; } catch (Exception e) { return super.handleException(request, e); } }