We needed to make some additional options for the voucher discount, so we made a custom discount provider.
The problem is when we have to set the voucher as used, we try doing MarkAsUsed, but it dosen't seem to do anything.
What am i doing wrong here:
[Dynamicweb.Extensibility.Subscribe(Dynamicweb.Notifications.eCommerce.Cart.CheckoutDoneOrderIsComplete)]
public class OrderCompleteVoucherUpdate : Dynamicweb.Extensibility.NotificationSubscriber
{
public override void OnNotify(string notification, Dynamicweb.Extensibility.NotificationArgs args)
{
var myArgs = (Dynamicweb.Notifications.eCommerce.Cart.CheckoutDoneOrderIsCompleteArgs)args;
Order order = myArgs.Order;
Voucher.MarkAsUsed(order.VoucherCode, order.ID);
}
}
It does nothing, i then tried updaing the fields manually - which works, but you don't have access to all Voucher fields (like discount and so on)
[Dynamicweb.Extensibility.Subscribe(Dynamicweb.Notifications.eCommerce.Cart.CheckoutDoneOrderIsComplete)]
public class OrderCompleteVoucherUpdate : Dynamicweb.Extensibility.NotificationSubscriber
{
public override void OnNotify(string notification, Dynamicweb.Extensibility.NotificationArgs args)
{
var myArgs = (Dynamicweb.Notifications.eCommerce.Cart.CheckoutDoneOrderIsCompleteArgs)args;
Order order = myArgs.Order;
Voucher.MarkAsUsed(order.VoucherCode, order.ID);
Voucher orderVoucher = Voucher.GetVoucherByCode(order.VoucherCode);
orderVoucher.UsedOrderID = order.ID;
orderVoucher.DateUsed = order.Date;
orderVoucher.Status = "Used";
orderVoucher.Save();
}
}
Any ideas on what im doing wrong?