public static LineItem ToWebModel(this VirtoCommerceCartModuleWebModelLineItem serviceModel, Currency currency, Language language)
        {
            var webModel = new LineItem(currency, language);

            webModel.InjectFrom<NullableAndEnumValueInjecter>(serviceModel);

            if (serviceModel.TaxDetails != null)
            {
                webModel.TaxDetails = serviceModel.TaxDetails.Select(td => td.ToWebModel()).ToList();
            }

            if (serviceModel.DynamicProperties != null)
            {
                webModel.DynamicProperties = serviceModel.DynamicProperties.Select(dp => dp.ToWebModel()).ToList();
            }

            webModel.DiscountTotal = new Money(serviceModel.DiscountTotal ?? 0, currency.Code);
            webModel.ExtendedPrice = new Money(serviceModel.ExtendedPrice ?? 0, currency.Code);
            webModel.IsGift = (bool)serviceModel.IsGift;
            webModel.IsReccuring = (bool)serviceModel.IsReccuring;
            webModel.Length = (decimal)(serviceModel.Length ?? 0);
            webModel.ListPrice = new Money(serviceModel.ListPrice ?? 0, currency.Code);
            webModel.PlacedPrice = new Money(serviceModel.PlacedPrice ?? 0, currency.Code);
            webModel.RequiredShipping = (bool)serviceModel.RequiredShipping;
            webModel.SalePrice = new Money(serviceModel.SalePrice ?? 0, currency.Code);
            webModel.TaxIncluded = (bool)serviceModel.TaxIncluded;
            webModel.Weight = (decimal)(serviceModel.Weight ?? 0);
            webModel.Width = (decimal)(serviceModel.Width ?? 0);

            return webModel;
        }
        public static LineItem ToLineItem(this Product product, Language language, int quantity)
        {
            var lineItemWebModel = new LineItem(product.Price.Currency, language);

            lineItemWebModel.InjectFrom<NullableAndEnumValueInjecter>(product);

            var currency = product.Price.Currency;

            lineItemWebModel.ImageUrl = product.PrimaryImage != null ? product.PrimaryImage.Url : null;
            lineItemWebModel.ListPrice = product.Price.ListPrice;
            lineItemWebModel.SalePrice = product.Price.GetTierPrice(quantity).Price;
            lineItemWebModel.ProductId = product.Id;
            lineItemWebModel.Quantity = quantity;

            lineItemWebModel.ThumbnailImageUrl = product.PrimaryImage != null ? product.PrimaryImage.Url : null;

            return lineItemWebModel;
        }
        public static LineItem ToLineItem(this Product product, Language language, int quantity)
        {
            var lineItemWebModel = new LineItem(product.Price.Currency, language);

            lineItemWebModel.InjectFrom<NullableAndEnumValueInjecter>(product);

            var currency = product.Price.Currency;

            lineItemWebModel.ImageUrl = product.PrimaryImage.Url;
            lineItemWebModel.ListPrice = product.Price.ListPrice;
            lineItemWebModel.SalePrice = product.Price.SalePrice;
            lineItemWebModel.PlacedPrice = product.Price.ActualPrice;
            lineItemWebModel.ExtendedPrice = lineItemWebModel.PlacedPrice * quantity;
            lineItemWebModel.ProductId = product.Id;
            lineItemWebModel.Quantity = quantity;
            lineItemWebModel.TaxTotal = new Money(0, currency.Code);
            lineItemWebModel.ThumbnailImageUrl = product.PrimaryImage.Url;

            return lineItemWebModel;
        }
Example #4
0
 private void AddLineItem(LineItem lineItem)
 {
     var existingLineItem = _cart.Items.FirstOrDefault(li => li.ProductId == lineItem.ProductId);
     if (existingLineItem != null)
     {
         existingLineItem.Quantity += lineItem.Quantity;
     }
     else
     {
         lineItem.Id = null;
         _cart.Items.Add(lineItem);
     }
 }