Beispiel #1
0
            /// <summary>
            /// Calculates all of the discount lines for the transactions.
            /// </summary>
            /// <param name="pricingDataManager">Provides data access to the calculation.</param>
            /// <param name="transaction">The sales transaction.</param>
            /// <param name="currencyAndRoundingHelper">Currency and rounding helper.</param>
            /// <param name="currencyCode">Currency code to filter discounts by.</param>
            /// <param name="lineDiscountGroup">Optional. Line discount group Id for the customer.</param>
            /// <param name="multilineDiscountGroup">Optional. Multiline discount group Id for the customer.</param>
            /// <param name="totalDiscountGroup">Optional. Total discount group Id for the customer.</param>
            /// <param name="shouldTotalLines">True if discount lines should be totaled for each line. False if they should be left as raw discount lines.</param>
            /// <param name="calculationMode">Pricing calculation mode.</param>
            /// <param name="activeDate">Optional. Active, channel date/time to apply discount for.</param>
            /// <remarks>Each sales line will have a collection of DiscountLines and a net discount total in DiscountAmount property (if totaling is enabled).</remarks>
            public static void CalculateDiscountsForLines(
                IPricingDataAccessor pricingDataManager,
                SalesTransaction transaction,
                ICurrencyOperations currencyAndRoundingHelper,
                string currencyCode,
                string lineDiscountGroup,
                string multilineDiscountGroup,
                string totalDiscountGroup,
                bool shouldTotalLines,
                DiscountCalculationMode calculationMode,
                DateTimeOffset activeDate)
            {
                if (transaction == null)
                {
                    throw new ArgumentNullException("transaction");
                }

                Customer     customer     = InitializeCustomer(transaction, lineDiscountGroup, multilineDiscountGroup, totalDiscountGroup);
                PriceContext priceContext = Discount.BuildPriceContext(pricingDataManager, currencyAndRoundingHelper, customer, transaction, currencyCode, transaction.IsTaxIncludedInPrice, calculationMode, activeDate);

                bool isDiagnosticsCollected = GetCollectDiagnostics(transaction);

                if (isDiagnosticsCollected)
                {
                    priceContext.IsDiagnosticsCollected         = true;
                    priceContext.PricingEngineDiagnosticsObject = new PricingEngineDiagnosticsObject();
                }

                CalculateDiscountsForLines(
                    pricingDataManager,
                    transaction,
                    shouldTotalLines,
                    priceContext);

                if (isDiagnosticsCollected)
                {
                    SetPricingEngineDiagnosticsObject(transaction, priceContext.PricingEngineDiagnosticsObject);
                }
            }