Class VoucherService
- Namespace
- Dynamicweb.Ecommerce.Orders.Vouchers
- Assembly
- Dynamicweb.Ecommerce.dll
Manages vouchers: reading them, generating new codes for a voucher list, validating a code before it is accepted on an order, and marking it as used once the order is placed.
public class VoucherService
- Inheritance
-
VoucherService
- Inherited Members
Methods
CheckVouchers(IEnumerable<string>)
Gets the subset of the given codes that exist as vouchers.
public virtual IEnumerable<string> CheckVouchers(IEnumerable<string> vouchers)
Parameters
vouchersIEnumerable<string>The voucher codes to look for.
Returns
Delete(Voucher)
Deletes a voucher.
public virtual void Delete(Voucher voucher)
Parameters
voucherVoucherThe voucher to delete.
GenerateVoucher(int, int)
Generates a single voucher code for a voucher list.
public virtual string GenerateVoucher(int listId, int numberOfSymbols = 8)
Parameters
listIdintThe voucher list to add the code to.
numberOfSymbolsintThe length of the generated code.
Returns
GenerateVouchers(int, int, int)
Generates voucher codes for a voucher list. Each code is unique among the existing vouchers.
public virtual IEnumerable<string> GenerateVouchers(int number, int listId, int numberOfSymbols = 8)
Parameters
numberintHow many codes to generate.
listIdintThe voucher list to add the codes to.
numberOfSymbolsintThe length of each generated code.
Returns
GetAllVouchers()
Gets every voucher, across all voucher lists.
public virtual IEnumerable<Voucher> GetAllVouchers()
Returns
GetAllVouchersForList(int)
Gets the vouchers belonging to a voucher list.
public virtual IEnumerable<Voucher> GetAllVouchersForList(int listId)
Parameters
listIdintThe voucher list identifier.
Returns
GetVoucherByCode(string)
Gets a voucher by its code.
public virtual Voucher? GetVoucherByCode(string voucherCode)
Parameters
voucherCodestringThe voucher code.
Returns
- Voucher
The voucher, or
nullwhen no voucher has that code.
GetVoucherByCode(string, int)
Gets a voucher by its code within a specific voucher list.
public virtual Voucher? GetVoucherByCode(string voucherCode, int listId)
Parameters
Returns
- Voucher
The voucher, or
nullwhen that list has no voucher with that code.
GetVoucherById(int)
Gets a voucher by its identifier.
public virtual Voucher? GetVoucherById(int id)
Parameters
idintThe voucher identifier.
Returns
- Voucher
The voucher, or
nullwhen no voucher has that identifier.
GetVoucherCodesFromString(string)
Splits a voucher code string into the individual codes it contains.
public virtual IEnumerable<string> GetVoucherCodesFromString(string voucherCodesString)
Parameters
voucherCodesStringstringOne or more voucher codes, separated by comma, semicolon or space.
Returns
- IEnumerable<string>
The codes, or an empty sequence when the string holds none.
GetVoucherListUsings(IEnumerable<VoucherList>)
Gets how many orders have used vouchers from each of the given voucher lists.
public virtual IEnumerable<VoucherListUsing> GetVoucherListUsings(IEnumerable<VoucherList> voucherLists)
Parameters
voucherListsIEnumerable<VoucherList>The voucher lists to count usage for.
Returns
HasAnyVoucherCode(VoucherList, IEnumerable<string>, bool, bool)
Gets a value indicating whether any of the given codes belongs to the given voucher list.
public virtual bool HasAnyVoucherCode(VoucherList list, IEnumerable<string> codes, bool searchInActiveListsOnly, bool checkUnusedCodesOnly)
Parameters
listVoucherListThe voucher list to search. Returns
falsewhennull.codesIEnumerable<string>The voucher codes to look for.
searchInActiveListsOnlyboolWhen
true, an inactive list never matches.checkUnusedCodesOnlyboolWhen
true, an already used voucher never matches.
Returns
IsValidVoucher(string)
Validates a voucher code with comprehensive checks including voucher list status, discount matrix, and loyalty rewards.
public virtual bool IsValidVoucher(string voucherCode)
Parameters
voucherCodestringThe voucher code to validate
Returns
- bool
True if the voucher is valid and can be used; otherwise, false
IsValidVoucher(string, int)
Validates a voucher code with comprehensive checks including voucher list status, discount matrix, and loyalty rewards.
public virtual bool IsValidVoucher(string voucherCode, int listId)
Parameters
Returns
- bool
True if the voucher is valid and can be used; otherwise, false
MarkVoucherAsUsed(string, string)
Marks the vouchers in a code string as used by an order. Only unused vouchers belonging to an active voucher list are marked, and nothing happens when the order does not accept vouchers.
public virtual void MarkVoucherAsUsed(string voucherCode, string orderId)
Parameters
voucherCodestringOne or more voucher codes, separated by comma, semicolon or space.
orderIdstringThe identifier of the order using the vouchers.
Save(Voucher)
Creates or updates a voucher.
public virtual void Save(Voucher voucher)
Parameters
voucherVoucherThe voucher to save.
UpdateVouchersOrderId(string, string)
Moves the unused vouchers reserved for one order over to another order.
public virtual void UpdateVouchersOrderId(string orderId, string newOrderId)
Parameters
orderIdstringThe order the vouchers are currently reserved for.
newOrderIdstringThe order to move them to.
UpdateVouchersStatus(int, string)
Sets the status on every voucher in a list that does not have one yet.
public virtual void UpdateVouchersStatus(int listId, string status)