コード例 #1
0
        private void GetPriceInfo(DemoMarketsViewModel viewModel)
        {
            var filter = new PriceFilter();

            viewModel.OptimizedPrices = _priceService.GetPrices(viewModel.SelectedMarket.MarketId,
                                                                DateTime.Now, new CatalogKey(viewModel.Shirt.Code), filter);

            filter.Quantity = 1;

            var custPricing = new List <CustomerPricing> {
                new CustomerPricing(CustomerPricing.PriceType.AllCustomers, string.Empty)
            };

            if (CustomerContext.Current.CurrentContact != null)
            {
                if (!string.IsNullOrEmpty(PrincipalInfo.Current.Name))
                {
                    custPricing.Add(new CustomerPricing(CustomerPricing.PriceType.UserName,
                                                        PrincipalInfo.Current.Name));
                }

                if (!string.IsNullOrEmpty(CustomerContext.Current.CurrentContact.EffectiveCustomerGroup))
                {
                    custPricing.Add(new CustomerPricing(CustomerPricing.PriceType.PriceGroup,
                                                        CustomerContext.Current.CurrentContact.EffectiveCustomerGroup));
                }
            }

            filter.CustomerPricing = custPricing;

            viewModel.FilteredPrices = _priceService.GetPrices(viewModel.SelectedMarket.MarketId,
                                                               DateTime.Now, new CatalogKey(viewModel.Shirt.Code), filter);

            Money lowestPrice = viewModel.FilteredPrices.OrderBy(p => p.UnitPrice).First().UnitPrice;

            Money lowestAllowed = viewModel.OptimizedPrices
                                  .Where(p => p.CustomerPricing.PriceTypeId == (CustomerPricing.PriceType) 3)
                                  .First().UnitPrice;
            var promos = _promotionEngine.Evaluate(viewModel.Shirt.ContentLink);

            if (promos.Count() > 0)
            {
                viewModel.PromotionsTotal = promos.Sum(p => p.Percentage);
                lowestPrice -= lowestPrice * viewModel.PromotionsTotal / 100;
                if (lowestPrice < lowestAllowed)
                {
                    viewModel.SellingPrice = lowestAllowed;
                }
                else
                {
                    viewModel.SellingPrice      = lowestPrice;
                    viewModel.PromotionsApplied = true;
                }
            }
        }
コード例 #2
0
        public ActionResult Index(ShirtVariation currentContent)
        {
            LoadingExamples(currentContent);

            // Dont't do like this
            //var myVariable = ServiceLocator.Current
            //    .GetInstance<IPriceDetailService>();

            // Don't use this
            //CatalogContentLoader ccc = new CatalogContentLoader();
            //ccc.GetCatalogEntries()

            var currM = _currentMarket.GetCurrentMarket();
            var link  = currentContent.ContentLink;
            //Price price = _readOnlyPricingLoader.Service.GetDefaultPrice(link, currM.MarketId, currM.DefaultCurrency, DateTime.UtcNow);

            // just checking
            //IEnumerable<DiscountedEntry> entries =
            //    _promotionEngine.GetDiscountPrices(
            //    currentContent.ContentLink, _currentMarket.GetCurrentMarket());

            Decimal theDiscount    = 0;
            string  discountString = String.Empty;

            // ...can also get the price direct by _promotionEngine.GetDiscountPrices(....) (above)
            List <RewardDescription> rewards = new List <RewardDescription>();

            rewards = _promotionEngine.Evaluate(currentContent.ContentLink).ToList();
            if (rewards.Count != 0)
            {
                theDiscount     = rewards.First().SavedAmount; // just take one to have a look
                discountString  = rewards.First().Description;
                discountString += " : ";
                discountString += rewards.First().Promotion.Description;
            }
            else
            {
                discountString = "...no discount";
            }


            var model = new Models.ViewModels.ShirtVariationViewModel
            {
                MainBody    = currentContent.MainBody,
                priceString = currentContent.GetDefaultPrice().UnitPrice.Amount.ToString("C"),

                discountString = discountString,
                discountPrice  = currentContent.GetDefaultPrice().UnitPrice.Amount - theDiscount, // could be other than "Default"

                image            = GetDefaultAsset(currentContent),
                CanBeMonogrammed = currentContent.CanBeMonogrammed,
            };

            return(View(model));
        }
コード例 #3
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);
        }
コード例 #4
0
        public ActionResult Index(ShirtVariation currentContent)
        {
            ShirtVariationViewModel model = new ShirtVariationViewModel();

            model.Name             = currentContent.DisplayName;
            model.CanBeMonogrammed = currentContent.CanBeMonogrammed;
            model.Image            = GetDefaultAsset(currentContent);
            model.MainBody         = currentContent.MainBody;
            model.Url         = GetUrl(currentContent.ContentLink);
            model.PriceString = currentContent.GetDefaultPrice().UnitPrice.Amount.ToString("0.00");

            List <RewardDescription> rewardDescriptions = _promotionEngine.Evaluate(currentContent.ContentLink).ToList();

            if (rewardDescriptions.Any())
            {
                model.Messages      = String.Join("<br/>", rewardDescriptions.Select(x => x.Promotion.Name));
                model.DiscountPrice = rewardDescriptions.First().SavedAmount;
            }

            return(View(model));
        }
コード例 #5
0
        public ActionResult Index(ShirtVariation currentContent)
        {
            IsOnLine = CheckIfOnLine.IsInternetAvailable; // Need to know... for Find
            CheckWarehouses(currentContent);              // WH-info on the Page

            var startPage = _contentLoader.Get <StartPage>(ContentReference.StartPage);
            var cartUrl   = _urlResolver.GetUrl(startPage.Settings.cartPage, currentContent.Language.Name);
            var wUrl      = _urlResolver.GetUrl(startPage.Settings.cartPage, currentContent.Language.Name);

            PricingService pSrvs = new PricingService(
                _priceService, _currentMarket, _priceDetailService);

            // used elsewere
            //currentContent.GetCustomerPrices() // works with the R/O-pricingLoader, would miss the custom SaleTypes
            //currentContent.GetPrices() // this one also uses the R/O-Loader ... unusable

            #region Newpromotions

            // New promotions
            decimal savedMoney        = 0;
            string  rewardDescription = String.Empty;
            //IEnumerable<RewardDescription> rewards;

            // get prices incl. "BasePrice"
            //IPriceValue salePrice = BestPricingCalculatorEver.GetSalePrice(currentContent.ContentLink);//
            IPriceValue salePrice = _myPriceCalculator.GetSalePrice(currentContent, 1);
            // the below does the second "Evaluate"
            var descr = _promotionEngine.Evaluate(currentContent.ContentLink).ToList();
            if (descr.Count == 0) // No promos
            {
                var d = new RewardDescription(
                    FulfillmentStatus.NotFulfilled, null, null, 0, 0, RewardType.None, "No promo");
                descr.Add(d);
                rewardDescription = descr.First().Description; // ...just to show
            }
            else
            {
                foreach (var item in descr)
                {
                    rewardDescription += item.Description;
                }
            }

            // previous way
            if (descr.Count() >= 1)
            {
                savedMoney = descr.First().Percentage *salePrice.UnitPrice.Amount / 100;
                //rewardDescription = descr.First().Description;
                Session["SavedMoney"] = savedMoney;
            }
            else
            {
                savedMoney = 0;
                //rewardDescription = "No discount";
            }

            // ...this goes to PriceCalc-discount
            var promoPrice = salePrice.UnitPrice.Amount - savedMoney;

            #endregion

            #region just checking on promos
            //List<RewardDescription> rewards = new List<RewardDescription>();
            //rewards = _promotionEngine.Evaluate(currentContent.ContentLink).ToList();
            //IEnumerable<DiscountedEntry> entries = _promotionEngine.GetDiscountPrices(currentContent.ContentLink, _currentMarket.GetCurrentMarket());
            #endregion

            #region FindStuff


            // new Find-Stuff - need to check this out...
            // FindQueries Qs = new FindQueries();
            // Qs.NewExtensionMethods(currentContent);
            // Qs.SDKExamples(currentContent.ContentLink);
            #endregion

            #region Checking some for routing and http-ctx

            /*
             * var str = currentContent.GetOriginalType().Name; // not for redirect
             * var x = ServiceLocator.Current.GetInstance<TemplateResolver>();
             *
             * RequestContext requestContext = new RequestContext(base.HttpContext, base.RouteData);
             * var parentStack = requestContext.HttpContext.Items[ContentContext.ContentContextKey] as
             * Stack<ContentContext.ContentPropertiesStack>;
             *
             * string controller = requestContext.GetController();
             * var t = x.Resolve(requestContext.HttpContext, new CartPage(), TemplateTypeCategories.MvcController); // could use .Name
             */
            #endregion

            #region LookingAround (incl. new and old Promo-engine)

            //LoadingExamples(currentContent);
            //CheckPrices(currentContent);

            // Have to fake a cart... but it looks good
            //string rewardDescription = String.Empty;

            //decimal savedMoney = CheckBetaPromotions(currentContent, out rewardDescription);

            //var theProxy = currentContent.GetType();
            //var yourClass = currentContent.GetOriginalType();

            //StoreHelper.GetDiscountPrice(currentContent.LoadEntry());
            //StoreHelper.GetSalePrice(currentContent.LoadEntry()

            #endregion

            #region Relations, parent - child, etc.

            CheckOnRelations(currentContent);

            #endregion

            #region RoCe - check this

            // quick-fix - nothing back
            ICart     dummyCart = _orderRepository.LoadOrCreateCart <ICart>(new Guid(), "DummyCart");
            ILineItem lineItem  = _orderGroupFactory.CreateLineItem(currentContent.Code, dummyCart);
            var       c2        = _lineItemCalculator.GetExtendedPrice(lineItem, _currentMarket.GetCurrentMarket().DefaultCurrency);
            var       check     = _lineItemCalculator.GetDiscountedPrice(
                lineItem, _currentMarket.GetCurrentMarket().DefaultCurrency).Amount;

            // Should check the BasePrice here (new way)
            // BestPricingCalc is the old way
            // should override the LI-calculator

            #endregion

            //_currentMarket.GetCurrentMarket().DefaultCurrency.Format(cu)
            //Currency.SetFormat(_currentMarket.GetCurrentMarket().DefaultCurrency.Format.CurrencySymbol);
            string thePriceString = string.Empty;

            if (currentContent.GetDefaultPrice().UnitPrice.Amount == 0)
            {
                thePriceString = "no default price";
            }
            else
            {
                thePriceString = currentContent.GetDefaultPrice().UnitPrice.ToString();
            }

            var model = new ShirtVariationViewModel
            {
                MainBody = currentContent.MainBody,

                // Pricing
                priceString = thePriceString,
                //theRightPriceToPlace = GetThePriceToPlace(currentContent), // tiered pricing...old, not in use
                CustomerPricingPrice = GetCustomerPricingPrice(currentContent),
                //discountPrice = CustomStoreHelper.GetDiscountPrice(currentContent.LoadEntry(CatalogEntryResponseGroup.ResponseGroup.Nodes)),
                discountPriceNew = _lineItemCalculator.GetDiscountedPrice(lineItem, _currentMarket.GetCurrentMarket().DefaultCurrency).Amount,

                image            = GetDefaultAsset((IAssetContainer)currentContent),
                CanBeMonogrammed = currentContent.CanBeMonogrammed,
                ProductArea      = currentContent.ProductArea,
                CartUrl          = cartUrl, // new stuff - not yet in course
                WishlistUrl      = wUrl,    // new stuff - not yet in course

                // Added for Adv. below
                //labPrice = BestPricingCalculatorEver.GetDiscountPrice(currentContent, 1, promoPrice), // , "Fashion", "Shirts"
                labPrice          = _myPriceCalculator.CheckDiscountPrice(currentContent, 1, promoPrice),
                overridePrices    = pSrvs.GetPrices(currentContent.Code),
                PromoString       = rewardDescription, // in #region LookingAround
                betaDiscountPrice = savedMoney,        // in #region LookingAround

                // warehouse info (Lists get filled up in the entrance of "Index-method")
                generalWarehouseInfo  = this.generalWarehouseInfo,
                specificWarehouseInfo = this.specificWarehouseInfo, // Fills up "Specific-List"
                localMarketWarehouses = GetLocalMarketWarehouses(),
                entryCode             = currentContent.Code,

                //Markets
                currentMarket = GetCurrentMarket(),
                marketOwner   = GetMarketOwner(),

                // Associations
                //Associations = GetAssociatedEntries(currentContent), // IEnumerable<ContentReference> // Remove when Aggregation is done
                //AssociationMetaData = GetAssociationMetaData(currentContent), // string // Remove when Aggregation is done
                AssocAggregated = GetAggregatedAssocciations(currentContent), // Dictionary<string, ContentReference> // The final thing

                // Searchendizing ... need to be OnLine to use
                BoughtThisBoughtThat = GetOtherEntries(currentContent.Code),

                // Taxes
                Tax          = GetTaxOldSchool(currentContent),
                TaxString    = GetTaxStrings(currentContent),
                TaxNewSchool = GetTaxNewSchool(currentContent),

                // info about the variation
                VariationAvailability = currentContent.IsAvailableInCurrentMarket(),
                VariationInfo         = "Info: " + CollectInfo()
            };

            return(View(model));
        }