on 2015 Nov 09 5:34 AM
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
Request clarification before answering.
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,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
18 | |
3 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.