#pragma warning restore 649

        /// <summary>
        /// Saves the MSRP price
        /// </summary>
        /// <param name="priceDetailService"></param>
        /// <param name="contentLink"></param>
        /// <param name="marketId"></param>
        /// <param name="currency"></param>
        /// <param name="amount"></param>
        public static void SaveMsrp(
            this IPriceDetailService priceDetailService, ContentReference contentLink, MarketId marketId, Currency currency, decimal amount)
        {
            var priceFilter = new PriceFilter {
                Currencies = new List <Currency> {
                    currency
                }
            };
            var msrp = (PriceDetailValue)priceDetailService
                       .List(contentLink, marketId, priceFilter, 0, int.MaxValue, out _)
                       .FirstOrDefault(
                p => p.UnitPrice.Currency == currency &&
                p.CustomerPricing.PriceTypeId == CustomerPricing.PriceType.PriceGroup &&
                p.CustomerPricing.PriceCode == "MSRP");

            if (msrp != null)
            {
                msrp.UnitPrice = new Money(amount, currency);
            }
            else
            {
                msrp = new PriceDetailValue();
                var entryContent = _contentRepository.Service.Get <EntryContentBase>(contentLink);
                msrp.CatalogKey      = new CatalogKey(entryContent.Code);
                msrp.CustomerPricing = new CustomerPricing(CustomerPricing.PriceType.PriceGroup, "MSRP");
                msrp.UnitPrice       = new Money(amount, currency);
                msrp.MarketId        = marketId;
                msrp.MinQuantity     = 0;
                msrp.ValidFrom       = entryContent.StartPublish ?? DateTime.MinValue;
            }

            priceDetailService.Save(msrp);
        }
Exemple #2
0
        private void AddPrice(string entryCode, decimal price)
        {
            var priceValue = new PriceDetailValue
            {
                CatalogKey      = new CatalogKey(AppContext.Current.ApplicationId, entryCode),
                MarketId        = "DEFAULT",
                CustomerPricing = CustomerPricing.AllCustomers,
                MinQuantity     = 0,
                ValidFrom       = DateTime.Now.AddDays(-7),
                ValidUntil      = DateTime.Now.AddYears(7),
                UnitPrice       = new Money(price, "USD")
            };

            _priceDetailService.Save(priceValue);
        }
Exemple #3
0
        public void CreatePrice(string code)
        {
            List <IPriceDetailValue> newPrices = new List <IPriceDetailValue>();

            var priceDetailValue = new PriceDetailValue
            {
                CatalogKey      = new CatalogKey(code),
                MarketId        = new MarketId("DEFAULT"),
                CustomerPricing = CustomerPricing.AllCustomers,
                ValidFrom       = DateTime.UtcNow.AddDays(-1),
                ValidUntil      = DateTime.UtcNow.AddYears(1),
                MinQuantity     = 5m,
                UnitPrice       = new Money(95m, Currency.USD)
            };

            newPrices.Add(priceDetailValue);

            _priceDetailService.Save(newPrices);
        }
Exemple #4
0
        public override string Execute()
        {
            var allMarkets = _marketService.GetAllMarkets();
            var added      = 0;

            foreach (var variant in _contentLoader.GetAllChildren <MovieVariant>(_referenceConverter.GetRootLink()))
            {
                var newPrices     = new List <PriceDetailValue>();
                var currentPrices = _priceDetailService.List(variant.ContentLink);
                //     var currentPrices2 = _priceService.GetCatalogEntryPrices(new CatalogKey(variant.Code));

                var markets = currentPrices?.Select(x => x.MarketId).Distinct().ToHashSet();

                foreach (var market in allMarkets)
                {
                    if (!markets.Contains(market.MarketId))
                    {
                        foreach (var currency in market.Currencies)
                        {
                            PriceDetailValue newPriceEntry = new PriceDetailValue();

                            newPriceEntry.CatalogKey      = new CatalogKey(variant.Code);
                            newPriceEntry.MinQuantity     = 0;
                            newPriceEntry.MarketId        = market.MarketId;
                            newPriceEntry.UnitPrice       = new Money(GetPrice(currency), currency);
                            newPriceEntry.ValidFrom       = DateTime.Now.AddDays(-1);
                            newPriceEntry.ValidUntil      = DateTime.Now.AddYears(20);
                            newPriceEntry.CustomerPricing = new CustomerPricing(0, "");
                            newPrices.Add(newPriceEntry);
                        }
                    }
                }

                if (newPrices.Any())
                {
                    _priceDetailService.Save(newPrices);
                    added += newPrices.Count;
                }
            }
            return($"Added {added} prices");
        }
Exemple #5
0
        public void AddPrice(VariationContent variant)
        {
            var allMarkets = _marketService.GetAllMarkets();
            var added      = 0;

            var newPrices     = new List <PriceDetailValue>();
            var currentPrices = _priceDetailService.List(variant.ContentLink);
            //     var currentPrices2 = _priceService.GetCatalogEntryPrices(new CatalogKey(variant.Code));

            var markets = currentPrices?.Select(x => x.MarketId).Distinct().ToHashSet();

            foreach (var market in allMarkets)
            {
                if (!markets.Contains(market.MarketId))
                {
                    foreach (var currency in market.Currencies)
                    {
                        PriceDetailValue newPriceEntry = new PriceDetailValue();

                        newPriceEntry.CatalogKey      = new CatalogKey(variant.Code);
                        newPriceEntry.MinQuantity     = 0;
                        newPriceEntry.MarketId        = market.MarketId;
                        newPriceEntry.UnitPrice       = new Money(GetPrice(currency), currency);
                        newPriceEntry.ValidFrom       = DateTime.Now.AddDays(-1);
                        newPriceEntry.ValidUntil      = DateTime.Now.AddYears(20);
                        newPriceEntry.CustomerPricing = new CustomerPricing(0, "");
                        newPrices.Add(newPriceEntry);
                    }
                }
            }

            if (newPrices.Any())
            {
                _priceDetailService.Save(newPrices);
                added += newPrices.Count;
            }
        }