Example #1
0
            /// <summary>
            /// Create a new instance of the <see cref="PriceContext"/> class for price or discount calculation.
            /// </summary>
            /// <param name="pricingDataManager">Pricing data manager.</param>
            /// <param name="currencyAndRoundingHelper">Currency and rounding helper.</param>
            /// <param name="priceCalculationMode">Price calculation mode.</param>
            /// <param name="discountCalculationMode">Discount calculation mode.</param>
            /// <param name="itemIds">Item Ids.</param>
            /// <param name="catalogIds">Catalog identifiers.</param>
            /// <param name="affiliationLoyaltyTiers">Affiliation or loyalty tier identifiers.</param>
            /// <param name="customerId">Customer Id.</param>
            /// <param name="customerPriceGroup">Customer price group.</param>
            /// <param name="customerLinePriceGroup">Customer line discount price group.</param>
            /// <param name="customerMultipleLinePriceGroup">Customer multiple line discount price group.</param>
            /// <param name="customerTotalPriceGroup">Customer total discount price group.</param>
            /// <param name="priceIncludesTax">Price includes tax.</param>
            /// <param name="currencyCode">Currency code.</param>
            /// <param name="activeDate">Active date.</param>
            /// <returns>A new instance of the <see cref="PriceContext"/> class.</returns>
            public static PriceContext CreatePriceContext(
                IPricingDataAccessor pricingDataManager,
                ICurrencyOperations currencyAndRoundingHelper,
                PricingCalculationMode priceCalculationMode,
                DiscountCalculationMode discountCalculationMode,
                ISet <string> itemIds,
                ISet <long> catalogIds,
                IEnumerable <AffiliationLoyaltyTier> affiliationLoyaltyTiers,
                string customerId,
                string customerPriceGroup,
                string customerLinePriceGroup,
                string customerMultipleLinePriceGroup,
                string customerTotalPriceGroup,
                bool priceIncludesTax,
                string currencyCode,
                DateTimeOffset activeDate)
            {
                if (pricingDataManager == null)
                {
                    throw new ArgumentNullException("pricingDataManager");
                }

                PriceContext priceContext = new PriceContext
                {
                    CurrencyAndRoundingHelper = currencyAndRoundingHelper,
                    ActiveDate                     = activeDate,
                    CurrencyCode                   = currencyCode,
                    CustomerAccount                = customerId,
                    CustomerPriceGroup             = customerPriceGroup,
                    CustomerLinePriceGroup         = customerLinePriceGroup,
                    CustomerMultipleLinePriceGroup = customerMultipleLinePriceGroup,
                    CustomerTotalPriceGroup        = customerTotalPriceGroup,
                    PriceParameters                = pricingDataManager.GetPriceParameters(),
                    IsTaxInclusive                 = priceIncludesTax,
                    PriceCalculationMode           = priceCalculationMode,
                    DiscountCalculationMode        = discountCalculationMode,
                };

                PriceContextHelper.InitializePriceContexOfAlgorithmMode(priceContext, pricingDataManager);
                PriceContextHelper.InitializePriceContexOfPriceGroups(priceContext, pricingDataManager, catalogIds, affiliationLoyaltyTiers);
                PriceContextHelper.InitializeItemCache(priceContext, pricingDataManager, itemIds);

                return(priceContext);
            }