@Override public void manageCookieLogout( @Nonnull HttpServletRequest request, @Nonnull HttpServletResponse response, @Nonnull KKAppEng kkAppEng) throws HstComponentException { if (!kkAppEng.isKkCookieEnabled()) { return; } CustomerIf currentCustomer = kkAppEng.getCustomerMgr().getCurrentCustomer(); if (currentCustomer != null) { String guestCustomerIdStr = getKKCookie(GUEST_CUSTOMER_ID, request, response, kkAppEng); // Only get the basket items if we can retrieve a temporary customer from the cookie if (guestCustomerIdStr != null) { try { currentCustomer.setId(Integer.parseInt(guestCustomerIdStr)); kkAppEng.getBasketMgr().getBasketItemsPerCustomer(); } catch (NumberFormatException e) { // do nothing } catch (KKException e) { throw new HstComponentException(e); } catch (KKAppException e) { throw new HstComponentException(e); } } } }
/** * When we log out, ensure that the new guest customer that is created has the id saved in the * browser cookie. * * @param request * @param response * @param kkAppEng * @throws KKException * @throws KKAppException */ protected void manageCookieLogout( HttpServletRequest request, HttpServletResponse response, KKAppEng kkAppEng) throws KKException, KKAppException { if (!kkAppEng.isKkCookieEnabled()) { return; } CustomerIf currentCustomer = kkAppEng.getCustomerMgr().getCurrentCustomer(); if (currentCustomer != null) { String guestCustomerIdStr = getKKCookie(GUEST_CUSTOMER_ID, request, response, kkAppEng); // Only get the basket items if we can retrieve a temporary customer from the cookie if (guestCustomerIdStr != null) { try { currentCustomer.setId(Integer.parseInt(guestCustomerIdStr)); kkAppEng.getBasketMgr().getBasketItemsPerCustomer(); } catch (NumberFormatException e) { } } } /* * Call class where you can place custom code */ CustomCookieAction cca = new CustomCookieAction(); cca.manageCookiesAfterLogout(request, response, kkAppEng); }
@Override @Nullable public String manageCookies( @Nonnull HttpServletRequest request, @Nonnull HttpServletResponse response, @Nonnull KKAppEng kkAppEng) throws HstComponentException { if (!kkAppEng.isKkCookieEnabled()) { return null; } /* * The current customer should at this point be a guest customer with a negative customer id */ CustomerIf currentCustomer = kkAppEng.getCustomerMgr().getCurrentCustomer(); if (currentCustomer == null) { log.warn( "Current customer is set to null in the manageCookies method. This should never happen"); return null; } /* * Get the customerUuid from the browser cookie. A new cookie is created if it doesn't exist */ String customerUuid = getCustomerUuidFromBrowserCookie(request, response); /* * Get the guestCustomerId from the KK database. */ String guestCustomerIdStr = getKKCookie(customerUuid, GUEST_CUSTOMER_ID, kkAppEng); if (guestCustomerIdStr == null) { /* * If it doesn't exist, then we create it */ setKKCookie( customerUuid, GUEST_CUSTOMER_ID, Integer.toString(currentCustomer.getId()), kkAppEng); } else { /* * Set the current customer id with the one retrieved from the cookie and fetch any cart * items that he may have. */ currentCustomer.setId(Integer.parseInt(guestCustomerIdStr)); try { kkAppEng.getBasketMgr().getBasketItemsPerCustomer(); } catch (Exception e) { throw new HstComponentException(e); } if (kkAppEng.getWishListMgr().allowWishListWhenNotLoggedIn()) { try { kkAppEng.getWishListMgr().fetchCustomersWishLists(); } catch (Exception e) { throw new HstComponentException(e); } } // Get the product page size String prodPageSizeStr = getKKCookie(customerUuid, TAG_PROD_PAGE_SIZE, kkAppEng); if (prodPageSizeStr != null && prodPageSizeStr.length() > 0) { try { int prodPageSize = Integer.parseInt(prodPageSizeStr); kkAppEng.getProductMgr().setMaxDisplaySearchResults(prodPageSize); } catch (NumberFormatException e) { log.warn( "The product page size value stored in the cookie for customer with guest id " + guestCustomerIdStr + " is not a numeric value: " + prodPageSizeStr); } } // Get the order page size String orderPageSizeStr = getKKCookie(customerUuid, TAG_ORDER_PAGE_SIZE, kkAppEng); if (orderPageSizeStr != null && orderPageSizeStr.length() > 0) { try { int orderPageSize = Integer.parseInt(orderPageSizeStr); kkAppEng.getOrderMgr().setPageSize(orderPageSize); } catch (NumberFormatException e) { log.warn( "The order page size value stored in the cookie for customer with guest id " + guestCustomerIdStr + " is not a numeric value: " + orderPageSizeStr); } } // Get the review page size String reviewPageSizeStr = getKKCookie(customerUuid, TAG_REVIEW_PAGE_SIZE, kkAppEng); if (reviewPageSizeStr != null && reviewPageSizeStr.length() > 0) { try { int reviewPageSize = Integer.parseInt(reviewPageSizeStr); kkAppEng.getReviewMgr().setPageSize(reviewPageSize); } catch (NumberFormatException e) { log.warn( "The review page size value stored in the cookie for customer with guest id " + guestCustomerIdStr + " is not a numeric value: " + reviewPageSizeStr); } } } if (log.isDebugEnabled()) { log.debug( "GUEST_CUSTOMER_ID cookie value = " + getKKCookie(customerUuid, GUEST_CUSTOMER_ID, kkAppEng)); log.debug( "CUSTOMER_NAME cookie value = " + getKKCookie(customerUuid, CUSTOMER_NAME, kkAppEng)); log.debug( "CUSTOMER_LOCALE cookie value = " + getKKCookie(customerUuid, CUSTOMER_LOCALE, kkAppEng)); log.debug( "PROD_PAGE_SIZE cookie value = " + getKKCookie(customerUuid, TAG_PROD_PAGE_SIZE, kkAppEng)); log.debug( "ORDER_PAGE_SIZE cookie value = " + getKKCookie(customerUuid, TAG_ORDER_PAGE_SIZE, kkAppEng)); log.debug( "REVIEW_PAGE_SIZE cookie value = " + getKKCookie(customerUuid, TAG_REVIEW_PAGE_SIZE, kkAppEng)); } return customerUuid; }