Example #1
0
        public async Task <ActionResult> Subscription(RequestParamsToCart param)
        {
            var warningMessage = string.Empty;

            ModelState.Clear();

            if (CartWithValidationIssues.Cart == null)
            {
                _cart = new CartWithValidationIssues
                {
                    Cart             = _cartService.LoadOrCreateCart(_cartService.DefaultCartName),
                    ValidationIssues = new Dictionary <ILineItem, List <ValidationIssue> >()
                };
            }

            var result = _cartService.AddToCart(CartWithValidationIssues.Cart, param);

            if (result.EntriesAddedToCart)
            {
                var item = CartWithValidationIssues.Cart.GetAllLineItems().FirstOrDefault(x => x.Code.Equals(param.Code));
                var subscriptionPrice = PriceCalculationService.GetSubscriptionPrice(param.Code, CartWithValidationIssues.Cart.MarketId, CartWithValidationIssues.Cart.Currency);
                if (subscriptionPrice != null)
                {
                    item.Properties["SubscriptionPrice"] = subscriptionPrice.UnitPrice.Amount;
                    item.PlacedPrice = subscriptionPrice.UnitPrice.Amount;
                }

                _orderRepository.Save(CartWithValidationIssues.Cart);
                await _recommendationService.TrackCart(HttpContext, CartWithValidationIssues.Cart);

                return(MiniCartDetails());
            }

            return(new HttpStatusCodeResult(500, result.GetComposedValidationMessage()));
        }
Example #2
0
        public virtual TViewModel CreatePackage <TPackage, TVariant, TViewModel>(TPackage currentContent)
            where TPackage : PackageContent
            where TVariant : VariationContent
            where TViewModel : PackageViewModelBase <TPackage>, new()
        {
            var viewModel         = new TViewModel();
            var variants          = GetVariants <TVariant, TPackage>(currentContent).Where(x => x.Prices().Where(p => p.UnitPrice > 0).Any()).ToList();
            var entries           = GetEntriesRelation(currentContent);
            var market            = _currentMarket.GetCurrentMarket();
            var currency          = _currencyservice.GetCurrentCurrency();
            var defaultPrice      = PriceCalculationService.GetSalePrice(currentContent.Code, market.MarketId, currency);
            var subscriptionPrice = PriceCalculationService.GetSubscriptionPrice(currentContent.Code, market.MarketId, currency);
            var currentStore      = _storeService.GetCurrentStoreViewModel();
            var relatedProducts   = currentContent.GetRelatedEntries().ToList();
            var associations      = relatedProducts.Any() ?
                                    _productService.GetProductTileViewModels(relatedProducts) :
                                    new List <ProductTileViewModel>();
            var contact = PrincipalInfo.CurrentPrincipal.GetCustomerContact();
            var productRecommendations = currentContent as IProductRecommendations;
            var isSalesRep             = PrincipalInfo.CurrentPrincipal.IsInRole("SalesRep");
            var currentWarehouse       = _warehouseRepository.GetDefaultWarehouse();
            var inStockQuantity        = GetAvailableStockQuantity(currentContent, currentWarehouse);
            var isInstock = inStockQuantity > 0;

            viewModel.InStockQuantity   = inStockQuantity;
            viewModel.CurrentContent    = currentContent;
            viewModel.Package           = currentContent;
            viewModel.ListingPrice      = defaultPrice?.UnitPrice ?? new Money(0, currency);
            viewModel.DiscountedPrice   = GetDiscountPrice(defaultPrice, market, currency);
            viewModel.SubscriptionPrice = subscriptionPrice?.UnitPrice ?? new Money(0, currency);
            viewModel.Images            = currentContent.GetAssets <IContentImage>(_contentLoader, _urlResolver);
            viewModel.Media             = currentContent.GetAssetsWithType(_contentLoader, _urlResolver);
            viewModel.IsAvailable       = _databaseMode.DatabaseMode != DatabaseMode.ReadOnly && defaultPrice != null && isInstock;
            viewModel.Entries           = variants;
            viewModel.EntriesRelation   = entries;
            //Reviews = GetReviews(currentContent.Code);
            viewModel.Stores = new StoreViewModel
            {
                Stores            = _storeService.GetEntryStoresViewModels(currentContent.Code),
                SelectedStore     = currentStore != null ? currentStore.Code : "",
                SelectedStoreName = currentStore != null ? currentStore.Name : ""
            };
            viewModel.StaticAssociations  = associations;
            viewModel.HasOrganization     = contact?.OwnerId != null;
            viewModel.ShowRecommendations = productRecommendations?.ShowRecommendations ?? true;
            viewModel.IsSalesRep          = isSalesRep;
            viewModel.SalesMaterials      = isSalesRep ? currentContent.CommerceMediaCollection.Where(x => !string.IsNullOrEmpty(x.GroupName) && x.GroupName.Equals("sales"))
                                            .Select(x => _contentLoader.Get <MediaData>(x.AssetLink)).ToList() : new List <MediaData>();
            viewModel.MinQuantity = defaultPrice != null ? (int)defaultPrice.MinQuantity : 0;
            viewModel.HasSaleCode = defaultPrice != null ? !string.IsNullOrEmpty(defaultPrice.CustomerPricing.PriceCode) : false;

            return(viewModel);
        }
        public virtual TViewModel CreateVariant <TVariant, TViewModel>(TVariant currentContent)
            where TVariant : VariationContent
            where TViewModel : EntryViewModelBase <TVariant>, new()
        {
            var market            = _currentMarket.GetCurrentMarket();
            var currency          = _currencyservice.GetCurrentCurrency();
            var defaultPrice      = PriceCalculationService.GetSalePrice(currentContent.Code, market.MarketId, currency);
            var subscriptionPrice = PriceCalculationService.GetSubscriptionPrice(currentContent.Code, market.MarketId, currency);
            var discountedPrice   = GetDiscountPrice(defaultPrice, market, currency);
            var currentStore      = _storeService.GetCurrentStoreViewModel();
            var relatedProducts   = currentContent.GetRelatedEntries().ToList();
            var associations      = relatedProducts.Any() ?
                                    _productService.GetProductTileViewModels(relatedProducts) :
                                    new List <ProductTileViewModel>();
            var contact = PrincipalInfo.CurrentPrincipal.GetCustomerContact();
            var productRecommendations = currentContent as IProductRecommendations;
            var isSalesRep             = PrincipalInfo.CurrentPrincipal.IsInRole("SalesRep");
            var currentWarehouse       = _warehouseRepository.GetDefaultWarehouse();

            var isInstock = true;

            if (currentContent.TrackInventory)
            {
                var inventoryRecord = _inventoryService.Get(currentContent.Code, currentWarehouse.Code);
                var inventory       = new Inventory(inventoryRecord);
                isInstock = inventory.IsTracked && inventory.InStockQuantity == 0 ? false : isInstock;
            }

            return(new TViewModel
            {
                CurrentContent = currentContent,
                ListingPrice = defaultPrice?.UnitPrice ?? new Money(0, currency),
                DiscountedPrice = discountedPrice,
                SubscriptionPrice = subscriptionPrice?.UnitPrice ?? new Money(0, currency),
                Images = currentContent.GetAssets <IContentImage>(_contentLoader, _urlResolver),
                Media = currentContent.GetAssetsWithType(_contentLoader, _urlResolver),
                IsAvailable = _databaseMode.DatabaseMode != DatabaseMode.ReadOnly && defaultPrice != null && isInstock,
                Stores = new StoreViewModel
                {
                    Stores = _storeService.GetEntryStoresViewModels(currentContent.Code),
                    SelectedStore = currentStore != null ? currentStore.Code : "",
                    SelectedStoreName = currentStore != null ? currentStore.Name : ""
                },
                StaticAssociations = associations,
                HasOrganization = contact?.OwnerId != null,
                ShowRecommendations = productRecommendations?.ShowRecommendations ?? true,
                IsSalesRep = isSalesRep,
                SalesMaterials = isSalesRep ? currentContent.CommerceMediaCollection.Where(x => !string.IsNullOrEmpty(x.GroupName) && x.GroupName.Equals("sales"))
                                 .Select(x => _contentLoader.Get <MediaData>(x.AssetLink)).ToList() : new List <MediaData>(),
                MinQuantity = (int)defaultPrice.MinQuantity,
                HasSaleCode = defaultPrice != null ? !string.IsNullOrEmpty(defaultPrice.CustomerPricing.PriceCode) : false
            });
        }
Example #4
0
        public virtual TViewModel CreatePackage <TPackage, TVariant, TViewModel>(TPackage currentContent)
            where TPackage : PackageContent
            where TVariant : VariationContent
            where TViewModel : PackageViewModelBase <TPackage>, new()
        {
            var variants          = GetVariants <TVariant, TPackage>(currentContent).ToList();
            var market            = _currentMarket.GetCurrentMarket();
            var currency          = _currencyservice.GetCurrentCurrency();
            var defaultPrice      = PriceCalculationService.GetSalePrice(currentContent.Code, market.MarketId, currency);
            var subscriptionPrice = PriceCalculationService.GetSubscriptionPrice(currentContent.Code, market.MarketId, currency);
            var currentStore      = _storeService.GetCurrentStoreViewModel();
            var relatedProducts   = currentContent.GetRelatedEntries().ToList();
            var associations      = relatedProducts.Any() ?
                                    _productService.GetProductTileViewModels(relatedProducts) :
                                    new List <ProductTileViewModel>();
            var contact = PrincipalInfo.CurrentPrincipal.GetCustomerContact();
            var productRecommendations = currentContent as IProductRecommendations;
            var isSalesRep             = PrincipalInfo.CurrentPrincipal.IsInRole("SalesRep");

            return(new TViewModel
            {
                CurrentContent = currentContent,
                Package = currentContent,
                ListingPrice = defaultPrice?.UnitPrice ?? new Money(0, currency),
                DiscountedPrice = GetDiscountPrice(defaultPrice, market, currency),
                SubscriptionPrice = subscriptionPrice?.UnitPrice ?? new Money(0, currency),
                Images = currentContent.GetAssets <IContentImage>(_contentLoader, _urlResolver),
                IsAvailable = defaultPrice != null,
                Entries = variants,
                //Reviews = GetReviews(currentContent.Code),
                Stores = new StoreViewModel
                {
                    Stores = _storeService.GetEntryStoresViewModels(currentContent.Code),
                    SelectedStore = currentStore != null ? currentStore.Code : "",
                    SelectedStoreName = currentStore != null ? currentStore.Name : ""
                },
                StaticAssociations = associations,
                HasOrganization = contact?.OwnerId != null,
                ShowRecommendations = productRecommendations?.ShowRecommendations ?? true,
                IsSalesRep = isSalesRep,
                SalesMaterials = isSalesRep ? currentContent.CommerceMediaCollection.Where(x => !string.IsNullOrEmpty(x.GroupName) && x.GroupName.Equals("sales"))
                                 .Select(x => _contentLoader.Get <MediaData>(x.AssetLink)).ToList() : new List <MediaData>()
            });
        }
Example #5
0
        public virtual TViewModel Create <TProduct, TVariant, TViewModel>(TProduct currentContent, string variationCode)
            where TProduct : ProductContent
            where TVariant : VariationContent
            where TViewModel : ProductViewModelBase <TProduct, TVariant>, new()
        {
            var viewModel = new TViewModel();
            var market    = _currentMarket.GetCurrentMarket();
            var currency  = _currencyservice.GetCurrentCurrency();
            var variants  = GetVariants <TVariant, TProduct>(currentContent)
                            .Where(v => v.Prices().Any(x => x.MarketId == _currentMarket.GetCurrentMarket().MarketId))
                            .ToList();
            var variantsState = GetVarantsState(variants, market);

            if (!TryGetVariant(variants, variationCode, out var variant))
            {
                return(new TViewModel
                {
                    Product = currentContent,
                    CurrentContent = currentContent,
                    Images = currentContent.GetAssets <IContentImage>(_contentLoader, _urlResolver),
                    Media = currentContent.GetAssetsWithType(_contentLoader, _urlResolver),
                    Colors = new List <SelectListItem>(),
                    Sizes = new List <SelectListItem>(),
                    StaticAssociations = new List <ProductTileViewModel>(),
                    Variants = new List <VariantViewModel>()
                });
            }

            variationCode = string.IsNullOrEmpty(variationCode) ? variants.FirstOrDefault()?.Code : variationCode;
            var isInstock        = true;
            var currentWarehouse = _warehouseRepository.GetDefaultWarehouse();

            if (!string.IsNullOrEmpty(variationCode))
            {
                var inStockQuantity = GetAvailableStockQuantity(variant, currentWarehouse);
                isInstock = inStockQuantity > 0;
                viewModel.InStockQuantity = inStockQuantity;
            }

            var defaultPrice      = PriceCalculationService.GetSalePrice(variant.Code, market.MarketId, currency);
            var subscriptionPrice = PriceCalculationService.GetSubscriptionPrice(variant.Code, market.MarketId, currency);
            var discountedPrice   = GetDiscountPrice(defaultPrice, market, currency);
            var currentStore      = _storeService.GetCurrentStoreViewModel();
            var relatedProducts   = currentContent.GetRelatedEntries().ToList();
            var associations      = relatedProducts.Any() ?
                                    _productService.GetProductTileViewModels(relatedProducts) :
                                    new List <ProductTileViewModel>();
            var contact                = PrincipalInfo.CurrentPrincipal.GetCustomerContact();
            var baseVariant            = variant as GenericVariant;
            var productRecommendations = currentContent as IProductRecommendations;
            var isSalesRep             = PrincipalInfo.CurrentPrincipal.IsInRole("SalesRep");

            viewModel.CurrentContent    = currentContent;
            viewModel.Product           = currentContent;
            viewModel.Variant           = variant;
            viewModel.ListingPrice      = defaultPrice?.UnitPrice ?? new Money(0, currency);
            viewModel.DiscountedPrice   = discountedPrice;
            viewModel.SubscriptionPrice = subscriptionPrice?.UnitPrice ?? new Money(0, currency);
            viewModel.Colors            = variants.OfType <GenericVariant>()
                                          .Where(x => x.Color != null)
                                          .GroupBy(x => x.Color)
                                          .Select(g => new SelectListItem
            {
                Selected = false,
                Text     = g.Key,
                Value    = g.Key
            }).ToList();
            viewModel.Sizes = variants.OfType <GenericVariant>()
                              .Where(x => (x.Color == null || x.Color.Equals(baseVariant?.Color, StringComparison.OrdinalIgnoreCase)) && x.Size != null)
                              .Select(x => new SelectListItem
            {
                Selected = false,
                Text     = x.Size,
                Value    = x.Size,
                Disabled = !variantsState.FirstOrDefault(v => v.Key == x.Code).Value
            }).ToList();
            viewModel.Color       = baseVariant?.Color;
            viewModel.Size        = baseVariant?.Size;
            viewModel.Images      = variant.GetAssets <IContentImage>(_contentLoader, _urlResolver);
            viewModel.Media       = variant.GetAssetsWithType(_contentLoader, _urlResolver);
            viewModel.IsAvailable = _databaseMode.DatabaseMode != DatabaseMode.ReadOnly && defaultPrice != null && isInstock;
            viewModel.Stores      = new StoreViewModel
            {
                Stores            = _storeService.GetEntryStoresViewModels(variant.Code),
                SelectedStore     = currentStore != null ? currentStore.Code : "",
                SelectedStoreName = currentStore != null ? currentStore.Name : ""
            };
            viewModel.StaticAssociations = associations;
            viewModel.Variants           = variants.Select(x =>
            {
                var variantImage        = x.GetAssets <IContentImage>(_contentLoader, _urlResolver).FirstOrDefault();
                var variantDefaultPrice = GetDefaultPrice(x.Code, market, currency);
                return(new VariantViewModel
                {
                    Sku = x.Code,
                    Name = x.Name,
                    Size = x is GenericVariant ? $"{(x as GenericVariant).Color} {(x as GenericVariant).Size}" : "",
                    ImageUrl = string.IsNullOrEmpty(variantImage) ? "http://placehold.it/54x54/" : variantImage,
                    DiscountedPrice = GetDiscountPrice(variantDefaultPrice, market, currency),
                    ListingPrice = variantDefaultPrice?.UnitPrice ?? new Money(0, currency),
                    StockQuantity = _quickOrderService.GetTotalInventoryByEntry(x.Code)
                });
            }).ToList();
            viewModel.HasOrganization     = contact?.OwnerId != null;
            viewModel.ShowRecommendations = productRecommendations?.ShowRecommendations ?? true;
            viewModel.IsSalesRep          = isSalesRep;
            viewModel.SalesMaterials      = isSalesRep ? currentContent.CommerceMediaCollection.Where(x => !string.IsNullOrEmpty(x.GroupName) && x.GroupName.Equals("sales"))
                                            .Select(x => _contentLoader.Get <MediaData>(x.AssetLink)).ToList() : new List <MediaData>();
            viewModel.Documents = currentContent.CommerceMediaCollection
                                  .Where(o => o.AssetType.Equals(typeof(PdfFile).FullName.ToLowerInvariant()) || o.AssetType.Equals(typeof(StandardFile).FullName.ToLowerInvariant()))
                                  .Select(x => _contentLoader.Get <MediaData>(x.AssetLink)).ToList();
            viewModel.MinQuantity = (int)defaultPrice.MinQuantity;
            viewModel.HasSaleCode = defaultPrice != null ? !string.IsNullOrEmpty(defaultPrice.CustomerPricing.PriceCode) : false;

            return(viewModel);
        }