Exemplo n.º 1
0
            internal static PriceResult GetActiveTradeAgreement(IPricingDataAccessor pricingDataManager, DiscountParameters priceParameters, string currencyCode, SalesLine saleItem, decimal quantity, string customerId, string customerPriceGroup, DateTimeOffset dateToCheck)
            {
                dateToCheck = saleItem.SalesDate ?? dateToCheck;

                IEnumerable <PriceGroup> priceGroups   = pricingDataManager.GetChannelPriceGroups() as IEnumerable <PriceGroup>;
                HashSet <string>         priceGroupIds = new HashSet <string>(priceGroups.Select(pg => pg.GroupId).Distinct(StringComparer.OrdinalIgnoreCase));

                PriceResult    result;
                ProductVariant variantLine = GetVariantFromLineOrDatabase(pricingDataManager, saleItem);

                variantLine = variantLine ?? new ProductVariant();

                Tuple <DateTimeOffset, DateTimeOffset> dateRange  = GetMinAndMaxActiveDates(new SalesLine[] { saleItem }, dateToCheck);
                ReadOnlyCollection <TradeAgreement>    agreements = pricingDataManager.ReadPriceTradeAgreements(
                    new HashSet <string> {
                    saleItem.ItemId
                },
                    priceGroupIds,
                    customerId,
                    dateRange.Item1,
                    dateRange.Item2,
                    currencyCode,
                    QueryResultSettings.AllRecords) as ReadOnlyCollection <TradeAgreement>;

                var agreementDict = new Dictionary <string, IList <TradeAgreement> >(StringComparer.OrdinalIgnoreCase);

                agreementDict.Add(saleItem.ItemId, agreements);

                result = TradeAgreementCalculator.GetPriceResultOfActiveTradeAgreement(
                    agreementDict,
                    priceParameters,
                    currencyCode,
                    saleItem.ItemId,
                    saleItem.OriginalSalesOrderUnitOfMeasure,
                    Discount.GetUnitOfMeasure(saleItem),
                    variantLine,
                    saleItem.UnitOfMeasureConversion,
                    quantity,
                    customerId,
                    customerPriceGroup,
                    priceGroupIds,
                    new List <SalesLine> {
                    saleItem
                },
                    new PriceContext(),
                    dateToCheck);

                return(result);
            }
Exemplo n.º 2
0
            private static void InitializePriceContexOfPriceGroups(PriceContext priceContext, IPricingDataAccessor pricingDataManager, ISet <long> catalogIds, IEnumerable <AffiliationLoyaltyTier> affiliationLoyaltyTiers)
            {
                if (priceContext == null)
                {
                    throw new ArgumentNullException("priceContext");
                }

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

                IEnumerable <PriceGroup> channelPriceGroups = pricingDataManager.GetChannelPriceGroups() as IEnumerable <PriceGroup>;

                AddPriceGroupsToCollections(
                    channelPriceGroups,
                    priceContext.ChannelPriceGroups,
                    priceContext.PriceGroupIdsToRecordIdsDictionary,
                    priceContext.RecordIdsToPriceGroupIdsDictionary,
                    priceContext.PriceGroupIdToPriorityDictionary);
                IEnumerable <CatalogPriceGroup> catalogPriceGroups     = catalogIds != null && catalogIds.Count > 0 ? pricingDataManager.GetCatalogPriceGroups(catalogIds) as IEnumerable <CatalogPriceGroup> : new List <CatalogPriceGroup>().AsReadOnly();
                IEnumerable <PriceGroup>        affiliationPriceGroups = affiliationLoyaltyTiers != null && affiliationLoyaltyTiers.Any() ? pricingDataManager.GetAffiliationPriceGroups(affiliationLoyaltyTiers) as IEnumerable <PriceGroup> : new List <PriceGroup>().AsReadOnly();

                foreach (CatalogPriceGroup catalogPriceGroup in catalogPriceGroups)
                {
                    if (!priceContext.CatalogPriceGroups.ContainsKey(catalogPriceGroup.CatalogId))
                    {
                        priceContext.CatalogPriceGroups.Add(catalogPriceGroup.CatalogId, new HashSet <string>(StringComparer.OrdinalIgnoreCase));
                    }

                    priceContext.CatalogPriceGroups[catalogPriceGroup.CatalogId].Add(catalogPriceGroup.GroupId);
                }

                priceContext.PriceGroupIdsToRecordIdsDictionary.Merge(catalogPriceGroups.Select(p => new KeyValuePair <string, long>(p.GroupId, p.PriceGroupId)));
                priceContext.RecordIdsToPriceGroupIdsDictionary.Merge(catalogPriceGroups.Select(p => new KeyValuePair <long, string>(p.PriceGroupId, p.GroupId)));
                priceContext.PriceGroupIdToPriorityDictionary.Merge(catalogPriceGroups.Select(p => new KeyValuePair <string, int>(p.GroupId, p.PricingPriorityNumber)));

                AddPriceGroupsToCollections(
                    affiliationPriceGroups,
                    priceContext.AffiliationPriceGroups,
                    priceContext.PriceGroupIdsToRecordIdsDictionary,
                    priceContext.RecordIdsToPriceGroupIdsDictionary,
                    priceContext.PriceGroupIdToPriorityDictionary);

                FixCustomerPriceGroupPriority(pricingDataManager, priceContext);
            }