Exemple #1
0
 public static string GetPriceAmountStringSafe(this Price price)
 {
     if (price == null)
     {
         return(string.Empty);
     }
     return(price.UnitPrice.ToString());
 }
Exemple #2
0
 public static decimal GetPriceAmountSafe(this Price price)
 {
     if (price == null)
     {
         return(0);
     }
     return(price.UnitPrice.Amount);
 }
Exemple #3
0
        /// <summary>
        /// Gets the display price for the variation and market, including currency symbol.
        /// </summary>
        /// <param name="variation">The variation to retrieve price from.</param>
        /// <param name="market">The market to get price for. If null, the current market is used.</param>
        /// <returns></returns>
        public static string GetDisplayPrice(this VariationContent variation, IMarket market = null)
        {
            Price price = variation.GetDefaultPriceMoney(market);

            return(price != null?price.UnitPrice.ToString() : string.Empty);
        }
Exemple #4
0
        public static int GetDefaultPriceAmount(this List <VariationContent> variations, IMarket market = null)
        {
            Price price = variations.GetDefaultPriceMoney(market);

            return(price != null?decimal.ToInt32(price.UnitPrice.Amount) : 0);
        }
Exemple #5
0
 /// <summary>
 /// Gets the discount price, if no discount is set, returns string.Empty
 /// </summary>
 /// <param name="variations">All variants for a product</param>
 /// <param name="defaultPrice">The price to compare against</param>
 /// <param name="market">The market.</param>
 /// <returns></returns>
 public static string GetDiscountDisplayPrice(this List <VariationContent> variations, Price defaultPrice, IMarket market = null)
 {
     if (variations.Any())
     {
         VariationContent variationContent = variations.FirstOrDefault(x => x.GetPricesWithMarket(market) != null);
         return(variationContent.GetDiscountDisplayPrice(defaultPrice, market));
     }
     return(string.Empty);
 }
Exemple #6
0
        /// <summary>
        /// Gets the discount price, if no discount is set, returns string.Empty
        /// </summary>
        /// <param name="variation">The variation.</param>
        /// <param name="defaultPrice">The price to return if no discounted price can be found</param>
        /// <param name="market">The market.</param>
        /// <returns></returns>
        public static string GetDiscountDisplayPrice(this VariationContent variation, Price defaultPrice, IMarket market = null)
        {
            if (market == null)
            {
                ICurrentMarket currentMarket = ServiceLocator.Current.GetInstance <ICurrentMarket>();
                market = currentMarket.GetCurrentMarket();
            }
            Func <PriceAndMarket, bool> priceFilter;

            priceFilter = delegate(PriceAndMarket d)
            {
                // Find a non CustomerClub price, but still a price with a price code
                return(d.PriceCode != string.Empty &&
                       !(d.PriceTypeId == CustomerPricing.PriceType.PriceGroup.ToString() &&
                         d.PriceCode == Constants.CustomerGroup.CustomerClub));
            };

            // Find a price with a price code that is not a customer club price
            var discountedPrice = variation.GetPricesWithMarket(market).FirstOrDefault(priceFilter);

            if (discountedPrice != null)
            {
                return(discountedPrice.Price);
            }
            return(string.Empty);


            //if (defaultPrice == null)
            //    return string.Empty;
            //Price price;
            //if(market == null)
            //    price = StoreHelper.GetDiscountPrice(variation.LoadEntry(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));
            //else
            //    price = StoreHelper.GetDiscountPrice(variation.LoadEntry(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull),string.Empty,string.Empty,market);

            //if(price == null)
            //{
            //    return string.Empty;
            //}

            //if (price.Money == defaultPrice.Money)
            //    return string.Empty;

            //return price.Money.Amount.ToString();
        }
Exemple #7
0
        /// <summary>
        /// Gets the discount price, if no discount is set, returns string.Empty
        /// </summary>
        /// <param name="variation">The variation.</param>
        /// <param name="defaultPrice">The price to compare against</param>
        /// <param name="market">The market.</param>
        /// <returns></returns>
        public static string GetDiscountDisplayPrice(this VariationContent variation, Price defaultPrice, IMarket market = null)
        {
            if (market == null)
            {
                ICurrentMarket currentMarket = ServiceLocator.Current.GetInstance <ICurrentMarket>();
                market = currentMarket.GetCurrentMarket();
            }
            Func <PriceAndMarket, bool> priceFilter = d => d.PriceCode != string.Empty &&
                                                      !(d.PriceTypeId == Mediachase.Commerce.Pricing.CustomerPricing.PriceType.PriceGroup.ToString() &&
                                                        d.PriceCode == Constants.CustomerGroup.CustomerClub);


            var prices = variation.GetPricesWithMarket(market).FirstOrDefault(priceFilter);


            if (prices != null)
            {
                return(prices.Price);
            }
            return(string.Empty);



            //if (defaultPrice == null)
            //    return string.Empty;
            //Price price;
            //if(market == null)
            //    price = StoreHelper.GetDiscountPrice(variation.LoadEntry(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));
            //else
            //    price = StoreHelper.GetDiscountPrice(variation.LoadEntry(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull),string.Empty,string.Empty,market);

            //if(price == null)
            //{
            //    return string.Empty;
            //}

            //if (price.Money == defaultPrice.Money)
            //    return string.Empty;

            //return price.Money.Amount.ToString();
        }
 /// <summary>
 /// Gets the discount price, if no discount is set, returns string.Empty
 /// </summary>
 /// <param name="variations">All variants for a product</param>
 /// <param name="defaultPrice">The price to compare against</param>
 /// <param name="market">The market.</param>
 /// <returns></returns>
 public static string GetDiscountDisplayPrice(this List<VariationContent> variations, Price defaultPrice, IMarket market = null)
 {
     if (variations.Any())
     {
         VariationContent variationContent = variations.FirstOrDefault(x => x.GetPricesWithMarket(market) != null);
         return variationContent.GetDiscountDisplayPrice(defaultPrice, market);
     }
     return string.Empty;
 }
        /// <summary>
        /// Gets the discount price, if no discount is set, returns string.Empty
        /// </summary>
        /// <param name="variation">The variation.</param>
        /// <param name="defaultPrice">The price to return if no discounted price can be found</param>
        /// <param name="market">The market.</param>
        /// <returns></returns>
        public static string GetDiscountDisplayPrice(this VariationContent variation, Price defaultPrice, IMarket market = null)
        {
            if (market == null)
            {
                ICurrentMarket currentMarket = ServiceLocator.Current.GetInstance<ICurrentMarket>();
                market = currentMarket.GetCurrentMarket();
            }
            Func<PriceAndMarket, bool> priceFilter;
            priceFilter = delegate(PriceAndMarket d)
            {
                // Find a non CustomerClub price, but still a price with a price code
                return d.PriceCode != string.Empty &&
                       !(d.PriceTypeId == CustomerPricing.PriceType.PriceGroup.ToString() &&
                         d.PriceCode == Constants.CustomerGroup.CustomerClub);
            };

            // Find a price with a price code that is not a customer club price
            var discountedPrice = variation.GetPricesWithMarket(market).FirstOrDefault(priceFilter);

            if (discountedPrice != null)
                return discountedPrice.UnitPrice.ToString();
            return string.Empty;

            //if (defaultPrice == null)
            //    return string.Empty;
            //Price price;
            //if(market == null)
            //    price = StoreHelper.GetDiscountPrice(variation.LoadEntry(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));
            //else
            //    price = StoreHelper.GetDiscountPrice(variation.LoadEntry(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull),string.Empty,string.Empty,market);

            //if(price == null)
            //{
            //    return string.Empty;
            //}

            //if (price.Money == defaultPrice.Money)
            //    return string.Empty;

            //return price.Money.Amount.ToString();
        }
Exemple #10
0
        // Demo - Fund
        public void CheckPrices(EntryContentBase CurrentContent)
        {
            // Pricing, a long story with many alternative

            /*
             * Two services are available for interacting with price data.
             *  - The IPriceService API is typically used by order processing to fetch prices for actual use
             *  - IPriceDetailService is typically used in "integration" and interface/code for display (all prices) and edit prices.
             *
             * The difference between these APIs is that the IPriceService works with optimized sets of price data,
             * while the IPriceDetailService works with "the truth".
             * The optimization in the IPriceService
             * removes prices that will cannot be used, and trims or splits prices that overlap.
             */

            #region StoreHelper...does this

            /*Steps in StoreHelper
             *
             * - Add AllCustomers
             * Check Cust-Group
             * ...Effective-Cust-Group
             * Get the service
             * Set the filter
             * Fetch ...  priceService.GetPrices + get the cheapest (note: always cheapest)
             * Get a ... IPriceValue and then...
             * ....return new Price(priceValue.UnitPrice);
             *
             * public static Price GetSalePrice(Entry entry, decimal quantity, IMarket market, Currency currency)
             *
             */
            #endregion

            // ... look in VariantController for nice extensions

            //var c = CustomerContext.Current.CurrentContact;
            //c.

            #region GetDefaultPrice...does this

            /*
             * Could have a look at .GetDefaultPrice in Reflector
             * PricingExtensions (EPiServer.Commerce.Catalog.ContentTypes)
             * - GetDefaultPrice() // gets the R/O-loader
             *
             * - tries to figure out  the Currency
             * - tries to figure out Market, DateTime, CatalogKey... and does...
             * - IPriceValue GetDefaultPrice(MarketId market, DateTime validOn, CatalogKey catalogKey, Currency currency);
             * ...goes to the concrete impl. för the R/O-provider and creates a PriceFilter
             * ....and gets a "default price" for a catalog entry. The "default price" for a
             *      ....market, currency, and catalog entry is the price available to
             *      "all customers" at a minimum quantity of 0.
             *  ...that in turn goes to the Provider and say GetPrices() ... with all the stuff found
             */

            #endregion


            // PriceDetails ... administrative stuff, don´t use for retrieving prices for the store
            // 3 overloads... the 3:rd with filter & Market
            List <IPriceDetailValue> priceList1 = _priceDetailService.List(CurrentContent.ContentLink).ToList();
            EPiServer.Commerce.SpecializedProperties.Price aPrice =
                new EPiServer.Commerce.SpecializedProperties.Price(priceList1.FirstOrDefault()); // just checking
            // ...have a CreatePrice("theCode"); // further below


            /* dbo.PriceType.sql
             *  0	All Customers
             *  1	Customer
             *  2	Customer Price Group
             */
            // PriceDetail - "R/W"
            // PriceValue, PriceGroup - "R/O" (...but it´s not, did write in R3)
            // Replicate...changes between the two services

            // DB-side paging, GetPrices() takes start-count, is R/O ... it´s a Loader
            PricingLoader detailedPricingLoader = ServiceLocator.Current.GetInstance <PricingLoader>();
            // detailedPricingLoader.GetPrices()

            // Good set of methods, no paging (GetChildrenPrices-obsoleted), gets it all
            ReadOnlyPricingLoader readOnlyPricingLoader = ServiceLocator.Current.GetInstance <ReadOnlyPricingLoader>();



            // detailedPricingLoader. as the service
            //readOnlyPricingLoader.GetChildrenPrices(...) // deprecated
            var p = readOnlyPricingLoader.GetDefaultPrice(CurrentContent.ContentLink);
            // use this "loader" on the front-end...instead of the service

            // PriceService R/O-pricing ("the optimized service" (from the good old R3-era ´:`))
            // ... that´s why we have some confusing stuff left in the system (it entered here before the "Content-Model" was in place)
            CatalogKey catKey = new CatalogKey(CurrentContent.Code); // Catalogkey... example of legacy
            // Note: CatalogKey is gone when using the new Inventory system. There you can go by "code"
            // ...will probably file a blemish-bug on this

            // return full sets of price data for the specified catalog entries?
            // ...also takes an Enumerable
            var pricesByKey    = _priceService.GetCatalogEntryPrices(catKey); // need catalogKey ( or IEnumerable of those )
            var priceByDefault = _priceService.GetDefaultPrice(               // Market, time, CatKey & Currency
                currentMarket.Service.GetCurrentMarket().MarketId             // ...better than MarketId.Default
                , DateTime.UtcNow
                , catKey
                , new Currency("usd"));



            //priceService.GetPrices(  //...3:rd overload takes an IEnumerable of CatalogKeyAndQuantity
            // The GetPrices methods return filtered data for the specified catalog entries. Returned price values
            // ...will match all specified The CatalogKeyAndQuantity class may be used to get prices
            // ...for multiple entries, with different quantities for each, in a single request

            CatalogKeyAndQuantity keyAndQtyExample = new CatalogKeyAndQuantity(catKey, 12);
            // first overload as GetDefaultPrice
            // second as an IEnumerable of keys
            // third as an IEnumerable of keysAndQty


            // If custom built "Optimized"...
            // ...then need a mechanism for synchronizing with a custom detail service, then it must call
            // IPriceDetailService.ReplicatePriceServiceChanges on all edits to update the optimized data store

            #region ... not much of a demo - PrintToPage and Housekeeping

            //Response.Write("<br/>");
            //Response.Write("ContentTypeID" + CurrentContent.ContentTypeID + "<br/>");
            //Response.Write("PriceRef.ID: " + CurrentContent.PriceReference.ID + "<br/>");

            //Response.Write("PriceDetails <br/>");
            //p1.ForEach(p => Response.Write("UnitPrice: " + p.UnitPrice.Amount.ToString() + "<br/>"));
            //Response.Write("PriceValueId: " + p1.FirstOrDefault().PriceValueId + "<br/>");
            //Response.Write("UnitPrice: " + p1.FirstOrDefault().UnitPrice.Amount.ToString() + "<br/>");

            //Response.Write("<br/>");
            //Response.Write("PriceService <br/>"); //  + "<br/>"
            //p2.ToList().ForEach(p => Response.Write("UnitPrice: " + p.UnitPrice.Amount.ToString() + "<br/>"));

            //Response.Write("<br/>");



            //// node
            //Response.Write("PriceList at ParentNode: " + contentLoader.Get<IContent>(CurrentContent.ParentLink).Name + "<br/>");
            //List<IPriceDetailValue> listFromNode = priceDetails.List(CurrentContent.ParentLink).ToList();
            //listFromNode.ForEach(nl => Response.Write(
            //    "CatalogKey: " + nl.CatalogKey.CatalogEntryCode
            //        + " :: " +
            //    "UnitPrice: " + nl.UnitPrice.Amount.ToString() + "<br/>"));

            //Response.Write("<br/>");

            // EPiServer.Commerce.Catalog.ContentTypes.PricingExtensions
            // ...getPrices() ...  by the "ReadOnlyPricingLoader"
            // Below, get all prices
            //EPiServer.Commerce.SpecializedProperties.ItemCollection
            //    <EPiServer.Commerce.SpecializedProperties.Price>
            //    prices = CurrentContent.GetPrices(); // 5 overloads, the third takes "Market" and "CustomerPricing"

            //var pp = CurrentContent.GetPrices(MarketId.Default, new CustomerPricing(CustomerPricing.PriceType.PriceGroup, "SpecialFriends"));
            //// PriceType & PriceCode in API , SaleType & SaleCode in UI
            //// should have the qty here ... ?
            //Response.Write("By Extesion methods <br/>");
            //prices.ToList().ForEach(p => Response.Write(p.UnitPrice.Amount + "<br/>"));
            //pp.ToList().ForEach(p => Response.Write("SpecialFriends: " + p.UnitPrice.Amount.ToString() + "<br/>"));

            #endregion


            /* Price Filter */

            List <Currency>        currencies = new List <Currency>();
            List <CustomerPricing> custprices = new List <CustomerPricing>();

            // SaleCode (UI) or PriceGroup (code) (string) ... the Cust-Group
            // CM / CMS UI: SaleType - SaleCode
            // API: PriceType, PriceCode (string)

            PriceFilter filter = new PriceFilter()
            {
                Quantity        = 2M,
                Currencies      = new Currency[] { "USD", "SEK" },
                CustomerPricing = new CustomerPricing[]
                {
                    new CustomerPricing(CustomerPricing.PriceType.AllCustomers, null),
                    new CustomerPricing(CustomerPricing.PriceType.PriceGroup, "MyBuddies") // or several...
                },
                ReturnCustomerPricing = true                                               // ...see below for info
                                                                                           // interpretation of the CustomerPricing property... if true; gets all that applies
            };

            #region Info ReturnCustomerPricing

            /* The ReturnCustomerPricing property controls the interpretation of the CustomerPricing property.
             * If the value of this property is false, and multiple price values that are identical except for the customer pricing
             * (but both match the prices targeted by the method call) could be returned, then only the entry in that grouping with
             * the lowest price will be returned (this is the more common use case). If the value of this property is true,
             * then all prices will be returned individually. The default value is false. As an example,
             *  suppose a catalog entry has a price of $10.00 for all customers, and $9.00 for one particular customer.
             *  A call to a GetPrices method that would match both prices, and has ReturnCustomerPricing set to false,
             *  would only get the $9.00 price in the result set. If ReturnCustomerPricing was set to true for the same call,
             *  both the $9.00 and $10.00 price would be returned. */

            #endregion

            // The rest needed, CatKey, Market, TimeStamp
            CatalogKey catalogKey = new CatalogKey(new Guid(CurrentContent.ApplicationId), CurrentContent.Code); // 3 overloads

            IEnumerable <IPriceValue> priceValues = _priceService.GetPrices(
                MarketId.Default, FrameworkContext.Current.CurrentDateTime, catalogKey, filter);

            decimal onePrice = priceValues.FirstOrDefault().UnitPrice.Amount; // just checking
        }
        // 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
                });
            }
        }
Exemple #12
0
        public static int GetDefaultPriceAmountWholeNumber(this VariationContent variation, IMarket market)
        {
            Price price = variation.GetPrice(market);

            return(price != null?decimal.ToInt32(price.UnitPrice.Amount) : 0);
        }