Пример #1
0
            /// <summary>
            /// This method will calculate the prices for the whole sales transaction.
            /// </summary>
            /// <param name="salesTransaction">Sales transaction.</param>
            /// <param name="pricingDataManager">Provides access to the pricing data to the pricing calculation.</param>
            /// <param name="currencyAndRoundingHelper">Currency and rounding helper.</param>
            /// <param name="customerPriceGroup">Customer price group.</param>
            /// <param name="currencyCode">Current code.</param>
            /// <param name="activeDate">Active date time offset for price.</param>
            /// <remarks>Parallel processing has been disabled, but we leave parameter here for backward compatibility.</remarks>
            public static void CalculatePricesForTransaction(
                SalesTransaction salesTransaction,
                IPricingDataAccessor pricingDataManager,
                ICurrencyOperations currencyAndRoundingHelper,
                string customerPriceGroup,
                string currencyCode,
                DateTimeOffset activeDate)
            {
                if (salesTransaction == null)
                {
                    throw new ArgumentNullException("salesTransaction");
                }

                if (pricingDataManager == null)
                {
                    throw new ArgumentNullException("pricingDataManager");
                }

                if (currencyAndRoundingHelper == null)
                {
                    throw new ArgumentNullException("currencyAndRoundingHelper");
                }

                ISet <long> catalogIds = PriceContextHelper.GetCatalogIds(salesTransaction);
                IEnumerable <AffiliationLoyaltyTier> affiliationLoyaltyTiers = PriceContextHelper.GetAffiliationLoyalTierIds(salesTransaction);

                ISet <string> itemIds      = PriceContextHelper.GetItemIds(salesTransaction);
                PriceContext  priceContext = PriceContextHelper.CreatePriceContext(
                    pricingDataManager,
                    currencyAndRoundingHelper,
                    PricingCalculationMode.Transaction,
                    DiscountCalculationMode.None,
                    itemIds,
                    catalogIds,
                    affiliationLoyaltyTiers,
                    salesTransaction.CustomerId,
                    customerPriceGroup,
                    salesTransaction.IsTaxIncludedInPrice,
                    currencyCode,
                    activeDate);

                bool isDiagnosticsCollected = GetCollectDiagnostics(salesTransaction);

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

                PricingEngine.CalculatePricesForSalesLines(salesTransaction.PriceCalculableSalesLines, priceContext, pricingDataManager);

                if (isDiagnosticsCollected)
                {
                    SetPricingEngineDiagnosticsObject(salesTransaction, priceContext.PricingEngineDiagnosticsObject);
                }
            }
Пример #2
0
            internal static PriceContext BuildPriceContext(
                IPricingDataAccessor pricingDataManager,
                ICurrencyOperations currencyAndRoundingHelper,
                Customer customer,
                SalesTransaction transaction,
                string currencyCode,
                bool doesPriceIncludeTax,
                DiscountCalculationMode discountCalculationMode,
                DateTimeOffset activeDate)
            {
                string customerAccount                = string.Empty;
                string customerPriceGroup             = string.Empty;
                string customerLinePriceGroup         = string.Empty;
                string customerMultipleLinePriceGroup = string.Empty;
                string customerTotalPriceGroup        = string.Empty;

                if (customer != null)
                {
                    if (!string.IsNullOrWhiteSpace(customer.AccountNumber))
                    {
                        customerAccount = customer.AccountNumber;
                    }

                    if (!string.IsNullOrWhiteSpace(customer.PriceGroup))
                    {
                        customerPriceGroup = customer.PriceGroup;
                    }

                    if (!string.IsNullOrWhiteSpace(customer.LineDiscountGroup))
                    {
                        customerLinePriceGroup = customer.LineDiscountGroup;
                    }

                    if (!string.IsNullOrWhiteSpace(customer.MultilineDiscountGroup))
                    {
                        customerMultipleLinePriceGroup = customer.MultilineDiscountGroup;
                    }

                    if (!string.IsNullOrWhiteSpace(customer.TotalDiscountGroup))
                    {
                        customerTotalPriceGroup = customer.TotalDiscountGroup;
                    }
                }

                ISet <string> itemIds    = PriceContextHelper.GetItemIds(transaction);
                ISet <long>   catalogIds = PriceContextHelper.GetCatalogIds(transaction);
                IEnumerable <AffiliationLoyaltyTier> affiliationLoyaltyTierIds = PriceContextHelper.GetAffiliationLoyalTierIds(transaction);

                return(PriceContextHelper.CreatePriceContext(
                           pricingDataManager,
                           currencyAndRoundingHelper,
                           PricingCalculationMode.Transaction,
                           discountCalculationMode,
                           itemIds,
                           catalogIds,
                           affiliationLoyaltyTierIds,
                           customerAccount,
                           customerPriceGroup,
                           customerLinePriceGroup,
                           customerMultipleLinePriceGroup,
                           customerTotalPriceGroup,
                           doesPriceIncludeTax,
                           currencyCode ?? string.Empty,
                           activeDate));
            }