cancel
Showing results for 
Search instead for 
Did you mean: 

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

Former Member
0 Kudos
1,465

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

View Entire Topic
former_member674342
Active Participant
0 Kudos

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,

Former Member
0 Kudos

Thanks