Hello,
I'm trying to migrate from a custom voucher system used on DW7 to the new Vouchers discounts of DW8.
Having voucher codes on a custom table (DQVouchers1) where I can see the voucher is used if it has an OrderId filled on the record, I use something like this:
var allVoucherLists = VoucherList.GetAllVoucherLists();
var table1List = allVoucherLists.FirstOrDefault(p => p.ListName == "25% Discount");
if (table1List != null)
{
DataContext dc = new DataContext();
var dqVouchers1 = dc.DQVouchers1s.ToList();
foreach (var dqVoucher in dqVouchers1)
{
var isValid = Voucher.isValid(dqVoucher.Code, table1List.ID);
if (!isValid)
{
dc.EcomVouchers.InsertOnSubmit(new EcomVoucher { VoucherCode = dqVoucher.Code, VoucherListID = table1List.ID });
dc.SubmitChanges();
if (!string.IsNullOrEmpty(dqVoucher.OrderId) && dqVoucher.OrderId != "0")
{
Voucher.MarkAsUsed(dqVoucher.Code, dqVoucher.OrderId);
}
}
}
}
else
{
Log.Error("There isn't a voucher list «25% Discount». It must be created!");
}
I am getting errors on the function Voucher.isValid(...) where the voucher code exists on the list, and on the function Voucher.MarkAsUsed(...).
I get exceptions "Object reference not set to an instance of an object.", and all the arguments are not null.
For the function Voucher.isValid() I can check the database, but I don't know how to mark a voucher as used without the function Voucher.MarkAsUsed(), because I don't know what to put on the varchar "VoucherStatus" of the table.
Any help?
Thanks,
Diogo Lino