// Where it happens for the new Promos/Cust-Pricing...need to clean this mess upp public static Price GetDiscountPrice( EntryContentBase contentReference, int quantity, decimal promoPrice /*, string catalogName, string categoryName*/) { // some basic validation if (contentReference == null) { throw new NullReferenceException("entry object can't be null"); } if (contentReference as IPricing == null) { throw new InvalidCastException("entry object must implement IPricing"); } // Define the PriceFilter PriceFilter filter = new PriceFilter() { Quantity = 0M, // need improvements here Currencies = new Currency[] { _currentMarket.Service.GetCurrentMarket().Currencies.FirstOrDefault() }, // only have one at the moment... CustomerPricing = GetCustomerPricingList(), // changed ReturnCustomerPricing = true // // ... if true; gets all that applies }; // The rest needed, CatKey, Market, TimeStamp CatalogKey catalogKey = new CatalogKey(contentReference.Code); // 3 overloads #region This is old stuff, may not use /* more hassle to get it working you could say, but used in the right way ... * ...it could simplyfy ... but it's still old */ //ItemCollection<Price> prices = pricingSKU.GetPrices( // _readOnlyPricingLoader.Service // , _currentMarket.Service.GetCurrentMarket().MarketId // , customerPricing); #endregion // ToDo: Get all applicable prices //IEnumerable<IPriceValue> prices = null; // starter IEnumerable <IPriceValue> prices = // Solution _priceService.Service.GetPrices(_currentMarket.Service.GetCurrentMarket().MarketId , DateTime.Now, catalogKey , filter); //ToDo: Identify the lowest price when the "base-price is excluded" // Outcommented is starter-code to make things work ... // ...exchange the below for lab-code //Price p = new Price(); //IPriceValue lowPrice = p.ToPriceValue(); // Solution IPriceValue lowPrice = prices.Where(x => x.MinQuantity <= quantity && x.CustomerPricing.PriceTypeId != (CustomerPricing.PriceType) 3) // do not look on "BasePrice" .OrderBy(pv => pv.UnitPrice).FirstOrDefault(); //ToDO: Get the base price (which is the lowest possible price) //IPriceValue basePrice = null; // is the starter // use as solution IPriceValue basePrice = prices.Where( x => x.CustomerPricing.PriceTypeId == (CustomerPricing.PriceType) 3).First(); // ...should check the RG... and reload if not filled with nodes Entry entry = contentReference.LoadEntry(CatalogEntryResponseGroup.ResponseGroup.Nodes); //get the discount price and return the highest of the discounted price and base price Price discountedPrice = GetDiscountPriceInternal(contentReference, entry, lowPrice, null, null); // sending empty... for now // As starter have the fork but return null...in both //ToDO: Add logic to set the discounted price to the base price if its lower than the base price // starter //if (basePrice != null && discountedPrice != null) // Solution, messy rewritten to us the new "promo-system" //if (basePrice != null && discountedPrice != null && basePrice.UnitPrice.Amount if (basePrice != null && basePrice.UnitPrice.Amount //> discountedPrice.UnitPrice.Amount) // old promos > promoPrice) // new promos { return(new Price(basePrice)); } else { // returning the promo-Price ... need a re-work return(new Price { UnitPrice = new Money(promoPrice, _currentMarket.Service.GetCurrentMarket().DefaultCurrency), ValidFrom = lowPrice.ValidFrom, ValidUntil = lowPrice.ValidUntil, MinQuantity = lowPrice.MinQuantity, MarketId = lowPrice.MarketId, EntryContent = contentReference, CustomerPricing = lowPrice.CustomerPricing }); } }