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,447

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

Accepted Solutions (1)

Accepted Solutions (1)

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

Answers (1)

Answers (1)

Former Member
0 Kudos

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