/// <summary> /// Visits each qualifying line item and applies the discount. /// </summary> /// <param name="lineItem"> /// The line item. /// </param> public void Visit(ILineItem lineItem) { // handle the special case for percent deduction based when tax is included in the product price var audit = new CouponRewardAdjustmentAudit() { RelatesToSku = lineItem.Sku }; if (lineItem.ExtendedData.TaxIncludedInProductPrice() && _productTaxationEnabled && lineItem.ExtendedData.DefinesProductVariant() && _adjustmentType == CouponDiscountLineItemReward.Adjustment.Percent) { var product = _merchello.Query.Product.GetByKey(lineItem.ExtendedData.GetProductKey()); var preTaxPrice = product.Price - (product.Price * DiscountPercent); var preTaxAmount = lineItem.ExtendedData.ProductPriceTaxAmount() - (lineItem.ExtendedData.ProductPriceTaxAmount() * DiscountPercent); //// this is sort of weird here, but the line item price may have been set outside the typical workflow //// and we cannot rely on the OnSale flag being set so we set both prices to the value set in the line item //// and then apply the taxes to the new price. Example of this would be using different currencies product.Price = lineItem.Price; // this will be the amount of the discount with the taxation break out from the taxation results product.SalePrice = preTaxPrice; var result = _taxationContext.CalculateTaxesForProduct(product); product.AlterProduct(result); audit.Log = product.Price == lineItem.Price ? product.ModifiedDataLogs : product.ModifiedDataLogs.Where(x => x.PropertyName == "SalePrice").ToArray(); _audits.Add(audit); // if taxes are to be excluded the constraint ExcludeTaxesIncludedInProductPrices should be added to remove them _qualifyingTotal += lineItem.Price * lineItem.Quantity; _adjustedProductPreTaxTotal += preTaxPrice * lineItem.Quantity; _adjustedTaxTotal += preTaxAmount * lineItem.Quantity; } else if (_adjustmentType == CouponDiscountLineItemReward.Adjustment.Percent) { var modifiedPrice = lineItem.Price - (lineItem.Price * DiscountPercent); audit.Log = new[] { new DataModifierLog() { PropertyName = "Price", OriginalValue = lineItem.Price, ModifiedValue = modifiedPrice } }; _audits.Add(audit); _qualifyingTotal += lineItem.Price * lineItem.Quantity; } else { _qualifyingTotal += lineItem.Price * lineItem.Quantity; } }
/// <summary> /// Visits each qualifying line item and applies the discount. /// </summary> /// <param name="lineItem"> /// The line item. /// </param> public void Visit(ILineItem lineItem) { // handle the special case for percent deduction based when tax is included in the product price var audit = new CouponRewardAdjustmentAudit() { RelatesToSku = lineItem.Sku }; if (lineItem.ExtendedData.TaxIncludedInProductPrice() && _productTaxationEnabled && lineItem.ExtendedData.DefinesProductVariant() && _adjustmentType == CouponDiscountLineItemReward.Adjustment.Percent) { var product = _merchello.Query.Product.GetByKey(lineItem.ExtendedData.GetProductKey()); var preTaxPrice = product.Price - (product.Price * DiscountPercent); var preTaxAmount = lineItem.ExtendedData.ProductPriceTaxAmount() - (lineItem.ExtendedData.ProductPriceTaxAmount() * DiscountPercent); //// this is sort of weird here, but the line item price may have been set outside the typical workflow //// and we cannot rely on the OnSale flag being set so we set both prices to the value set in the line item //// and then apply the taxes to the new price. Example of this would be using different currencies product.Price = lineItem.Price; // this will be the amount of the discount with the taxation break out from the taxation results product.SalePrice = preTaxPrice; var result = _taxationContext.CalculateTaxesForProduct(product); product.AlterProduct(result); audit.Log = product.Price == lineItem.Price ? product.ModifiedDataLogs : product.ModifiedDataLogs.Where(x => x.PropertyName == "SalePrice").ToArray(); _audits.Add(audit); // if taxes are to be excluded the constraint ExcludeTaxesIncludedInProductPrices should be added to remove them _qualifyingTotal += lineItem.Price * lineItem.Quantity; _adjustedProductPreTaxTotal += preTaxPrice * lineItem.Quantity; _adjustedTaxTotal += preTaxAmount * lineItem.Quantity; } else if (_adjustmentType == CouponDiscountLineItemReward.Adjustment.Percent) { var modifiedPrice = lineItem.Price * DiscountPercent; audit.Log = new[] { new DataModifierLog() { PropertyName = "Price", OriginalValue = lineItem.Price, ModifiedValue = modifiedPrice } }; _audits.Add(audit); _qualifyingTotal += lineItem.Price; } else { _qualifyingTotal += lineItem.Price; } }