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

How can we set start date is today date and end date is greater than start date

Hi ,

can any one suggest to set up start date as todays date ans end date as greater than start date in promotions

thanks in advance

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    Posted on Nov 10, 2015 at 08:43 AM

    Hello ,

    I have checked how you can do that, and i found two ways for it.

    The first one is to overwrite the defaultvalue for startDate and endDate in a new extension and overwrite this attributes in the items.xml file in the extension. I have made a simple class to do this:

     public final class CreateDate {
          private static Date currentDate = new Date();
      public static Date CreatePromotionTimeStart() {
           return currentDate;
       }
      
       public static Date CreatePromotionTimeEnd(final int promotionDurationTimeInDays) {
           final Calendar cal = Calendar.getInstance();
           cal.setTime(currentDate);
           cal.add(Calendar.DATE, promotionDurationTimeInDays);
           currentDate = cal.getTime();
      
           return currentDate;
       }
     }
    
    

    In the items.xml:

     <defaultvalue>             
                de.hybris.merchandise.CreateDate.CreatePromotionTimeStart() //startDate
                de.hybris.merchandise.CreateDate.CreatePromotionTimeEnd(10) //endDate
      </defaultvalue>;
    
    

    The second way to make this work is to create a InitDefaultsInterceptor.

    For this I have also made a class:

     public class DateInterceptor implements InitDefaultsInterceptor {
          private int promotionLength;
       @Override
       public void onInitDefaults(final Object arg0, final InterceptorContext arg1) throws InterceptorException {
           if (arg0 instanceof AbstractPromotionModel) {
               final Date currentDate = new Date();
               final AbstractPromotionModel apm = (AbstractPromotionModel) arg0;
      
               apm.setStartDate(currentDate);
               final Calendar cal = Calendar.getInstance();
               cal.setTime(currentDate);
               cal.add(Calendar.DATE, promotionLength);
      
               apm.setEndDate(cal.getTime());
           }
       }
    
    
    

    In the extension-spring.xml:

     <bean id="DateInterceptor" class="de.hybris.merchandise.interceptors.DateInterceptor" >;
              <property name="promotionLength" value="15" />
          </bean>
       <bean id="StadiumInterceptorMapping"
           class="de.hybris.platform.servicelayer.interceptor.impl.InterceptorMapping">
           <property name="interceptor" ref="DateInterceptor" />
           <property name="typeCode" value="AbstractPromotion" />
       </bean>
       
    
    

    Feel free to use/modify/extend the code if you want to. I hope that it helps you Best regards,

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 09, 2015 at 09:20 AM

    Hi Prasad,

    you can achieve this goal by following three ways.

    1. when you creating custom promotion by Impex then use default values for date for start date and for future you can use any constant date value.

    2. you can also provide default values in your items.xml.

    3. you need to write an Interceptor so that you can provide custom date values before saving promotion to hybris database. please follow the page so that you can easily create custom interceptor https://wiki.hybris.com/display/release5/Interceptors.

    Thanks

    Raushan

    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.