Exemplo n.º 1
0
        public void CheckReferenceConverter()
        {
            // variationController has demo code for "Loading examples"
            ContentReference theRef = _referenceConverter.GetContentLink("Shirts_1");
            int theInt = _referenceConverter.GetObjectId(theRef);

            CatalogContentType theType = _referenceConverter.GetContentType(theRef);

            ContentReference theSameRef = _referenceConverter.GetContentLink
                                              (theInt, CatalogContentType.CatalogNode, 0);

            string theCode = _referenceConverter.GetCode(theSameRef);

            ContentReference catalogRoot = _referenceConverter.GetRootLink();

            List <string> codes = new List <string>
            {
                "Shirts_1",
                "Men_1"
            };

            IDictionary <string, ContentReference> theDict;

            theDict = _referenceConverter.GetContentLinks(codes);
        }
Exemplo n.º 2
0
        public async Task <CartContentResponce> Handle(CartContentRequest request, CancellationToken cancellationToken)
        {
            var cart = _cartFactory.LoadOrCreateCart();

            var allLineItems  = cart.GetAllLineItems();
            var lineItemCodes = allLineItems.Select(x => x.Code).Distinct();
            var variants      = _contentLoader.GetItems(_referenceConverter.GetContentLinks(lineItemCodes).Select(x => x.Value), new LoaderOptions {
                LanguageLoaderOption.FallbackWithMaster()
            }).OfType <MovieVariant>();
            var prices    = _customerPriceService.GetPrices(variants.Select(x => x.Code)).ToDictionary(x => x.CatalogKey.CatalogEntryCode, x => x);
            var discounts = _customerPriceService.GetDiscountPrices(variants.Select(x => x.ContentLink)).ToDictionary(x => x.EntryLink, x => x);
            var products  = variants.Select(
                x => new
            {
                variant = x.ContentLink,
                product = _contentLoader.GetItems(x.GetParentProducts(), new LoaderOptions {
                    LanguageLoaderOption.FallbackWithMaster()
                }).OfType <MovieProduct>()
            }).ToDictionary(x => x.variant, x => x.product.FirstOrDefault());

            var lineItems = cart.GetAllLineItems().Select(x => new LineItem()
            {
                Code             = x.Code,
                DisplayName      = x.DisplayName,
                Quantity         = Convert.ToInt32(x.Quantity),
                ImageUrl         = "",//products[variants.Where(y => y.Code == x.Code).Select(y => y.ContentLink).First()].PosterPath,
                Price            = prices[x.Code].UnitPrice.ToString(),
                DiscountPrice    = discounts[variants.First(y => y.Code == x.Code).ContentLink].DiscountPrices.Last().Price.ToString(),
                ProductReference = products[variants.Where(y => y.Code == x.Code).Select(y => y.ContentLink).First()].ContentLink
            });

            var total            = _orderGroupCalculator.GetOrderGroupTotals(cart);
            var tax              = _orderGroupCalculator.GetTaxTotal(cart);
            var orderDiscount    = _orderGroupCalculator.GetOrderDiscountTotal(cart);
            var lineItemDiscount = new Money(cart.GetAllLineItems().Sum(x => x.GetEntryDiscount()), cart.Currency);
            var noDiscount       = new Money(allLineItems.Sum(x => prices[x.Code].UnitPrice.Amount * x.Quantity), cart.Currency);
            var model            = new CartContentResponce()
            {
                LineItems     = lineItems,
                Total         = total.Total.ToString(),
                ItemsDiscount = lineItemDiscount.ToString(),
                OrderDiscount = orderDiscount.ToString(),
                NoDiscount    = noDiscount.ToString()
            };

            return(await Task.FromResult(model));
        }
Exemplo n.º 3
0
 private IDictionary <string, ContentReference> GetEntries(IEnumerable <IPriceValue> prices)
 {
     return(_referenceConverter.GetContentLinks(prices.GroupBy(x => x.CatalogKey.CatalogEntryCode)
                                                .Select(x => x.First().CatalogKey.CatalogEntryCode)));
 }
Exemplo n.º 4
0
        public IEnumerable <DiscountedEntry> GetDiscountPrices(IEnumerable <string> codes)
        {
            var reference = _referenceConverter.GetContentLinks(codes).Select(x => x.Value);

            return(GetDiscountPrices(reference));
        }
        public IEnumerable <ResolvedContentType> ResolveContentTypesFromCodes(IEnumerable <string> codes)
        {
            var references = _referenceConverter.GetContentLinks(codes);

            return(ResolveContentTypes(references.Values));
        }