Skip to Content
author's profile photo Former Member
Former Member

Anonymous Cart Restoration Issue-Unable to get added products after re-opening same browser

Hi Experts,

We are using Hybris 5.1 version.

Issue: Opened my web site and added one product to cart , mini cart I can see one product in top right, then closed my browser totally for a while( even not more than a minute) . Restarted my browser and went to my web site again, there is no added product in the mini cart. I need to get previously added mini cart product in web site cart (with out adding again) after reopening in the same browser.

Could you please any one help on this Anonymous Cart Restoration Issue ? Thanks in advance.

Regards, Bala.

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Posted on Jul 29, 2016 at 08:32 AM

    CartRestorationFilter.java

    public void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain) throws IOException, ServletException { if (getUserService().isAnonymousUser(getUserService().getCurrentUser())) { if (getCartService().hasSessionCart() && getBaseSiteService().getCurrentBaseSite().equals( getBaseSiteService().getBaseSiteForUID(getCartService().getSessionCart().getSite().getUid()))) { final String guid = getCartService().getSessionCart().getGuid();

                 if (!StringUtils.isEmpty(guid))
                 {
                     getCartRestoreCookieGenerator().addCookie(response, guid);
                 }
             }
             else if (request.getSession().isNew()
                     || (getCartService().hasSessionCart() && !getBaseSiteService().getCurrentBaseSite().equals(
                             getBaseSiteService().getBaseSiteForUID(getCartService().getSessionCart().getSite().getUid()))))
             {
                 String cartGuid = null;
    
                 if (request.getCookies() != null)
                 {
                     final String anonymousCartCookieName = getCartRestoreCookieGenerator().getCookieName();
    
                     for (final Cookie cookie : request.getCookies())
                     {
                         if (anonymousCartCookieName.equals(cookie.getName()))
                         {
                             cartGuid = cookie.getValue();
                             break;
                         }
                     }
                 }
    
                 if (!StringUtils.isEmpty(cartGuid))
                 {
                     getSessionService().setAttribute(WebConstants.CART_RESTORATION_SHOW_MESSAGE, Boolean.TRUE);
                     try
                     {
                         getSessionService().setAttribute(WebConstants.CART_RESTORATION, getCartFacade().restoreSavedCart(cartGuid));
                     }
                     catch (final CommerceCartRestorationException e)
                     {
                         getSessionService().setAttribute(WebConstants.CART_RESTORATION_ERROR_STATUS,
                                 WebConstants.CART_RESTORATION_ERROR_STATUS);
                     }
                 }
             }
    
         }
         else
         {
             if ((!getCartService().hasSessionCart() && getSessionService().getAttribute(WebConstants.CART_RESTORATION) == null)
                     || (getCartService().hasSessionCart() && !getBaseSiteService().getCurrentBaseSite().equals(
                             getBaseSiteService().getBaseSiteForUID(getCartService().getSessionCart().getSite().getUid()))))
             {
                 getSessionService().setAttribute(WebConstants.CART_RESTORATION_SHOW_MESSAGE, Boolean.TRUE);
                 try
                 {
                     getSessionService().setAttribute(WebConstants.CART_RESTORATION, getCartFacade().restoreSavedCart(null));
                 }
                 catch (final CommerceCartRestorationException e)
                 {
                     getSessionService().setAttribute(WebConstants.CART_RESTORATION, WebConstants.CART_RESTORATION_ERROR_STATUS);
                 }
             }
         }
    
         filterChain.doFilter(request, response);
     }
    
    

    This filter has logic for the cart restoration.

    Debug the below files also : CartRestoreCookieGenerator.java EnhancedCookieGenerator.java

    CartFacade.java CartRestorationData restoreSavedCart(String code) throws CommerceCartRestorationException;

    Disable the cart removal cron job:
    https://wiki.hybris.com/display/release5/Removing+Old+Carts+with+Cronjob

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 28, 2016 at 12:18 PM

    Check your browser settings if it deletes cookies with shutdown. as long the cookies are available for the site you should be able to see the data.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.