Esempio n. 1
0
        public IEnumerable <CartItem> GetCartItems()
        {
            if (CartHelper.IsEmpty)
            {
                return(Enumerable.Empty <CartItem>());
            }

            var cartItems = new List <CartItem>();
            var lineItems = CartHelper.Cart.GetAllLineItems();

            // In order to show the images for the items in the cart, we need to load the variants
            var variants = _contentLoader.GetItems(lineItems.Select(x => _referenceConverter.GetContentLink(x.Code)),
                                                   _preferredCulture).OfType <VariationContent>();

            var marketId = _currentMarket.GetCurrentMarket().MarketId;
            var currency = _currencyService.GetCurrentCurrency();

            foreach (var lineItem in lineItems)
            {
                VariationContent variant = variants.FirstOrDefault(x => x.Code == lineItem.Code);
                ProductContent   product = _contentLoader.Get <ProductContent>(variant.GetParentProducts().FirstOrDefault());
                CartItem         item    = new CartItem
                {
                    Code          = lineItem.Code,
                    DisplayName   = lineItem.DisplayName,
                    ImageUrl      = variant.GetAssets <IContentImage>(_contentLoader, _urlResolver).FirstOrDefault() ?? "",
                    ExtendedPrice = GetExtendedPrice(lineItem, marketId, currency),
                    PlacedPrice   = lineItem.ToMoney(lineItem.PlacedPrice),
                    DiscountPrice = lineItem.ToMoney(currency.Round(((lineItem.PlacedPrice * lineItem.Quantity) - lineItem.Discounts.Cast <LineItemDiscount>().Sum(x => x.DiscountValue)) / lineItem.Quantity)),
                    Quantity      = lineItem.Quantity,
                    Url           = lineItem.GetUrl(),
                    Variant       = variant,
                    Discounts     = lineItem.Discounts.Cast <LineItemDiscount>().Select(x => new OrderDiscountModel
                    {
                        Discount    = new Money(x.DiscountAmount, new Currency(CartHelper.Cart.BillingCurrency)),
                        Displayname = x.DisplayMessage
                    }),
                    IsAvailable = _pricingService.GetCurrentPrice(variant.Code).HasValue
                };

                if (product is FashionProduct)
                {
                    var fashionProduct = (FashionProduct)product;
                    var fashionVariant = (FashionVariant)variant;
                    item.Brand = fashionProduct.Brand;
                    var variations = _productService.GetVariations(fashionProduct);
                    item.AvailableSizes = variations.Where(x => x.Color == fashionVariant.Color).Select(x => x.Size);
                }

                cartItems.Add(item);
            }

            return(cartItems);
        }
Esempio n. 2
0
        public void UpdateLineItemSku(string oldCode, string newCode, decimal quantity)
        {
            //merge same sku's
            var newLineItem = CartHelper.Cart.GetLineItem(newCode);

            if (newLineItem != null)
            {
                newLineItem.Quantity += quantity;
                RemoveLineItem(oldCode);
                newLineItem.AcceptChanges();
                ValidateCart();
                return;
            }

            var lineItem = CartHelper.Cart.GetLineItem(oldCode);
            var entry    = CatalogContext.Current.GetCatalogEntry(newCode,
                                                                  new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.Variations));

            lineItem.Code            = entry.ID;
            lineItem.MaxQuantity     = entry.ItemAttributes.MaxQuantity;
            lineItem.MinQuantity     = entry.ItemAttributes.MinQuantity;
            lineItem.InventoryStatus = (int)entry.InventoryStatus;

            var price = _pricingService.GetCurrentPrice(newCode);

            lineItem.ListPrice   = price.Amount;
            lineItem.PlacedPrice = price.Amount;

            ValidateCart();
            lineItem.AcceptChanges();
        }
Esempio n. 3
0
        private void UpdateLineItemSku(ICart cart, int shipmentId, string oldCode, string newCode, decimal quantity)
        {
            RemoveLineItem(cart, shipmentId, oldCode);

            //merge same sku's
            var newLineItem = GetFirstLineItem(cart, newCode);

            if (newLineItem != null)
            {
                var shipment = cart.GetFirstForm().Shipments.First(s => s.ShipmentId == shipmentId || shipmentId == 0);
                cart.UpdateLineItemQuantity(shipment, newLineItem, newLineItem.Quantity + quantity);
            }
            else
            {
                newLineItem          = cart.CreateLineItem(newCode, _orderGroupFactory);
                newLineItem.Quantity = quantity;
                cart.AddLineItem(newLineItem, _orderGroupFactory);

                var price = _pricingService.GetCurrentPrice(newCode);
                if (price.HasValue)
                {
                    newLineItem.PlacedPrice = price.Value.Amount;
                }
            }

            ValidateCart(cart);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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
            });
        }
Esempio n. 6
0
        private ProductViewModel CreateProductViewModel(ProductContent product, VariationContent variation)
        {
            if (variation == null)
            {
                return(null);
            }

            ContentReference productContentReference;

            if (product != null)
            {
                productContentReference = product.ContentLink;
            }
            else
            {
                productContentReference = variation.GetParentProducts(_relationRepository).FirstOrDefault();
                if (ContentReference.IsNullOrEmpty(productContentReference))
                {
                    return(null);
                }
            }
            var market   = _currentMarket.GetCurrentMarket();
            var currency = _currencyService.GetCurrentCurrency();

            var originalPrice   = _pricingService.GetCurrentPrice(variation.Code);
            var discountedPrice = originalPrice.HasValue ? GetDiscountPrice(variation, market, currency, originalPrice.Value) : (Money?)null;

            var image = variation.GetAssets <IContentImage>(_contentLoader, _urlResolver).FirstOrDefault() ?? "";
            var brand = product is FashionProduct ? ((FashionProduct)product).Brand : string.Empty;

            return(new ProductViewModel
            {
                DisplayName = product != null ? product.DisplayName : variation.DisplayName,
                PlacedPrice = originalPrice.HasValue ? originalPrice.Value : new Money(0, currency),
                DiscountedPrice = discountedPrice,
                ImageUrl = image,
                Url = variation.GetUrl(),
                Brand = brand,
                IsAvailable = originalPrice.HasValue
            });
        }
        public virtual CartItemViewModel CreateCartItemViewModel(ICart cart, ILineItem lineItem, VariationContent variant)
        {
            var productLink = variant.GetParentProducts(_relationRepository).FirstOrDefault();
            var product     = _contentLoader.Get <ProductContent>(productLink) as BaseProduct;

            return(new CartItemViewModel
            {
                Code = lineItem.Code,
                DisplayName = variant.DisplayName,
                ImageUrl = variant.GetAssets <IContentImage>(_contentLoader, _urlResolver).FirstOrDefault() ?? "",
                DiscountedPrice = GetDiscountedPrice(cart, lineItem),
                PlacedPrice = new Money(lineItem.PlacedPrice, _currencyService.GetCurrentCurrency()),
                Quantity = lineItem.Quantity,
                Url = lineItem.GetUrl(),
                Variant = variant,
                IsAvailable = _pricingService.GetCurrentPrice(variant.Code).HasValue,
                Brand = GetBrand(product),
                AvailableSizes = GetAvailableSizes(product, variant),
                DiscountedUnitPrice = GetDiscountedUnitPrice(cart, lineItem),
                IsGift = lineItem.IsGift
            });
        }
Esempio n. 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);
        }
Esempio n. 9
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(_linksRepository, _urlResolver),
                Entry               = entry,
                IsAvailable         = _pricingService.GetCurrentPrice(entry.Code).HasValue,
                DiscountedUnitPrice = GetDiscountedUnitPrice(cart, lineItem),
                IsGift              = lineItem.IsGift
            };

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

            FashionProduct product;

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

            var variant = entry as FashionVariant;

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

            return(viewModel);
        }