1 2 Previous Next 16 Replies Latest reply: Nov 20, 2012 6:42 AM by 877508 RSS

    Many coupons in order

    973908
      Hi All!

      Need to be able to use a lot of coupons to the same order. OOTB can use only one coupon to order. How to implement this functionality? (ATG 10.0.x)

      Edited by: Yury Gerzhedovich on 15.11.2012 13:44
        • 1. Re: Many coupons in order
          Praveer.Rai
          hi Yury,

          AFAIK any number of coupons can be applied OOTB.
          what is the issue you are facing in applying multiple coupons ?
          ---
          Praveer

          Edited by: Praveer Rai on Nov 15, 2012 5:41 PM
          • 2. Re: Many coupons in order
            973908
            I use<dsp:input bean="StoreCouponFormHandler.couponCode". He takes one coupon code to the input. Could you provide code for many coupons?

            Edited by: Yury Gerzhedovich on 15.11.2012 16:55
            • 3. Re: Many coupons in order
              Nitin Khare
              I believe the StoreCouponFormHandler which you are using, it would be extending from the OOB CouponFormHandler and it would be invoking its handleClaimCoupon() method only. The default CouponFormHandler.handleClaimCoupon() internally calls ClaimableManager.claimCoupon(profileId, couponClaimCode) which attempts to grant the coupons' associated promotion to the current user. So one simple approach can be to add a new handler method within your custom CouponFormHandler which can accept multiple coupon codes so you can hook it with your UI and then within your formhandler's new handle method invoke ClaimableManager.claimCoupon() for each of the coupon input.
              • 4. Re: Many coupons in order
                Praveer.Rai
                Ok Got it , so you want to apply more than one coupon at a go...

                create your class MyCouponFormHandler extending StoreCouponFormHandler ,
                Create a properties file CouponFormHandler.properties and give class as MyCouponFormHandler

                Create an private Array<String> variable say coupons with public getters and setters.

                from JSP set the values as :

                <dsp:input bean="CouponFormHandler.coupons[0]....."
                <dsp:input bean="CouponFormHandler.coupons[1]....."
                <dsp:input bean="CouponFormHandler.coupons[2]....." and so on..

                override the method handleClaimCoupon in your class.

                call tender coupon method of purchase process helper for all values of coupon :
                for ( String coupon : coupons ) {
                boolean result= ((StorePurchaseProcessHelper) getPurchaseProcessHelper()).tenderCoupon(coupon, getOrder(), getProfile(), getUserPricingModels(), getUserLocale());
                }

                You will have to give a thought on what you will do if one of the coupon is invalid or fails - handle the result accr to boolean returned by the method.

                ```
                Praveer
                • 5. Re: Many coupons in order
                  karthik chopperla
                  Since we do not know the number of coupons user wants to enter, we cannot have CouponFormHandler.coupons[0] and so on.

                  It would be better to ask users to enter them with comma seperated and we parse the string internally in handleClaimCoupon and call OOTB for each coupon same as praveer suggested.

                  -karthik

                  Edited by: karthik chopperla on Nov 15, 2012 12:16 PM
                  • 6. Re: Many coupons in order
                    973908
                    I tried this method - is used, only the last code from the list
                    • 7. Re: Many coupons in order
                      Praveer.Rai
                      Enable logDebug on following components and check server log after applying codes:

                      CouponFormHandler
                      ClaimableManager
                      PromotionTools


                      ```
                      Praveer
                      • 8. Re: Many coupons in order
                        973908
                        I turn on debug info. For example we have 2 coupons.
                        First coupon apply and calculate discount. But for next coupons we have old price value (not calculated of the first coupon). As a result apply only last coupon code.
                        • 9. Re: Many coupons in order
                          Praveer.Rai
                          try calling claimCoupon(String pCouponCode,StoreOrderImpl pOrder,RepositoryItem pProfile,boolean pRepriceOrder,PricingModelHolder pUserPricingModels,Locale pUserLocale) method of StorePurchaseProcessHelper , pass pRepriceOrder as true , debug in this method if you still get issue.


                          for ( String coupon : coupons ) {
                          ((StorePurchaseProcessHelper) getPurchaseProcessHelper()).claimCoupon(coupon, getOrder(), getProfile(),true, getUserPricingModels(), getUserLocale()) ;
                          }


                          ```
                          Praveer
                          • 10. Re: Many coupons in order
                            973908
                            after calling claimCoupon more than once I have
                            java.lang.IllegalArgumentException: There is a coupon claimed for order specified!
                            at atg.projects.store.order.purchase.StorePurchaseProcessHelper.claimCoupon(StorePurchaseProcessHelper.java:596)

                            Unfortunately I haven't source code, but after decompilation I see that this exception throws if order already have coupon code
                            if (!StringUtils.isEmpty(pOrder.getCouponCode())) {
                            throw new IllegalArgumentException("There is a coupon claimed for order specified!");
                            }

                            I tried remove code from order for each iteration. For this case apply only first coupon from list.
                            • 11. Re: Many coupons in order
                              Praveer.Rai
                              yeah , CRS is customised to allow user to enter one coupon only , you can override and remove that part of code.

                              Also note that if some exception(like coupon already applied , not eligible etc) is coming in applying any of the coupons , that transaction will be rolled back.


                              ```
                              Praveer

                              Edited by: Praveer Rai on Nov 16, 2012 7:02 PM
                              • 12. Re: Many coupons in order
                                973908
                                Could you explain. Do you mean override claimCoupon in StorePurchaseProcessHelper?

                                Ie something like this?

                                public void claimCoupon(String pCouponCode, StoreOrderImpl pOrder, RepositoryItem pProfile, boolean pRepriceOrder, PricingModelHolder pUserPricingModels, Locale pUserLocale)
                                throws CommerceException, IllegalArgumentException
                                {
                                getClaimableManager().claimCoupon(pProfile.getRepositoryId(), pCouponCode);
                                }
                                • 13. Re: Many coupons in order
                                  Praveer.Rai
                                  yeah ,

                                  also do reprising after applying each coupon.Claim coupon will not reprise automatically.Also use transaction.

                                  public void claimCoupon(String pCouponCode, StoreOrderImpl pOrder, RepositoryItem pProfile, boolean pRepriceOrder, PricingModelHolder pUserPricingModels, Locale pUserLocale)
                                  throws CommerceException, IllegalArgumentException
                                  {
                                  // begin transaction
                                  getClaimableManager().claimCoupon(pProfile.getRepositoryId(), pCouponCode);
                                  pUserPricingModels.initializePricingModels();
                                  repriceOrder(pOrder, pUserPricingModels, pUserLocale, pProfile);
                                  //end transaction
                                  }
                                  • 14. Re: Many coupons in order
                                    Georgeo-Oracle
                                    Yury,
                                    Please note that decompilation of proprietary Oracle ATG code is a breach of the license agreement as well as a violation of US Copyright Law. Please remove any decompiled code and cease any further decompilation or the violation will be reported to the Oracle legal department for further investigation and action.

                                    In this case, the source code to the Commerce Reference Store is included with the product. You can find the source to that class here (at least it is there in my 10.1 install):

                                    {ATG Root}\CommerceReferenceStore\Store\EStore\src\atg\projects\store\order\purchase\StorePurchaseProcessHelper.java

                                    - George
                                    1 2 Previous Next