on ‎2018 Oct 06 12:15 AM
As per the Voucher documentation, the voucher should not be redeemed more than redemptionQuantityLimit or redemptionQuantityLimitPerUser. but it is not happening. Voucher is getting applied more than the number of times assigned in the two attributes.
I have debugged the code and found that in voucher service there are two methods to redeemvoucher.
1) public boolean redeemVoucher(String voucherCode, CartModel cart)
throws JaloPriceFactoryException
{
saveIfModified(cart);
boolean changed = VoucherManager.getInstance().redeemVoucher(voucherCode, getCart(cart));
if (changed)
{
refresh(cart);
}
return changed;
}
2) public VoucherInvalidationModel redeemVoucher(String voucherCode, OrderModel order)
{
saveIfModified(order);
VoucherInvalidation voucherInvalidation=VoucherManager.getInstance().redeemVoucher(voucherCode,getOrder(order));
if (voucherInvalidation == null)
{
return null;
}
refresh(order);
return ((VoucherInvalidationModel)getModelService().get(voucherInvalidation));
}
In the wiki, it is mentioned that when a voucher is applied, an entry should be created in VoucherInvalidation table with a promotion code, order code, and user. This will be created only when the second method is called. But somehow this method is not getting called. always the first method is getting called hence there is no way to check that the voucher is used by the user of a given number of times.
Please help me out on this. why this is implemented like this. though we have attributes restrict the voucher to given number of times, why it is not working as expected.
Request clarification before answering.
Hi Bhaskar , Did you get solution/ work around for this, having same issue, set limit to 1 but able to use more than 1.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Himanshu, This is what I mentioned in my original questions. The methods are available. but these are not getting called anywhere in the extension's code. then how come you are able to restrict the voucher redemption?.
my problem is I have created a voucher with limit 3 per user. but redeemption limit is not working.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Bhaskar,
you need to check in the voucher.class, this code snippet creates the invalidation object.
public VoucherInvalidation redeem(final String aVoucherCode, final Order anOrder) {
if (!this.checkVoucherCode(aVoucherCode)) {
return null;
}
VoucherInvalidation invalidation = this.getInvalidation(aVoucherCode, anOrder);
if (invalidation == null) {
invalidation = this.reserve(aVoucherCode, anOrder);
}
if (invalidation == null || "confirmed".equals(invalidation.getStatus())) {
return null;
}
invalidation.setStatus("confirmed");
return invalidation;
}
public VoucherInvalidation reserve(final String aVoucherCode, final Order anOrder) {
if (this.checkVoucherCode(aVoucherCode) && this.isReservable(aVoucherCode, (AbstractOrder)anOrder)) {
anOrder.addDiscount((Discount)this);
return this.createVoucherInvalidation(aVoucherCode, anOrder);
}
return null;
}
So, the invalidation object is only created after the at the time of order creation. Once the order is placed, the invalidation object is created and the user is restricted from adding the voucher to the cart if the coupon is not reservable.
Hope this helps.
thanks,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Himanshu, Thanks for your reply. yes, you are right. For promotional vouchers, the number of times the coupon is redeemed can be configurable. but it is not working though I configured both the attributes.
redemptionQuantityLimit and redemptionQuantityLimitPerUser
return getInvalidations(aVoucherCode, user ).size() < getRedemptionQuantityLimitPerUserAsPrimitive()
First inorder to validate the above condition which you have referred above. the VoucherInvalidation object should be created and saved whenever a Voucher is redeemed right. The code to create this instance is nowhere getting called.
Please let me know how this is working for you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Bhaskar,
if you check the code for DefaultVoucherRedemptionPlaceOrderMethodHook, you will see beforeSubmitOrder() the getVoucherService().redeemVoucher(voucherCode, orderModel);method is called from.
For more information please refer here
https://help.hybris.com/1808/hcd/8c7ff2918669101483ddd711fc3f5df5.html
public boolean isReservable( String aVoucherCode, User user )
{
return getInvalidations(aVoucherCode, user ).size() < getRedemptionQuantityLimitPerUserAsPrimitive()
&& getInvalidations( aVoucherCode ).size() < getRedemptionQuantityLimitAsPrimitive();
}
determines if the coupon is reservable, and is called at the time of redeemVoucher(String voucherCode, CartModel cart) for Promotional Vouchers, for serial voucher it checks
public boolean isReservable(final String aVoucherCode, final User user) {
return this.getInvalidations(aVoucherCode).isEmpty();
}
ie. for serialVouchers the voucher can be applied only once per user but for promotional vouchers the number of time the coupon is redeemed is configurable.
Hope this help you.
Thanks,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 1 | |
| 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.