Пример #1
0
        public bool TryGetPriceField(string name, Mediachase.Commerce.Currency currency, MarketId marketId, out IFieldConfiguration <double?> field)
        {
            IFieldConfiguration fieldWorker = this.TryGetFieldWorker(name, (string)null, new Mediachase.Commerce.Currency?(currency), new MarketId?(marketId));

            field = fieldWorker as IFieldConfiguration <double?>;
            return(field != null);
        }
Пример #2
0
        public IFieldConfiguration <double?> GetPriceField(string name, Mediachase.Commerce.Currency currency, MarketId marketId)
        {
            IFieldConfiguration <double?> field;

            if (!this.TryGetPriceField(name, currency, marketId, out field))
            {
                throw new Exception(string.Format("Price field \"{0}\" for currency \"{1}\" and market \"{2}\" not found.", (object)name, (object)currency.CurrencyCode, (object)marketId.Value));
            }
            return(field);
        }
Пример #3
0
        private static IFieldConfiguration <double?> CreateSalePriceField(Mediachase.Commerce.Currency currency, MarketId marketId)
        {
            string fieldKey = string.Format("{0}_{1}", (object)currency.CurrencyCode, (object)marketId.Value);

            return((IFieldConfiguration <double?>) new ProviderFieldConfiguration <double?>("saleprice", (string)null, new Mediachase.Commerce.Currency?(currency), new MarketId?(marketId), 0 != 0, 0 != 0, EPiServer.Commerce.FindSearchProvider.LocalImplementation.Expressions.CloseFieldAccessParameter <double?>((Expression <Func <FindDocument, double?> >)(d => d.SalePrices[fieldKey])), (Func <FindDocument, double?>)(d =>
            {
                double?nullable;
                if (!d.SalePrices.TryGetValue(fieldKey, out nullable))
                {
                    return new double?();
                }
                return nullable;
            }), (Action <FindDocument, double?>)((d, a) => d.SalePrices[fieldKey] = a)));
        }
Пример #4
0
        public IFieldConfiguration GetAnyField(string name, string locale, Mediachase.Commerce.Currency currency, MarketId marketId)
        {
            IFieldConfiguration field;

            if (!this.TryGetAnyField(name, locale, currency, marketId, out field))
            {
                throw new Exception(string.Format("Field matching values name \"{0}\", locale \"{1}\", currency \"{2}\", and market \"{3}\" not found.", new object[4]
                {
                    (object)name,
                    (object)locale,
                    (object)currency.CurrencyCode,
                    (object)marketId.Value
                }));
            }
            return(field);
        }
Пример #5
0
        private IEnumerable <DiscountedEntry> GetDiscountPrices(
            IEnumerable <ContentReference> entryLinks,
            IMarket market,
            Mediachase.Commerce.Currency marketCurrency,
            Mediachase.Commerce.Catalog.ReferenceConverter referenceConverter)
        {
            if (entryLinks is null || (market is null) || marketCurrency.IsEmpty)
            {
                throw new ArgumentNullException(nameof(marketCurrency));
            }

            List <DiscountedEntry>       source     = new List <DiscountedEntry>();
            HashSet <string>             entryCodes = new HashSet <string>(entryLinks.Select <ContentReference, string>(new Func <ContentReference, string>(referenceConverter.GetCode)));
            Dictionary <string, decimal> dictionary = new Dictionary <string, decimal>();

            foreach (RewardDescription rewardDescription in _promotionEngine.Evaluate(entryLinks, market, marketCurrency, RequestFulfillmentStatus.Fulfilled))
            {
                HashSet <string> usedCodes = new HashSet <string>();
                foreach (ILineItem lineItem in rewardDescription.Redemptions.Where <RedemptionDescription>((Func <RedemptionDescription, bool>)(x => x.AffectedEntries != null)).SelectMany <RedemptionDescription, PriceEntry>((Func <RedemptionDescription, IEnumerable <PriceEntry> >)(x => x.AffectedEntries.PriceEntries)).Where <PriceEntry>((Func <PriceEntry, bool>)(x => x != null)).Select <PriceEntry, ILineItem>((Func <PriceEntry, ILineItem>)(x => x.ParentItem)).Where <ILineItem>((Func <ILineItem, bool>)(x => !usedCodes.Contains(x.Code))).Where <ILineItem>((Func <ILineItem, bool>)(x => entryCodes.Contains(x.Code))))
                {
                    usedCodes.Add(lineItem.Code);
                    ContentReference entryLink       = referenceConverter.GetContentLink(lineItem.Code);
                    DiscountedEntry  discountedEntry = source.SingleOrDefault <DiscountedEntry>((Func <DiscountedEntry, bool>)(x => x.EntryLink == entryLink));
                    if (discountedEntry == null)
                    {
                        discountedEntry = new DiscountedEntry(entryLink, (IList <DiscountPrice>) new List <DiscountPrice>());
                        source.Add(discountedEntry);
                    }
                    if (dictionary.ContainsKey(lineItem.Code))
                    {
                        dictionary[lineItem.Code] -= rewardDescription.SavedAmount;
                    }
                    else
                    {
                        // lineItemCalculator.GetExtendedPrice(lineItem, marketCurrency).Amount;
                        decimal amount = PriceCalculationService.GetSalePrice(lineItem.Code, market.MarketId, marketCurrency).UnitPrice.Amount;
                        dictionary.Add(lineItem.Code, amount - rewardDescription.SavedAmount);
                    }
                    DiscountPrice discountPrice = new DiscountPrice((EntryPromotion)rewardDescription.Promotion, new Money(Math.Max(dictionary[lineItem.Code], 0M), marketCurrency), new Money(lineItem.PlacedPrice, marketCurrency));
                    discountedEntry.DiscountPrices.Add(discountPrice);
                }
            }
            return((IEnumerable <DiscountedEntry>)source);
        }
Пример #6
0
 public void AddCurrency(Mediachase.Commerce.Currency currency)
 {
     if (this._knownCurrencies.Contains(currency))
     {
         return;
     }
     lock (this._knownConfigurationLock)
     {
         if (this._knownCurrencies.Contains(currency))
         {
             return;
         }
         this._knownCurrencies.Add(currency);
         foreach (MarketId knownMarket in this._knownMarkets)
         {
             this.AddField((IFieldConfiguration)ProviderConfiguration.CreateListPriceField(currency, knownMarket));
             this.AddField((IFieldConfiguration)ProviderConfiguration.CreateSalePriceField(currency, knownMarket));
         }
     }
 }
Пример #7
0
        private void BuildPrices(FindDocument document, CatalogEntryDto.CatalogEntryRow entryRow, ISearchConfiguration configuration)
        {
            IPriceService instance   = ServiceLocator.Current.GetInstance <IPriceService>();
            CatalogKey    catalogKey = new CatalogKey(entryRow);
            HashSet <Mediachase.Commerce.Currency> source1 = new HashSet <Mediachase.Commerce.Currency>();
            HashSet <MarketId>            source2          = new HashSet <MarketId>();
            IFieldConfiguration <double?> field            = null;

            foreach (IPriceValue catalogEntryPrice in instance.GetCatalogEntryPrices(catalogKey))
            {
                HashSet <Mediachase.Commerce.Currency> currencySet = source1;
                Money unitPrice = catalogEntryPrice.UnitPrice;
                Mediachase.Commerce.Currency currency1 = unitPrice.Currency;
                if (currencySet.Add(currency1))
                {
                    ISearchConfiguration searchConfiguration = configuration;
                    unitPrice = catalogEntryPrice.UnitPrice;
                    Mediachase.Commerce.Currency currency2 = unitPrice.Currency;
                    searchConfiguration.AddCurrency(currency2);
                }
                if (source2.Add(catalogEntryPrice.MarketId))
                {
                    configuration.AddMarket(catalogEntryPrice.MarketId);
                }
                ISearchConfiguration searchConfiguration1 = configuration;
                string name = "saleprice";
                unitPrice = catalogEntryPrice.UnitPrice;
                Mediachase.Commerce.Currency currencyCode = (Mediachase.Commerce.Currency)unitPrice.Currency.CurrencyCode;
                MarketId marketId = (MarketId)catalogEntryPrice.MarketId.Value;
                ref IFieldConfiguration <double?> local = ref field;
                if (searchConfiguration1.TryGetPriceField(name, currencyCode, marketId, out local))
                {
                    unitPrice = catalogEntryPrice.UnitPrice;
                    double amount   = (double)unitPrice.Amount;
                    double?nullable = field.GetValue(document);
                    if (!nullable.HasValue || nullable.Value > amount)
                    {
                        field.SetValue(document, new double?(amount));
                    }
                }
            }
Пример #8
0
        public override IOrderGroup CreateInMemoryOrderGroup(
            ContentReference entryLink,
            IMarket market,
            Mediachase.Commerce.Currency marketCurrency)
        {
            InMemoryOrderGroup memoryOrderGroup = new InMemoryOrderGroup(market, marketCurrency);

            memoryOrderGroup.CustomerId = PrincipalInfo.CurrentPrincipal.GetContactId();
            string      code  = this._referenceConverter.GetCode(entryLink);
            IPriceValue price = PriceCalculationService.GetSalePrice(code, market.MarketId, marketCurrency);

            if (price != null && price.UnitPrice != null)
            {
                decimal priceAmount = price.UnitPrice.Amount;
                memoryOrderGroup.Forms.First <IOrderForm>().Shipments.First <IShipment>().LineItems.Add((ILineItem) new InMemoryLineItem()
                {
                    Quantity    = 1M,
                    Code        = code,
                    PlacedPrice = priceAmount
                });
            }

            return((IOrderGroup)memoryOrderGroup);
        }
Пример #9
0
        private IFieldConfiguration TryGetFieldWorker(string name, string locale, Mediachase.Commerce.Currency?currency, MarketId?marketId)
        {
            if (locale != null)
            {
                this.AddLocale(locale);
            }
            if (currency.HasValue)
            {
                this.AddCurrency(currency.Value);
            }
            if (marketId.HasValue)
            {
                this.AddMarket(marketId.Value);
            }
            List <IFieldConfiguration> fieldConfigurationList;

            if (!this._fieldMap.TryGetValue(name, out fieldConfigurationList))
            {
                return((IFieldConfiguration)null);
            }
            IFieldConfiguration fieldConfiguration1 = (IFieldConfiguration)null;
            IFieldConfiguration fieldConfiguration2 = (IFieldConfiguration)null;
            IFieldConfiguration fieldConfiguration3 = (IFieldConfiguration)null;

            foreach (IFieldConfiguration fieldConfiguration4 in fieldConfigurationList)
            {
                if (fieldConfiguration4.Locale == null && !fieldConfiguration4.Currency.HasValue)
                {
                    if (fieldConfiguration1 != null)
                    {
                        throw new Exception(string.Format("Multiple single-language fields found for \"{0}\".", (object)name));
                    }
                    fieldConfiguration1 = fieldConfiguration4;
                }
                else if (fieldConfiguration4.Locale != null)
                {
                    if (string.Equals(locale, fieldConfiguration4.Locale, StringComparison.OrdinalIgnoreCase))
                    {
                        if (fieldConfiguration2 != null)
                        {
                            throw new Exception(string.Format("Multiple multi-language fields found for \"{0}\", \"{1}\".", (object)name, (object)locale));
                        }
                        fieldConfiguration2 = fieldConfiguration4;
                    }
                }
                else if (fieldConfiguration4.Currency.HasValue && currency.HasValue && marketId.HasValue)
                {
                    Mediachase.Commerce.Currency?currency1 = fieldConfiguration4.Currency;
                    Mediachase.Commerce.Currency currency2 = currency.Value;
                    if ((currency1.HasValue ? (currency1.HasValue ? (currency1.GetValueOrDefault() == currency2 ? 1 : 0) : 1) : 0) != 0)
                    {
                        MarketId?marketId1 = fieldConfiguration4.MarketId;
                        MarketId marketId2 = marketId.Value;
                        if ((marketId1.HasValue ? (marketId1.HasValue ? (marketId1.GetValueOrDefault() == marketId2 ? 1 : 0) : 1) : 0) != 0)
                        {
                            if (fieldConfiguration3 != null)
                            {
                                throw new Exception(string.Format("Multiple price fields found for \"{0}\", \"{1}\", \"{2}\".", (object)name, (object)currency.Value.CurrencyCode, (object)marketId.Value.Value));
                            }
                            fieldConfiguration3 = fieldConfiguration4;
                        }
                    }
                }
            }
            IFieldConfiguration fieldConfiguration5 = fieldConfiguration2 ?? fieldConfiguration1;

            if (fieldConfiguration5 != null && fieldConfiguration3 != null)
            {
                throw new Exception(string.Format("Multiple kinds of fields found for \"{0}\", \"{1}\", \"{2}\", \"{3}\".", new object[4]
                {
                    (object)name,
                    (object)(locale ?? string.Empty),
                    marketId.HasValue ? (object)marketId.Value.Value : (object)string.Empty,
                    currency.HasValue ? (object)currency.Value.CurrencyCode : (object)string.Empty
                }));
            }
            return(fieldConfiguration5 ?? fieldConfiguration3);
        }
Пример #10
0
 public bool TryGetAnyField(string name, string locale, Mediachase.Commerce.Currency currency, MarketId marketId, out IFieldConfiguration field)
 {
     field = this.TryGetFieldWorker(name, locale, new Mediachase.Commerce.Currency?(currency), new MarketId?(marketId));
     return(field != null);
 }
Пример #11
0
        internal static IEnumerable <KeyValuePair <string, Expression <Func <FindDocument, Filter> > > > GetPriceFacets(this ITypeSearch <FindDocument> search, SearchFilter filter, Mediachase.Commerce.Currency currency, MarketId marketId)
        {
            IFieldConfiguration <double?> field;

            if (FindProviderExtensions.IsPriceRangeFacet(filter) && search.Client.GetConfiguration().TryGetPriceField(filter.field, currency, marketId, out field))
            {
                foreach (PriceRangeValue priceRangeValue in ((IEnumerable <PriceRangeValue>)filter.Values.PriceRangeValue).Where <PriceRangeValue>((Func <PriceRangeValue, bool>)(prv => string.Equals(prv.currency, (string)currency, StringComparison.OrdinalIgnoreCase))))
                {
                    yield return(new KeyValuePair <string, Expression <Func <FindDocument, Filter> > >(FindProviderExtensions.EncodeFacetName(field.Name, priceRangeValue.key), UntypedFilterBuilder.GetRangeFilter((IFieldConfiguration)field, priceRangeValue.lowerbound, priceRangeValue.upperbound, priceRangeValue.lowerboundincluded, priceRangeValue.upperboundincluded)));
                }
            }
        }
Пример #12
0
 /// <summary>
 /// Adds faceting requests to the search for the specified pricing.
 /// </summary>
 public static ITypeSearch <FindDocument> AddPriceFacet(this ITypeSearch <FindDocument> search, SearchFilter filter, Mediachase.Commerce.Currency currency, MarketId marketId)
 {
     foreach (KeyValuePair <string, Expression <Func <FindDocument, Filter> > > priceFacet in search.GetPriceFacets(filter, currency, marketId))
     {
         search = search.FilterFacet <FindDocument>(priceFacet.Key, priceFacet.Value);
     }
     return(search);
 }