2 Replies Latest reply: Oct 7, 2011 5:52 AM by 892582 RSS

    Persistent Shopping Bag for anonymous users at 1st item addition

    892582
      Hi,

      Can anybody suggest me how to implement Persistent Shopping Bag for anonymous users only at 1st item addition in ATG.

      I know there is OOTB steps to Persist Shopping Bag for anonymous users but this happens for every site access which is not a correct behavior.

      Based on my requirement I need to persist Shopping Bag for anonymous users only when user has added his 1st item in the basket.

      To achieve the same I tried to change transient property of the order to false in preAddItemToOrder method in my CartFormHandler but this is not taking effect.

      this.getOrder().setTransient(false);

      transient property of the order always remains true for anonymous users in spite of changing it forcefully.

      Any help would be appreciated.

      Thanks
      Atal

      Edited by: 889579 on Oct 6, 2011 3:23 AM
        • 1. Re: Persistent Shopping Bag for anonymous users at 1st item addition
          Gurvinder
          You can override the CartModifierFormHandler's postAddItemtoOrder() and check if the order is transient and has atleast one commerceitem then
          call OrderManager.addOrder(order);
          This should save your order to repository.

          Thanks
          • 2. Re: Persistent Shopping Bag for anonymous users at 1st item addition
            892582
            Thanks for your response.

            I have achieved this by calling addOrderToRepository link in pipeline as

            <pipelinechain name="addAnonymousOrder" transaction="TX_REQUIRED" headlink="addOrderToRepository3" xml-combine="append">
            <pipelinelink transaction="TX_MANDATORY" name="addOrderToRepository3">
            <processor jndi="/atg/commerce/order/processor/AddOrderToRepository"/>
            </pipelinelink>
            </pipelinechain>


            And changed postAddItemToOrder method as

            Map<String, Object> map = new HashMap<String, Object>();
            Locale userLocale = ServletUtil.getUserLocale();
                           map.put(PipelineConstants.ORDER, this.getOrder());
                           map.put(PipelineConstants.ORDERMANAGER, this.getOrderManager());
                           map.put(PipelineConstants.LOCALE, userLocale);
            PipelineResult result;
                           try {
                                result = getCommercePipelineManager().runProcess(getChainToRun(), map);
                 PipelineUtils.processPipelineErrors(result, this, null);
                           } catch (RunProcessException e) {
                      if (isLoggingError()) {
                                     logError("addItemToOrder() Pipeline execution exception = " + e);
                                }
                           }

            This has persisted the order but actually his will not help me completely.

            Because to retrieve the same I also need to persist the profile after adding 1st item to basket. Which is still not clear, how to achieve so that it create DYN_USER_ID cookie and persist the profile.

            Any idea?

            Thanks
            Atal