Example #1
0
            /// <summary>
            /// Create a new instance of the <see cref="PriceContext"/> class.
            /// </summary>
            /// <param name="requestContext">Request context.</param>
            /// <param name="pricingDataManager">Pricing data manager.</param>
            /// <param name="priceParameters">Price parameters.</param>
            /// <param name="currencyAndRoundingHelper">Currency and rounding helper.</param>
            /// <param name="itemIds">Item Ids.</param>
            /// <param name="catalogIds">Catalog identifiers.</param>
            /// <param name="activeDate">Active date.</param>
            /// <param name="priceCalculationMode">Price calculation mode.</param>
            /// <param name="discountCalculationMode">Discount calculation mode.</param>
            /// <returns>A new instance of the <see cref="PriceContext"/> class.</returns>
            public static PriceContext CreatePriceContext(
                RequestContext requestContext,
                IPricingDataAccessor pricingDataManager,
                PriceParameters priceParameters,
                ICurrencyOperations currencyAndRoundingHelper,
                ISet <string> itemIds,
                ISet <long> catalogIds,
                DateTimeOffset activeDate,
                PricingCalculationMode priceCalculationMode,
                DiscountCalculationMode discountCalculationMode)
            {
                if (requestContext == null)
                {
                    throw new ArgumentNullException("requestContext");
                }

                PriceContext priceContext = new PriceContext
                {
                    CurrencyAndRoundingHelper = currencyAndRoundingHelper,
                    ActiveDate              = activeDate,
                    PriceParameters         = priceParameters,
                    PriceCalculationMode    = priceCalculationMode,
                    DiscountCalculationMode = discountCalculationMode,
                };

                PriceContextHelper.InitializePriceContextOfInferredProperties(priceContext, pricingDataManager, requestContext, itemIds, catalogIds, null);

                return(priceContext);
            }
Example #2
0
            /// <summary>
            /// Create a new DiscountParameters object from the passed in data.
            /// </summary>
            /// <param name="priceParameters">Data model object representing price activation options.</param>
            /// <returns>Newly fetched and initialized DiscountParameters object.</returns>
            public static DiscountParameters CreateAndInitialize(PriceParameters priceParameters)
            {
                DiscountParameters parameters = new DiscountParameters();

                parameters.GetDiscountParameters(priceParameters);
                return(parameters);
            }
Example #3
0
            /// <summary>
            /// Create a new instance of the <see cref="PriceContext"/> class.
            /// </summary>
            /// <param name="requestContext">Request context.</param>
            /// <param name="pricingDataManager">Pricing data manager.</param>
            /// <param name="transaction">Current transaction.</param>
            /// <param name="priceParameters">Price parameters.</param>
            /// <param name="currencyAndRoundingHelper">Currency and rounding helper.</param>
            /// <param name="activeDate">Active date.</param>
            /// <param name="customerId">Customer Id.</param>
            /// <param name="customerPriceGroup">Customer price group.</param>
            /// <param name="priceIncludesTax">Price includes tax.</param>
            /// <param name="priceCalculationMode">Price calculation mode.</param>
            /// <param name="discountCalculationMode">Discount calculation mode.</param>
            /// <returns>A new instance of the <see cref="PriceContext"/> class.</returns>
            public static PriceContext CreatePriceContext(
                RequestContext requestContext,
                IPricingDataAccessor pricingDataManager,
                SalesTransaction transaction,
                PriceParameters priceParameters,
                ICurrencyOperations currencyAndRoundingHelper,
                DateTimeOffset activeDate,
                string customerId,
                string customerPriceGroup,
                bool priceIncludesTax,
                PricingCalculationMode priceCalculationMode,
                DiscountCalculationMode discountCalculationMode)
            {
                if (requestContext == null)
                {
                    throw new ArgumentNullException("requestContext");
                }

                PriceContext priceContext = new PriceContext
                {
                    CurrencyAndRoundingHelper = currencyAndRoundingHelper,
                    ActiveDate              = activeDate,
                    CustomerAccount         = customerId,
                    CustomerPriceGroup      = customerPriceGroup,
                    IsTaxInclusive          = priceIncludesTax,
                    PriceParameters         = priceParameters,
                    PriceCalculationMode    = priceCalculationMode,
                    DiscountCalculationMode = discountCalculationMode,
                };

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

                PriceContextHelper.InitializePriceContextOfInferredProperties(priceContext, pricingDataManager, requestContext, itemIds, catalogIds, affiliationLoyaltyTiers);

                return(priceContext);
            }
Example #4
0
 /// <summary>
 /// Creates the specified sales parameters.
 /// </summary>
 /// <param name="salesParameters">The discount parameters.</param>
 /// <returns>The price.</returns>
 public static Price Create(PriceParameters salesParameters)
 {
     return(new Price(salesParameters));
 }
Example #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Price"/> class.
 /// </summary>
 /// <param name="salesParameters">The sales parameters.</param>
 private Price(PriceParameters salesParameters)
 {
     this.priceParameters = salesParameters;
 }
Example #6
0
            /// <summary>
            /// Populate the internal set of enabled trade agreement combinations based on values in given PriceParameters object.
            /// </summary>
            /// <param name="priceParameters">Data model object representing price activation options.</param>
            private void GetDiscountParameters(PriceParameters priceParameters)
            {
                var activeCombinations = new HashSet <Tuple <PriceDiscountType, PriceDiscountAccountCode, PriceDiscountItemCode> >();

                if (priceParameters.ApplyPriceForCustomerAndItem)
                {
                    activeCombinations.Add(CreateCombo(PriceDiscountType.PriceSales, PriceDiscountAccountCode.Customer, PriceDiscountItemCode.Item));
                }

                if (priceParameters.ApplyPriceForCustomerGroupAndItem)
                {
                    activeCombinations.Add(CreateCombo(PriceDiscountType.PriceSales, PriceDiscountAccountCode.CustomerGroup, PriceDiscountItemCode.Item));
                }

                if (priceParameters.ApplyPriceForAllCustomersAndItem)
                {
                    activeCombinations.Add(CreateCombo(PriceDiscountType.PriceSales, PriceDiscountAccountCode.AllCustomers, PriceDiscountItemCode.Item));
                }

                if (priceParameters.ApplyLineDiscountForCustomerAndItem)
                {
                    activeCombinations.Add(CreateCombo(PriceDiscountType.LineDiscountSales, PriceDiscountAccountCode.Customer, PriceDiscountItemCode.Item));
                }

                if (priceParameters.ApplyLineDiscountForCustomerAndItemGroup)
                {
                    activeCombinations.Add(CreateCombo(PriceDiscountType.LineDiscountSales, PriceDiscountAccountCode.Customer, PriceDiscountItemCode.ItemGroup));
                }

                if (priceParameters.ApplyLineDiscountForCustomerAndAllItems)
                {
                    activeCombinations.Add(CreateCombo(PriceDiscountType.LineDiscountSales, PriceDiscountAccountCode.Customer, PriceDiscountItemCode.AllItems));
                }

                if (priceParameters.ApplyLineDiscountForCustomerGroupAndItem)
                {
                    activeCombinations.Add(CreateCombo(PriceDiscountType.LineDiscountSales, PriceDiscountAccountCode.CustomerGroup, PriceDiscountItemCode.Item));
                }

                if (priceParameters.ApplyLineDiscountForCustomerGroupAndItemGroup)
                {
                    activeCombinations.Add(CreateCombo(PriceDiscountType.LineDiscountSales, PriceDiscountAccountCode.CustomerGroup, PriceDiscountItemCode.ItemGroup));
                }

                if (priceParameters.ApplyLineDiscountForCustomerGroupAndAllItems)
                {
                    activeCombinations.Add(CreateCombo(PriceDiscountType.LineDiscountSales, PriceDiscountAccountCode.CustomerGroup, PriceDiscountItemCode.AllItems));
                }

                if (priceParameters.ApplyLineDiscountForAllCustomersAndItem)
                {
                    activeCombinations.Add(CreateCombo(PriceDiscountType.LineDiscountSales, PriceDiscountAccountCode.AllCustomers, PriceDiscountItemCode.Item));
                }

                if (priceParameters.ApplyLineDiscountForAllCustomersAndItemGroup)
                {
                    activeCombinations.Add(CreateCombo(PriceDiscountType.LineDiscountSales, PriceDiscountAccountCode.AllCustomers, PriceDiscountItemCode.ItemGroup));
                }

                if (priceParameters.ApplyLineDiscountForAllCustomersAndAllItems)
                {
                    activeCombinations.Add(CreateCombo(PriceDiscountType.LineDiscountSales, PriceDiscountAccountCode.AllCustomers, PriceDiscountItemCode.AllItems));
                }

                if (priceParameters.ApplyMultilineDiscountForCustomerAndItemGroup)
                {
                    activeCombinations.Add(CreateCombo(PriceDiscountType.MultilineDiscountSales, PriceDiscountAccountCode.Customer, PriceDiscountItemCode.ItemGroup));
                }

                if (priceParameters.ApplyMultilineDiscountForCustomerAndAllItems)
                {
                    activeCombinations.Add(CreateCombo(PriceDiscountType.MultilineDiscountSales, PriceDiscountAccountCode.Customer, PriceDiscountItemCode.AllItems));
                }

                if (priceParameters.ApplyMultilineDiscountForCustomerGroupAndItemGroup)
                {
                    activeCombinations.Add(CreateCombo(PriceDiscountType.MultilineDiscountSales, PriceDiscountAccountCode.CustomerGroup, PriceDiscountItemCode.ItemGroup));
                }

                if (priceParameters.ApplyMultilineDiscountForCustomerGroupAndAllItems)
                {
                    activeCombinations.Add(CreateCombo(PriceDiscountType.MultilineDiscountSales, PriceDiscountAccountCode.CustomerGroup, PriceDiscountItemCode.AllItems));
                }

                if (priceParameters.ApplyMultilineDiscountForAllCustomersAndItemGroup)
                {
                    activeCombinations.Add(CreateCombo(PriceDiscountType.MultilineDiscountSales, PriceDiscountAccountCode.AllCustomers, PriceDiscountItemCode.ItemGroup));
                }

                if (priceParameters.ApplyMultilineDiscountForAllCustomersAndAllItems)
                {
                    activeCombinations.Add(CreateCombo(PriceDiscountType.MultilineDiscountSales, PriceDiscountAccountCode.AllCustomers, PriceDiscountItemCode.AllItems));
                }

                if (priceParameters.ApplyTotalDiscountForCustomerAndAllItems)
                {
                    activeCombinations.Add(CreateCombo(PriceDiscountType.EndDiscountSales, PriceDiscountAccountCode.Customer, PriceDiscountItemCode.AllItems));
                }

                if (priceParameters.ApplyTotalDiscountForCustomerGroupAndAllItems)
                {
                    activeCombinations.Add(CreateCombo(PriceDiscountType.EndDiscountSales, PriceDiscountAccountCode.CustomerGroup, PriceDiscountItemCode.AllItems));
                }

                if (priceParameters.ApplyTotalDiscountForAllCustomersAndAllItems)
                {
                    activeCombinations.Add(CreateCombo(PriceDiscountType.EndDiscountSales, PriceDiscountAccountCode.AllCustomers, PriceDiscountItemCode.AllItems));
                }

                // save found combinations on the object
                this.enabledCombinations = activeCombinations;
            }