Last active
August 5, 2020 02:12
-
-
Save mauro-vieira/23020bdf9afcda614246de4e160e4627 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyCustomDiscountProcessor : BuyQuantityGetItemDiscountProcessor | |
{ | |
private readonly IAccountManager _accountManager; | |
public MyCustomDiscountProcessor(CollectionTargetEvaluator targetEvaluator, | |
FulfillmentEvaluator fulfillmentEvaluator, LocalizationService localizationService, | |
RedemptionDescriptionFactory redemptionDescriptionFactory, IAccountManager accountManager) | |
: base(targetEvaluator, fulfillmentEvaluator, localizationService, redemptionDescriptionFactory) | |
{ | |
this._accountManager = accountManager; | |
} | |
protected override bool CanBeFulfilled(BuyQuantityGetItemDiscount promotionData, PromotionProcessorContext context) | |
{ | |
//We need to check whether the promotion is our extension | |
MyCustomDiscount myCustomDiscount; | |
if (promotionData is MyCustomDiscount) | |
{ | |
//We cast it | |
myCustomDiscount = promotionData as MyCustomDiscount; | |
//Here we can include our custom logic to decide if we apply the promotion, or not | |
if (myCustomDiscount.AccountNumber.IsNullOrEmpty()) | |
return false; | |
//We get the AccountNumber from our AccountManager | |
string accountNumber = this._accountManager.GetAccountNumber(); | |
if (accountNumber == null) | |
return false; | |
//And we compare it with the one on the Promotion | |
if (myCustomDiscount.AccountNumber != accountNumber) | |
return false; | |
} | |
//We fulfill the base type as well | |
return base.CanBeFulfilled(promotionData, context); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment