Пример #1
0
        private ProductTileViewModel CreateProductViewModelForEntry(EntryContentBase entry)
        {
            var originalPrice = _pricingService.GetPrice(entry.Code);

            var image = entry.GetAssets <IContentImage>(_contentLoader, _urlResolver).FirstOrDefault() ?? "";

            return(new ProductTileViewModel
            {
                Code = entry.Code,
                DisplayName = entry.DisplayName,
                PlacedPrice = originalPrice?.UnitPrice ?? _pricingService.GetMoney(0),
                DiscountedPrice = GetDiscountPrice(entry),
                ImageUrl = image,
                Url = entry.GetUrl(),
                IsAvailable = originalPrice != null
            });
        }
Пример #2
0
        private void UpdateRecommendation(RecommendationData recommendation, EntryContentBase entry)
        {
            var imageUrl      = entry.GetAssets <IContentImage>(_contentLoader, _urlResolver).FirstOrDefault() ?? "";
            var originalPrice = _pricingService.GetPrice(entry.Code);
            var salePrice     = _pricingService.GetDiscountPrice(entry.Code);

            if (recommendation.Attributes == null)
            {
                recommendation.Attributes = new Dictionary <string, string>();
            }

            recommendation.Attributes.Add(Title, entry.DisplayName);
            recommendation.Attributes.Add(Url, entry.GetUrl(recommendation.Lang));
            recommendation.Attributes.Add(Image, imageUrl);
            recommendation.Attributes.Add(UnitPrice, originalPrice?.UnitPrice.ToString());
            recommendation.Attributes.Add(SalePrice, salePrice?.UnitPrice.ToString());
        }
Пример #3
0
        public virtual CartItemViewModel CreateCartItemViewModel(ICart cart, ILineItem lineItem, EntryContentBase entry)
        {
            var basePrice = lineItem.Properties["BasePrice"] != null?decimal.Parse(lineItem.Properties["BasePrice"].ToString()) : 0;

            var optionPrice = lineItem.Properties["OptionPrice"] != null?decimal.Parse(lineItem.Properties["OptionPrice"].ToString()) : 0;

            var viewModel = new CartItemViewModel
            {
                Code                = lineItem.Code,
                DisplayName         = lineItem.DisplayName,
                ImageUrl            = entry.GetAssets <IContentImage>(_contentLoader, _urlResolver).FirstOrDefault() ?? "",
                DiscountedPrice     = GetDiscountedPrice(cart, lineItem),
                BasePrice           = new Money(basePrice, _currencyService.GetCurrentCurrency()),
                OptionPrice         = new Money(optionPrice, _currencyService.GetCurrentCurrency()),
                PlacedPrice         = new Money(lineItem.PlacedPrice, _currencyService.GetCurrentCurrency()),
                Quantity            = lineItem.Quantity,
                Url                 = entry.GetUrl(_relationRepository, _urlResolver),
                Entry               = entry,
                IsAvailable         = _pricingService.GetCurrentPrice(entry.Code).HasValue,
                DiscountedUnitPrice = GetDiscountedUnitPrice(cart, lineItem),
                IsGift              = lineItem.IsGift,
                Description         = entry["Description"] != null ? entry["Description"].ToString() : "",
                IsDynamicProduct    = lineItem.Properties["VariantOptionCodes"] != null
            };

            var productLink = entry is VariationContent?
                              entry.GetParentProducts(_relationRepository).FirstOrDefault() :
                                  entry.ContentLink;

            if (_contentLoader.TryGet(productLink, out EntryContentBase catalogContent))
            {
                var product = catalogContent as GenericProduct;
                if (product != null)
                {
                    viewModel.Brand = GetBrand(product);
                    var variant = entry as GenericVariant;
                    if (variant != null)
                    {
                        viewModel.AvailableSizes = GetAvailableSizes(product, variant);
                    }
                }
            }

            return(viewModel);
        }
Пример #4
0
        private ProductTileViewModel CreateProductViewModelForEntry(EntryContentBase entry)
        {
            var market          = _currentMarket.GetCurrentMarket();
            var currency        = _currencyService.GetCurrentCurrency();
            var originalPrice   = _pricingService.GetCurrentPrice(entry.Code);
            var discountedPrice = originalPrice.HasValue ? GetDiscountPrice(entry, market, currency, originalPrice.Value) : (Money?)null;
            var image           = entry.GetAssets <IContentImage>(_contentLoader, _urlResolver).FirstOrDefault() ?? "";

            return(new ProductTileViewModel
            {
                DisplayName = entry.DisplayName,
                PlacedPrice = originalPrice.HasValue ? originalPrice.Value : new Money(0, currency),
                DiscountedPrice = discountedPrice,
                ImageUrl = image,
                Url = entry.GetUrl(),
                IsAvailable = originalPrice.HasValue
            });
        }
        private void UpdateOrderLines(IList <OrderLine> orderLines, CheckoutConfiguration checkoutConfiguration)
        {
            foreach (var lineItem in orderLines)
            {
                if (lineItem != null && lineItem.Type.Equals("physical"))
                {
                    EntryContentBase entryContent = null;
                    FashionProduct   product      = null;
                    if (!string.IsNullOrEmpty(lineItem.Reference))
                    {
                        var contentLink = _referenceConverter.Service.GetContentLink(lineItem.Reference);
                        if (!ContentReference.IsNullOrEmpty(contentLink))
                        {
                            entryContent = _contentRepository.Service.Get <EntryContentBase>(contentLink);

                            var parentLink =
                                entryContent.GetParentProducts(_relationRepository.Service).SingleOrDefault();
                            product = _contentRepository.Service.Get <FashionProduct>(parentLink);
                        }
                    }

                    var patchedOrderLine = (PatchedOrderLine)lineItem;
                    if (patchedOrderLine.ProductIdentifiers == null)
                    {
                        patchedOrderLine.ProductIdentifiers = new PatchedProductIdentifiers();
                    }


                    patchedOrderLine.ProductIdentifiers.Brand = product?.Brand;
                    patchedOrderLine.ProductIdentifiers.GlobalTradeItemNumber  = "GlobalTradeItemNumber test";
                    patchedOrderLine.ProductIdentifiers.ManuFacturerPartNumber = "ManuFacturerPartNumber test";
                    patchedOrderLine.ProductIdentifiers.CategoryPath           = "test / test";

                    if (checkoutConfiguration.SendProductAndImageUrl && entryContent != null)
                    {
                        ((PatchedOrderLine)lineItem).ProductUrl = SiteUrlHelper.GetAbsoluteUrl()
                                                                  + entryContent.GetUrl(_relationRepository.Service, _urlResolver.Service);
                    }
                }
            }
        }
Пример #6
0
        private ProductTileViewModel CreateProductViewModelForEntry(EntryContentBase entry)
        {
            var   market        = _currentMarketService.GetCurrentMarket();
            var   currency      = _currencyService.GetCurrentCurrency();
            var   originalPrice = PriceCalculationService.GetSalePrice(entry.Code, market.MarketId, market.DefaultCurrency);
            Money?discountedPrice;

            if (originalPrice?.UnitPrice == null || originalPrice.UnitPrice.Amount == 0)
            {
                originalPrice = new PriceValue()
                {
                    UnitPrice = new Money(0, market.DefaultCurrency)
                };
                discountedPrice = null;
            }
            else
            {
                discountedPrice = GetDiscountPrice(entry, market, currency, originalPrice.UnitPrice);
            }

            var image        = entry.GetAssets <IContentImage>(_contentLoader, _urlResolver).FirstOrDefault() ?? "";
            var currentStore = _storeService.GetCurrentStoreViewModel();

            return(new ProductTileViewModel
            {
                Code = entry.Code,
                DisplayName = entry.DisplayName,
                PlacedPrice = originalPrice.UnitPrice,
                DiscountedPrice = discountedPrice,
                ImageUrl = image,
                Url = entry.GetUrl(),
                IsAvailable = originalPrice.UnitPrice != null && originalPrice.UnitPrice.Amount > 0,
                Stores = new StoreViewModel
                {
                    Stores = _storeService.GetEntryStoresViewModels(entry.Code),
                    SelectedStore = currentStore != null ? currentStore.Code : "",
                    SelectedStoreName = currentStore != null ? currentStore.Name : ""
                }
            });
        }
Пример #7
0
        public virtual CartItemViewModel CreateCartItemViewModel(ICart cart, ILineItem lineItem, EntryContentBase entry)
        {
            var viewModel = new CartItemViewModel
            {
                Code                = lineItem.Code,
                DisplayName         = entry.DisplayName,
                ImageUrl            = entry.GetAssets <IContentImage>(_contentLoader, _urlResolver).FirstOrDefault() ?? "",
                DiscountedPrice     = GetDiscountedPrice(cart, lineItem),
                PlacedPrice         = _pricingService.GetMoney(lineItem.PlacedPrice),
                Quantity            = lineItem.Quantity,
                Url                 = entry.GetUrl(_relationRepository, _urlResolver),
                Entry               = entry,
                IsAvailable         = _pricingService.GetPrice(entry.Code) != null,
                DiscountedUnitPrice = GetDiscountedUnitPrice(cart, lineItem),
                IsGift              = lineItem.IsGift
            };

            var productLink = entry is VariationContent?
                              entry.GetParentProducts(_relationRepository).FirstOrDefault() :
                                  entry.ContentLink;

            FashionProduct product;

            if (_contentLoader.TryGet(productLink, out product))
            {
                viewModel.Brand = GetBrand(product);
            }

            var variant = entry as FashionVariant;

            if (variant != null)
            {
                viewModel.AvailableSizes = GetAvailableSizes(product, variant);
            }

            return(viewModel);
        }
Пример #8
0
        public virtual CartItemViewModel CreateCartItemViewModel(ICart cart, ILineItem lineItem, EntryContentBase entry)
        {
            var viewModel = new CartItemViewModel
            {
                Code                = lineItem.Code,
                DisplayName         = entry.DisplayName,
                ImageUrl            = entry.GetAssets <IContentImage>(_contentLoader, _urlResolver).FirstOrDefault() ?? "",
                DiscountedPrice     = GetDiscountedPrice(cart, lineItem),
                PlacedPrice         = new Money(lineItem.PlacedPrice, _currencyService.GetCurrentCurrency()),
                Quantity            = lineItem.Quantity,
                Url                 = entry.GetUrl(_relationRepository, _urlResolver),
                Entry               = entry,
                IsAvailable         = _pricingService.GetCurrentPrice(entry.Code).HasValue,
                DiscountedUnitPrice = GetDiscountedUnitPrice(cart, lineItem),
                IsGift              = lineItem.IsGift,
                Description         = entry["Description"] != null ? entry["Description"].ToString() : ""
            };

            var productLink = entry is VariationContent?
                              entry.GetParentProducts(_relationRepository).FirstOrDefault() :
                                  entry.ContentLink;

            if (_contentLoader.TryGet(productLink, out GenericProduct product))
            {
                viewModel.Brand = GetBrand(product);
            }

            var variant = entry as GenericVariant;

            if (variant != null)
            {
                viewModel.AvailableSizes = GetAvailableSizes(product, variant);
            }

            viewModel.Description = string.IsNullOrEmpty(viewModel.Description) ? viewModel.Description : product.Description.ToHtmlString();
            return(viewModel);
        }
Пример #9
0
        public Session Build(Session session, ICart cart, PaymentsConfiguration paymentsConfiguration, IDictionary <string, object> dic = null, bool includePersonalInformation = false)
        {
            if (includePersonalInformation && paymentsConfiguration.CustomerPreAssessment)
            {
                session.Customer = new Customer
                {
                    DateOfBirth = "1980-01-01",
                    Gender      = "Male",
                    LastFourSsn = "1234"
                };
            }
            session.MerchantReference2 = "12345";

            if (paymentsConfiguration.UseAttachments)
            {
                var converter = new IsoDateTimeConverter
                {
                    DateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"
                };


                var customerAccountInfos = new List <Dictionary <string, object> >
                {
                    new Dictionary <string, object>
                    {
                        { "unique_account_identifier", "Test Testperson" },
                        { "account_registration_date", DateTime.Now },
                        { "account_last_modified", DateTime.Now }
                    }
                };

                var emd = new Dictionary <string, object>
                {
                    { "customer_account_info", customerAccountInfos }
                };

                session.Attachment = new Attachment
                {
                    ContentType = "application/vnd.klarna.internal.emd-v2+json",
                    Body        = JsonConvert.SerializeObject(emd, converter)
                };
            }

            if (session.OrderLines != null)
            {
                foreach (var lineItem in session.OrderLines)
                {
                    if (lineItem.Type.Equals("physical"))
                    {
                        EntryContentBase entryContent = null;
                        FashionProduct   product      = null;
                        if (!string.IsNullOrEmpty(lineItem.Reference))
                        {
                            var contentLink = _referenceConverter.Service.GetContentLink(lineItem.Reference);
                            if (!ContentReference.IsNullOrEmpty(contentLink))
                            {
                                entryContent = _contentRepository.Service.Get <EntryContentBase>(contentLink);

                                var parentLink =
                                    entryContent.GetParentProducts(_relationRepository.Service).SingleOrDefault();
                                product = _contentRepository.Service.Get <FashionProduct>(parentLink);
                            }
                        }

                        var patchedOrderLine = (PatchedOrderLine)lineItem;
                        if (patchedOrderLine.ProductIdentifiers == null)
                        {
                            patchedOrderLine.ProductIdentifiers = new PatchedProductIdentifiers();
                        }

                        patchedOrderLine.ProductIdentifiers.Brand = product?.Brand;
                        patchedOrderLine.ProductIdentifiers.GlobalTradeItemNumber  = "GlobalTradeItemNumber test";
                        patchedOrderLine.ProductIdentifiers.ManuFacturerPartNumber = "ManuFacturerPartNumber test";
                        patchedOrderLine.ProductIdentifiers.CategoryPath           = "test / test";

                        if (paymentsConfiguration.SendProductAndImageUrlField && entryContent != null)
                        {
                            ((PatchedOrderLine)lineItem).ProductUrl = SiteUrlHelper.GetAbsoluteUrl() + entryContent.GetUrl(_linksRepository.Service,
                                                                                                                           _urlResolver.Service);
                        }
                    }
                }
            }
            return(session);
        }
 public static string GetUrl(this EntryContentBase entry) => entry.GetUrl(RelationRepository.Value, UrlResolver.Value);