Page 1 of 1

Bypassing the Item link to see the product into the cart

Posted: Fri Feb 28, 2014 2:43 am
by henry
Hi ,when i click on buy now button the product is added to cart and after click of Item link i can see my product to cart page.Now my requirement is that i need to bypass the Item Link ,instead of clicking Item Link to see product in cart i want to directly jump to cart page by clicking on new Button OrderNow.So i can directly see my product in cart page without Clicking of item link .

what i tried to do is calling the this.addJson() so the product is able to add on cart page.When i directly provide the url

Code: Select all

http://localhost:8080/mycompany/cart/
i can see my product in cart page, but when i tried to do same thing by click on order now button i am not able to redirect to cart page.
method on CartController.java

Code: Select all

@RequestMapping(value="/orderNow",produces = "application/json")
   public String quickOrder(HttpServletRequest request,HttpServletResponse response, Model model,@ModelAttribute("addToCartItem") AddToCartItem addToCartItem)
         throws IOException, PricingException, AddToCartException {
      this.addJson(request, response, model, addToCartItem);
      
      return super.cart(request, response, model);
   }


This is the error

Code: Select all

[ERROR] 12:04:50 DefaultErrorHandler - An error occurred during the workflow
org.broadleafcommerce.core.order.service.exception.RequiredAttributeNotProvidedException: Unable to find non-default sku matching given options and cannot sell default sku
   at org.broadleafcommerce.core.order.service.workflow.add.ValidateAddRequestActivity.determineSku(ValidateAddRequestActivity.java:133)
   at org.broadleafcommerce.core.order.service.workflow.add.ValidateAddRequestActivity.execute(ValidateAddRequestActivity.java:82)
   at org.broadleafcommerce.core.order.service.workflow.add.ValidateAddRequestActivity.execute(ValidateAddRequestActivity.java:40)
   at org.broadleafcommerce.core.workflow.SequenceProcessor.doActivities(SequenceProcessor.java:79)
   at org.broadleafcommerce.core.order.service.OrderServiceImpl.addItemWithPriceOverrides(OrderServiceImpl.java:507)
   at org.broadleafcommerce.core.order.service.OrderServiceImpl.addItem(OrderServiceImpl.java:484)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:606)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
   at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
   at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
   at com.sun.proxy.$Proxy290.addItem(Unknown Source)
   at org.broadleafcommerce.core.web.controller.cart.BroadleafCartController.add(BroadleafCartController.java:93)
   at com.mycompany.controller.cart.CartController.addJson(CartController.java:84)
   at com.mycompany.controller.cart.CartController.quickOrder(CartController.java:294)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:606)
   at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
   at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
   at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
   at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
   at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
   at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
   at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
   at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
   at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
   at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
   at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
   at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
   at org.broadleafcommerce.core.web.order.security.CartStateFilter.doFilter(CartStateFilter.java:57)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
   at org.broadleafcommerce.common.web.filter.TranslationFilter.doFilter(TranslationFilter.java:48)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
   at org.broadleafcommerce.cms.web.URLHandlerFilter.doFilterInternal(URLHandlerFilter.java:71)
   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
   at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
   at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:166)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
   at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
   at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
   at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
   at org.broadleafcommerce.profile.web.core.security.SessionFixationProtectionFilter.doFilter(SessionFixationProtectionFilter.java:95)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
   at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
   at org.broadleafcommerce.profile.web.core.security.CustomerStateFilter.doFilter(CustomerStateFilter.java:53)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
   at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:139)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
   at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
   at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
   at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
   at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
   at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
   at org.springframework.security.web.access.channel.ChannelProcessingFilter.doFilter(ChannelProcessingFilter.java:144)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
   at org.broadleafcommerce.common.web.BroadleafRequestFilter.doFilterInternal(BroadleafRequestFilter.java:97)
   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
   at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:180)
   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
   at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
   at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:166)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
   at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
   at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
   at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
   at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
   at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
   at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
   at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
   at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
   at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2430)
   at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2419)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
   at java.lang.Thread.run(Thread.java:744)
[ERROR] 12:04:50 TemplateEngine - [THYMELEAF][http-apr-8080-exec-7] Exception processing template "cart/cart": Exception evaluating SpringEL expression: "cart.subTotal.zero" (cart/cart:13)

Re: Bypassing the Item link to see the product into the cart

Posted: Fri Feb 28, 2014 9:35 am
by RapidTransit
Looks like your request needs to contain a sku id

Re: Bypassing the Item link to see the product into the cart

Posted: Fri Mar 07, 2014 9:13 am
by henry
Hi RapidTransit I am successfully able to get in the cart page but the problem is that i am not able to get the skuid and offerstatus in my controller method parameter addToCartitem cause of that my product is not able to add into cart for that i tried to to ajax call but still i am not able to get it pls see where i am mistaking

this is my ajax call on cartOperation.js

Code: Select all

 $('body').on('click', 'input.redirectTologin', function() {
      
       var $button = $(this),
          $container = $button.closest('.product_container'),
          $form = $button.closest('form'),
          $options = $container.find('span.option-value'),
          $errorSpan = $container.find('span.error');
          $productOptionsSpan = $container.find('span.productOptionsSpan');
      if ($container.length == 0) {
          var myId = $button.parent().attr('id').substring('productOptions'.length);
          $container = $('.productActions' + myId).closest('.product_container');
          $form = $container.find('form');
          $options = $button.parent().find('span.option-value');
          $errorSpan = $button.parent().find('span.error');
          $productOptionsSpan = $container.find('span.productOptionsSpan');
      }
      
       var itemRequest = BLC.serializeObject($form),
          modalClick = $button.parents('.fancybox-inner').length > 0,
          wishlistAdd = $button.hasClass('addToWishlist');
         
          if (itemRequest.hasProductOptions == "true" && !modalClick) {
          $.fancybox.open($.extend({ href : '#productOptions' + itemRequest.productId}, fancyProductOptionsOptions));
      } else {
          $options.each(function(index, element) {
             var optionType = $(element).data('optiontype');
             var value;
             
             if ("TEXT" == optionType) {
                value = $(element).next().find('input').val();
             } else {
             var   value = $(element).text();
             }//need to add other types(date,long, etc) as needed
             $("#sizeVarience").val(value);
             itemRequest['itemAttributes[' + $(element).attr('id') + ']'] = value;
          });
         BLC.ajax({url: $form.attr('action'),
                    type: "POST",
                    dataType: "json",
                    data: itemRequest
                }, function(data, extraData) {}
                    alert("yeah its returning something after success");
            );
         }
      
    });


This is my product.html
snippet

Code: Select all

   <blc:form method="POST" th:action="@{/cart/anonymousOrder}" id="orderNow">
                     <div th:class="*{'productActions' + id}">
                        <div class="in_cart"
                           th:classappend="${!cart.containsSku(#object.defaultSku)}? ' hidden'">
                           <a class="fancycart fancybox.ajax big-button gray-button"
                              th:href="@{/cart}">In Cart!</a>
                        </div>
                        <div class="add_to_cart prod-details-addto-cart"
                           th:classappend="${cart.containsSku(#object.defaultSku)}? ' hidden'">
                           <input type="hidden" name="productId" th:value="*{id}" /> <input
                              type="hidden" name="quantity" value="1" />
                              <input type="hidden" id="sizeVarience" name="sizeVarience" />
                              <input type="submit" class="redirectTologin order-now-butt" th:value="#{order.now}"/>
                        </div>
                        <p class="error" th:if="${param.errorMessage}"
                           th:text="${param.errorMessage[0]}"></p>
                     </div>
                  </blc:form>


This is the modify method of quickOrder()

Code: Select all

@RequestMapping(value = "/anonymousOrder")
   public String quickOrder(HttpServletRequest request,
         HttpServletResponse response, Model model,
         @ModelAttribute("addToCartItem") AddToCartItem addToCartItem)
         throws IOException, PricingException, AddToCartException {
      Map<String, String> itemAttribute = addToCartItem.getItemAttributes();
      String size = request.getParameter("sizeVarience");
      HttpSession session = request.getSession();
      if (CustomerState.getCustomer().isAnonymous()) {
         //String referrer = request.getHeader("Referer");
      //   session.setAttribute("referrer", referrer);
         String referrer1 = "/cart/anonymousOrder";
         itemAttribute.put("OfferStatus", "NoOffer");
         itemAttribute.put("Size_" + addToCartItem.getProductId(), "M");
         addToCartItem.setItemAttributes(itemAttribute);
         session.setAttribute("addToCart", addToCartItem);
         session.setAttribute("url_prior_login", referrer1);
         // model.addAttribute("addToCartItem", addToCartItem);
         return "redirect:login";
      } else {
         AddToCartItem addToCartItem1 = (AddToCartItem) session
               .getAttribute("addToCart");
         session.removeAttribute("addToCart");
         //String url = (String) session.getAttribute("referrer");
      //   session.removeAttribute("referrer");
         this.addJson(request, response, model, addToCartItem1);
         RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
         redirectStrategy.sendRedirect(request, response, "/cart");
         return null;
      }

   }