Class LoyaltyService
- Namespace
- Dynamicweb.Ecommerce.Loyalty
- Assembly
- Dynamicweb.Ecommerce.dll
public class LoyaltyService : ICacheStorage<int, Reward>, ICacheStorage<int>, ICacheStorage
- Inheritance
-
LoyaltyService
- Implements
- Inherited Members
Properties
AllowEarnPointsFromPurchasedPoints
Gets the value indicating whether the buying items with points should earn more points.
public virtual bool AllowEarnPointsFromPurchasedPoints { get; }
Property Value
Info
Gets information about the cache holding the rewards.
public CacheInformation Info { get; }
Property Value
Methods
ClearCache()
Drops every cached reward.
public virtual void ClearCache()
ClearCache(IEnumerable<int>)
Drops the given rewards from the cache.
public virtual void ClearCache(IEnumerable<int> keys)
Parameters
keysIEnumerable<int>The ids of the rewards to drop.
ClearCache(int)
Drops the given reward from the cache.
public virtual void ClearCache(int key)
Parameters
keyintThe id of the reward to drop.
ClearRewardRuleCache()
Remove all reward rules from cache.
public virtual void ClearRewardRuleCache()
ClearUserTransactionCache(int)
Remove user transactions from cache.
public virtual void ClearUserTransactionCache(int userId)
Parameters
userIdint
CreateTransaction(UserTransaction)
Creates the user transaction
public virtual void CreateTransaction(UserTransaction transaction)
Parameters
transactionUserTransactionThe UserTransaction.
CreateTransaction(UserTransaction, OrderLine)
Creates the user transaction
public virtual void CreateTransaction(UserTransaction transaction, OrderLine orderLine)
Parameters
transactionUserTransactionThe UserTransaction.
orderLineOrderLineThe OrderLine.
CreateTransaction(UserTransaction, User?)
Creates the user transaction
public virtual void CreateTransaction(UserTransaction transaction, User? user)
Parameters
transactionUserTransactionThe UserTransaction.
userUserThe User.
DeleteReward(Reward)
Deletes the reward.
public virtual void DeleteReward(Reward reward)
Parameters
rewardReward
DeleteRewardRule(RewardRule)
Deletes the instance.
public virtual void DeleteRewardRule(RewardRule rewardRule)
Parameters
rewardRuleRewardRule
FindPoints(OrderLine)
Finds the points.
public virtual IPointInfo? FindPoints(OrderLine orderLine)
Parameters
orderLineOrderLineThe order line.
Returns
- IPointInfo
The IPointInfo.
FindPoints(Product, Order, DateTime)
Finds the points.
public virtual ConditionPointInfo? FindPoints(Product product, Order order, DateTime orderTime)
Parameters
Returns
FindPoints(Product, Order, DateTime, string?)
Finds the points.
public virtual ConditionPointInfo? FindPoints(Product product, Order order, DateTime orderTime, string? unitId)
Parameters
productProductThe product.
orderOrderThe order.
orderTimeDateTimeThe order time.
unitIdstringThe unit ID.
Returns
GetPointsBalance(User)
Gets the transaction balance for user.
public virtual double GetPointsBalance(User user)
Parameters
Returns
GetPointsBalance(int)
Gets the transaction balance by user id.
public virtual double GetPointsBalance(int userId)
Parameters
userIdintThe user id.
Returns
GetRewardById(int)
Gets reward by ID.
public virtual Reward? GetRewardById(int rewardId)
Parameters
rewardIdintThe reward id.
Returns
- Reward
The reward.
GetRewardRule(int, int)
Gets the reward rule.
public virtual RewardRule? GetRewardRule(int rewardId, int id)
Parameters
Returns
- RewardRule
The RewardRule.
GetRewardUsageCount(Reward)
Gets the count of the reward usage.
public virtual int GetRewardUsageCount(Reward reward)
Parameters
rewardReward
Returns
- int
Number of the reward usage.
GetRewards()
Return all rewards.
public virtual IEnumerable<Reward> GetRewards()
Returns
GetRewardsGiven(IEnumerable<Reward>)
Gets the points given for the specified list of rewards.
public virtual IEnumerable<RewardPointsGiven> GetRewardsGiven(IEnumerable<Reward> rewards)
Parameters
rewardsIEnumerable<Reward>The rewards to report on.
Returns
- IEnumerable<RewardPointsGiven>
The points given per reward.
GetRulesForReward(int)
Gets rules for the reward id.
public virtual IEnumerable<RewardRule> GetRulesForReward(int rewardId)
Parameters
rewardIdintThe reward id.
Returns
GetTotalPoints(Reward, double, double, double)
Gets the total points.
public virtual double GetTotalPoints(Reward reward, double productsPrice, double productsCount, double divisor)
Parameters
rewardRewardThe reward whose points are calculated.
productsPricedoubleThe products price.
productsCountdoubleThe products count.
divisordoubleThe divisor.
Returns
- double
The total points.
GetUserTransactions(int)
Gets the collection of the user transactions by user id.
public virtual IEnumerable<UserTransaction> GetUserTransactions(int userId)
Parameters
userIdintThe user id.
Returns
LoadRewardsFromUserTransaction(IEnumerable<UserTransaction>)
Loads the rewards from the user transaction collection.
public virtual void LoadRewardsFromUserTransaction(IEnumerable<UserTransaction> userTransactions)
Parameters
userTransactionsIEnumerable<UserTransaction>The collection of user transactions.
RedeemExpiredPoints()
Spends the points that have passed the configured expiration period, for every user holding any. Does nothing when points are configured never to expire.
public virtual void RedeemExpiredPoints()
RedeemPoints(Order)
Redeem points from Order.
public virtual void RedeemPoints(Order order)
Parameters
RedeemPoints(double, string, int)
Redeem points.
public virtual void RedeemPoints(double points, string comment, int userId)
Parameters
pointsdoubleThe number of points.
commentstringThe comment for transaction.
userIdintThe user id.
RedeemPoints(double, string, int, DateTime)
Redeem points.
public virtual void RedeemPoints(double points, string comment, int userId, DateTime transactionDate)
Parameters
pointsdoubleThe number of points.
commentstringThe comment for transaction.
userIdintThe user id.
transactionDateDateTimeThe transaction date.
RedeemPoints(double, string, int, DateTime, TransactionObjectType, string)
Spends points on behalf of a user, recording what the points were spent on.
public virtual void RedeemPoints(double points, string comment, int userId, DateTime transactionDate, TransactionObjectType transactionType, string transactionElement)
Parameters
pointsdoubleThe number of points to spend.
commentstringThe comment for the transaction.
userIdintThe user id.
transactionDateDateTimeThe transaction date.
transactionTypeTransactionObjectTypeWhat the transaction is attached to.
transactionElementstringThe id of the thing the transaction is attached to.
Exceptions
- InvalidOperationException
The user does not have enough points.
RewardPoints(Order)
Reward points from order lines on an order.
public virtual void RewardPoints(Order order)
Parameters
orderOrderThe order.
RewardPoints(double, string, int)
Reward points.
public virtual void RewardPoints(double points, string comment, int userId)
Parameters
pointsdoubleThe number of points.
commentstringThe comment for transaction.
userIdintThe user id.
SaveReward(Reward)
Saves current reward to the database.
public virtual void SaveReward(Reward reward)
Parameters
rewardReward
SaveRewardRule(RewardRule)
Saves the instance to the data base.
public virtual void SaveRewardRule(RewardRule rewardRule)
Parameters
rewardRuleRewardRule
SetCacheType<TObjectCache>()
Replaces the cache implementation holding the rewards.
public void SetCacheType<TObjectCache>() where TObjectCache : ServiceCache<int, Reward>
Type Parameters
TObjectCacheThe cache implementation to switch to.
TryUpdateRewards(Order)
Tries to update rewards.
public virtual void TryUpdateRewards(Order order)
Parameters
orderOrderThe order.
UsePoints(Order)
Redeem points from Order and exchange points in case of Loyalty discount is used.
public virtual void UsePoints(Order order)