public virtual ProductItemViewModel Build(ProductModel productModel, bool inProductListPage = true) { var cartContext = _cartContextAccessor.CartContext; var currency = (cartContext == null) ? _currencyService.Get(_requestModelAccessor.RequestModel.CountryModel.Country.CurrencySystemId) : _currencyService.Get(cartContext.CurrencyCode); var country = (cartContext == null) ? _requestModelAccessor.RequestModel.CountryModel.Country : _countryService.Get(cartContext.CountryCode); var websiteModel = _requestModelAccessor.RequestModel.WebsiteModel; var productPriceModel = _productPriceModelBuilder.Build(productModel.SelectedVariant, currency, _requestModelAccessor.RequestModel.ChannelModel.Channel, country); var images = productModel.SelectedVariant.Fields.GetValue <IList <Guid> >(SystemFieldDefinitionConstants.Images).MapTo <IList <ImageModel> >(); return(new ProductItemViewModel { SystemId = productModel.SelectedVariant.SystemId, Id = productModel.SelectedVariant.Id, Price = productPriceModel, FormattedPrice = productPriceModel.Price.FormatPrice(true), StockStatusDescription = _stockService.GetStockStatusDescription(productModel.SelectedVariant), Currency = currency, IsInStock = _stockService.HasStock(productModel.SelectedVariant), Images = images, ImageUrls = images.Select(image => image.GetUrlToImage(new System.Drawing.Size(220, 300), new System.Drawing.Size(280, 400)).Url).ToArray(), Color = _fieldDefinitionService.Get <ProductArea>("Color").GetTranslation(productModel.GetValue <string>("Color")), Size = _fieldDefinitionService.Get <ProductArea>("Size").GetTranslation(productModel.GetValue <string>("Size")), Brand = _fieldDefinitionService.Get <ProductArea>("Brand").GetTranslation(productModel.GetValue <string>("Brand")), Description = productModel.GetValue <string>(SystemFieldDefinitionConstants.Description), Name = productModel.GetValue <string>(SystemFieldDefinitionConstants.Name), Url = productModel.GetUrl(websiteModel.SystemId, channelSystemId: _requestModelAccessor.RequestModel.ChannelModel.SystemId), QuantityFieldId = Guid.NewGuid().ToString(), ShowBuyButton = websiteModel.GetValue <bool>(AcceleratorWebsiteFieldNameConstants.ShowBuyButton), ShowQuantityField = inProductListPage ? websiteModel.GetValue <bool>(AcceleratorWebsiteFieldNameConstants.ShowQuantityFieldProductList) : websiteModel.GetValue <bool>(AcceleratorWebsiteFieldNameConstants.ShowQuantityFieldProductPage), UseVariantUrl = productModel.UseVariantUrl }); }
public virtual void CalculateFromCarrier(OrderCarrier orderCarrier, SecurityToken token) { var currency = currencyService.Get(orderCarrier.CurrencyID); var total = 0m; foreach (var r in orderCarrier.OrderRows) { CalculateOrderRowTotal(r, currency); total += r.TotalPrice; } orderCarrier.TotalOrderRow = total; }
public override ValidationResult Validate(ValidateCartContextArgs entity, ValidationMode validationMode) { var result = new ValidationResult(); var order = entity.Cart.Order; if (order.Rows.Count > 0) { var personId = order.CustomerInfo?.PersonSystemId ?? _securityContextService.GetIdentityUserSystemId() ?? Guid.Empty; var orderRows = order.Rows.Where(x => x.OrderRowType == OrderRowType.Product) .Select(orderRow => _salesOrderRowFactory.Create(new CreateSalesOrderRowArgs { ArticleNumber = orderRow.ArticleNumber, Quantity = orderRow.Quantity, PersonSystemId = personId, ChannelSystemId = order.ChannelSystemId ?? Guid.Empty, CountrySystemId = _countryService.Get(order.CountryCode)?.SystemId ?? Guid.Empty, CurrencySystemId = _currencyService.Get(order.CurrencyCode)?.SystemId ?? Guid.Empty })); if (orderRows.Any(result => result == null)) { result.AddError("Cart", "sales.validation.product.nolongeravailableforsale".AsWebsiteText()); } } return(result); }
public virtual List <DeliveryMethodViewModel> Build(string countryCode, string currencyCode) { var currency = _currencyService.Get(currencyCode); if (currency == null) { return(new List <DeliveryMethodViewModel>()); } var countrySystemId = _countryService.Get(countryCode)?.SystemId; var channelSystemId = _requestModelAccessor.RequestModel.ChannelModel?.Channel?.SystemId; List <DeliveryMethodViewModel> deliveryMethods = new List <DeliveryMethodViewModel>(); var channel = _channelService.Get(channelSystemId.HasValue ? channelSystemId.Value : Guid.Empty); foreach (var shippingOption in channel?.CountryLinks?.Where(x => x.CountrySystemId == countrySystemId)?.SelectMany(x => x.ShippingOptions)) { var fee = shippingOption.Fee ?? 0m; deliveryMethods.Add(new DeliveryMethodViewModel { Id = shippingOption.Id, FormattedPrice = currency.Format(shippingOption.Fee ?? 0, true, CultureInfo.CurrentCulture), Name = string.IsNullOrWhiteSpace(shippingOption.Name) ? shippingOption.Id.ToString() : shippingOption.Name, Price = shippingOption.Fee }); } return(deliveryMethods); }
public override ValidationResult Validate(ValidateCartContextArgs entity, ValidationMode validationMode) { var result = new ValidationResult(); var order = entity.Cart.Order; if (order.Rows.Count > 0) { var personId = order.CustomerInfo?.PersonSystemId ?? _securityContextService.GetIdentityUserSystemId() ?? Guid.Empty; var orderRows = from orderRow in order.Rows.Where(x => x.OrderRowType == OrderRowType.Product) let createdRow = _salesOrderRowFactory.Create(new CreateSalesOrderRowArgs { ArticleNumber = orderRow.ArticleNumber, Quantity = orderRow.Quantity, PersonSystemId = personId, ChannelSystemId = order.ChannelSystemId ?? Guid.Empty, CountrySystemId = _countryService.Get(order.CountryCode)?.SystemId ?? Guid.Empty, CurrencySystemId = _currencyService.Get(order.CurrencyCode)?.SystemId ?? Guid.Empty }) where createdRow != null where orderRow.UnitPriceExcludingVat != createdRow.UnitPriceExcludingVat || orderRow.VatRate != createdRow.VatRate select orderRow; if (orderRows.Any()) { result.AddError("Cart", "sales.validation.productprices.haschanged".AsWebsiteText()); } } return(result); }
public virtual CheckoutViewModel Build(CartContext cartContext) { var requestModel = _requestModelAccessor.RequestModel; var orderDetails = cartContext?.Cart.Order; var countryCode = orderDetails?.CountryCode ?? requestModel.CountryModel.Country.Id; var currencyCode = orderDetails?.CurrencyCode ?? _currencyService.Get(requestModel.CountryModel.Country.CurrencySystemId)?.Id; var deliveryMethods = _deliveryMethodViewModelBuilder.Build(countryCode, currencyCode); var paymentOptions = _paymentOptionViewModelBuilder.Build(cartContext); _signInUrlResolver.TryGet(_routeRequestLookupInfoAccessor.RouteRequestLookupInfo, out var loginPageUrl); var checkoutModeInt = requestModel.WebsiteModel.GetValue <int>(AcceleratorWebsiteFieldNameConstants.CheckoutMode); var checkoutMode = checkoutModeInt == 0 ? CheckoutMode.Both : (CheckoutMode)checkoutModeInt; var model = new CheckoutViewModel() { Authenticated = _securityContextService.GetIdentityUserSystemId().HasValue, CheckoutMode = (int)checkoutMode, DeliveryMethods = deliveryMethods, PaymentMethods = paymentOptions, IsBusinessCustomer = _personStorage.CurrentSelectedOrganization != null, CompanyName = _personStorage.CurrentSelectedOrganization?.Name, CheckoutUrl = cartContext?.CheckoutFlowInfo.CheckoutPageUrl, TermsUrl = cartContext?.CheckoutFlowInfo.TermsUrl, LoginUrl = loginPageUrl, }; GetSelectedShippingOptionId(model, orderDetails); GetSelectedPaymentOptionId(model, orderDetails); GetCustomerDetails(model); //Connected country to the channel must be selected if (model.IsBusinessCustomer) { var countries = _countryService.GetAll().Where(x => _requestModelAccessor.RequestModel.ChannelModel.Channel.CountryLinks.Any(y => y.CountrySystemId == x.SystemId)); var companyAddresses = _personStorage.CurrentSelectedOrganization?.Addresses?.Where(x => countries.Any(y => y.Id == x.Country)) .Select(address => address.MapTo <AddressViewModel>())?.Where(address => address != null)?.ToList(); model.CompanyAddresses = companyAddresses; model.SelectedCompanyAddressId = companyAddresses?.FirstOrDefault(x => x.Country == countryCode)?.SystemId; } else { model.CustomerDetails.Country = countryCode; } return(model); }
public CartViewModel Build(CartContext cartContext) { if (cartContext == null) { return(new CartViewModel { Quantity = "0", }); } var includeVat = IncludeVat(cartContext.Cart); decimal discount = 0; if (cartContext.Cart.Order is SalesOrder salesOrder) { var resultOrderRows = salesOrder.DiscountInfo.Where(x => !x.ProductDiscount).Select(x => x.ResultOrderRowSystemId).ToList(); if (resultOrderRows.Count > 0) { var discountRows = cartContext.Cart.Order.Rows.Where(x => resultOrderRows.Contains(x.SystemId)).ToList(); discount = includeVat ? discountRows.Sum(x => x.TotalIncludingVat) : discountRows.Sum(x => x.TotalExcludingVat); } } var deliveryCost = includeVat ? cartContext.Cart.Order.ShippingCostIncludingVat : cartContext.Cart.Order.ShippingCostExcludingVat; var paymentCost = includeVat ? cartContext.Cart.Order.TotalFeesIncludingVat : cartContext.Cart.Order.TotalFeesExcludingVat; var quantity = cartContext.Cart.Order.Rows.Where(x => x.OrderRowType == OrderRowType.Product).Sum(x => x.Quantity); var currency = _currencyService.Get(cartContext.CurrencyCode); var checkoutPage = _requestModelAccessor.RequestModel.WebsiteModel.GetValue <PointerPageItem>(AcceleratorWebsiteFieldNameConstants.CheckoutPage).MapTo <LinkModel>(); var orderRows = cartContext.Cart.Order.Rows.Where(x => x.OrderRowType == OrderRowType.Product).Select(row => BuildOrderRow(row, currency, includeVat, cartContext.Cart.Order)).ToList(); var orderTotal = includeVat ? orderRows.Sum(x => x.CampaignPrice is null? x.TotalPriceIncludingVat : x.TotalCampaignPriceIncludingVat.Value) : orderRows.Sum(x => x.CampaignPrice is null ? x.TotalPriceExcludingVat : x.TotalCampaignPriceExcludingVat.Value); return(new CartViewModel { GrandTotal = currency.Format(cartContext.Cart.Order.GrandTotal, true, CultureInfo.CurrentCulture), OrderTotal = currency.Format(orderTotal, true, CultureInfo.CurrentCulture), Discount = currency.Format(discount, true, CultureInfo.CurrentCulture), DeliveryCost = currency.Format(deliveryCost, true, CultureInfo.CurrentCulture), PaymentCost = currency.Format(paymentCost, true, CultureInfo.CurrentCulture), Vat = currency.Format(cartContext.Cart.Order.TotalVat, true, CultureInfo.CurrentCulture), Quantity = decimal.Round(quantity, 0).ToString(CultureInfo.CurrentCulture), OrderRows = orderRows, CheckoutUrl = checkoutPage?.Href, }); }
public async void Get_null_record() { var mock = new ServiceMockFacade <ICurrencyRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <string>())).Returns(Task.FromResult <Currency>(null)); var service = new CurrencyService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.CurrencyModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLCurrencyMapperMock, mock.DALMapperMockFactory.DALCurrencyMapperMock, mock.BOLMapperMockFactory.BOLCurrencyRateMapperMock, mock.DALMapperMockFactory.DALCurrencyRateMapperMock); ApiCurrencyResponseModel response = await service.Get(default(string)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <string>())); }
private Currency GetCurrency(OrderCarrier orderCarrier) { if (orderCarrier == null) { orderCarrier = CalculatorContext.GetCurrentOrderCarrier(); } Currency currency = null; if (orderCarrier != null) { currency = currencyService.Get(orderCarrier.CurrencyID); } if (currency == null) { currency = new Currency(string.Empty); } return(currency); }
public VariantInfo Build(Guid variantSystemId, Guid channelSystemId, DataFilterBase dataFilter = null) { if (variantSystemId == Guid.Empty) { return(null); } var entity = _variantService.Get(variantSystemId); if (entity == null) { return(null); } var pageModel = new VariantInfo() { SystemId = variantSystemId }; var currency = _currencyService.Get(id: ((ProductDataFilter)dataFilter)?.Currency) ?? _currencyService.GetBaseCurrency(); BuildFields(pageModel, entity, dataFilter?.Culture); BuildPrices(pageModel, entity, currency, channelSystemId); return(pageModel); }
public virtual List <PaymentOptionViewModel> Build(CartContext cartContext) { var paymentOptions = new List <PaymentOptionViewModel>(); if (cartContext != null) { var channel = _channelService.Get(cartContext.ChannelSystemId.GetValueOrDefault()); var countrySystemId = _countryService.Get(cartContext.CountryCode)?.SystemId; var currency = _currencyService.Get(cartContext.CurrencyCode); foreach (var paymentOption in channel?.CountryLinks?.Where(x => x.CountrySystemId == countrySystemId)?.SelectMany(x => x.PaymentOptions)) { paymentOptions.Add(new PaymentOptionViewModel { Id = paymentOption.Id, FormattedPrice = currency?.Format(paymentOption.Fee ?? 0m, true, CultureInfo.CurrentCulture), Name = string.IsNullOrWhiteSpace(paymentOption.Name) ? paymentOption.Id.ToString() : paymentOption.Name, Price = paymentOption.Fee }); } } return(paymentOptions); }
internal OrderDetailsViewModel Build(OrderOverview orderOverview) { var order = orderOverview.SalesOrder; if (order == null) { return(new OrderDetailsViewModel()); } var includeVat = IncludeVat(order); var currency = _currencyService.Get(order.CurrencyCode); var paymentOptionName = string.Empty; var shippingOptionName = string.Empty; DateTimeOffset?deliveryDate = null; if (order.ChannelSystemId.HasValue) { var paymentOption = _orderHelperService.GetPaymentOption(order); paymentOptionName = paymentOption?.Name.NullIfWhiteSpace() ?? paymentOption?.Id?.ToString(); var shippingOption = _orderHelperService.GetShippingOption(order); shippingOptionName = shippingOption?.Name.NullIfWhiteSpace() ?? shippingOption?.Id?.ToString(); } var shippingInfo = order.ShippingInfo.FirstOrDefault(); if (shippingInfo != null) { var shippingOption = _shippingProviderService.Get(shippingInfo.ShippingOption.ProviderId)?.Options.FirstOrDefault(x => x.Id == shippingInfo.ShippingOption.OptionId); if (shippingOption != null) { deliveryDate = order.OrderDate.AddDays(shippingOption.DeliveryTimeInDays); } } var orderState = _stateTransitionsService.GetState <SalesOrder>(order.SystemId); var statusTranslation = ("sales.order.status." + orderState).AsWebsiteText(); var orderTotalFee = includeVat ? order.TotalFeesIncludingVat : order.TotalFeesExcludingVat; var orderTotalDiscountAmount = includeVat ? order.TotalPromotionsAndDiscountsIncludingVat : order.TotalPromotionsAndDiscountsExcludingVat; var orderTotalDeliveryCost = includeVat ? order.ShippingCostIncludingVat : order.ShippingCostExcludingVat; var totalVat = order.TotalVat; var grandTotal = order.GrandTotal; string organizationName = string.Empty; if (order.CustomerInfo.OrganizationSystemId.HasValue) { var organization = _organizationService.Get(order.CustomerInfo.OrganizationSystemId.Value); organizationName = organization != null ? organization.Name : order.ShippingInfo.FirstOrDefault()?.ShippingAddress.OrganizationName; } var shippingAddress = order.ShippingInfo.First()?.ShippingAddress; var orderDetails = new OrderDetailsViewModel { OrderId = order.SystemId, ExternalOrderID = order.Id, OrderDate = order.OrderDate, OrderStatus = orderState, Status = statusTranslation, OrderTotalFee = currency.Format(orderTotalFee, true, CultureInfo.CurrentUICulture), OrderTotalDiscountAmount = orderTotalDiscountAmount < 0 ? currency.Format(orderTotalDiscountAmount, true, CultureInfo.CurrentUICulture) : string.Empty, OrderTotalDeliveryCost = currency.Format(orderTotalDeliveryCost, true, CultureInfo.CurrentUICulture), OrderTotalVat = currency.Format(totalVat, true, CultureInfo.CurrentUICulture), OrderGrandTotal = currency.Format(grandTotal, true, CultureInfo.CurrentUICulture), OrderRows = order.Rows.Where(x => x.OrderRowType == OrderRowType.Product).Select(x => BuildOrderRow(x, includeVat, currency, order)).ToList(), PaymentMethod = paymentOptionName, DeliveryMethod = shippingOptionName, ActualDeliveryDate = deliveryDate, Deliveries = order.ShippingInfo.Select(x => BuildDeliveryRow(orderOverview, x, includeVat, currency)).ToList(), CustomerInfo = new OrderDetailsViewModel.CustomerInfoModel { CustomerNumber = order.CustomerInfo?.CustomerNumber, FirstName = order.CustomerInfo?.FirstName, LastName = order.CustomerInfo?.LastName, Address1 = shippingAddress?.Address1, Zip = shippingAddress?.ZipCode, City = shippingAddress?.City, Country = string.IsNullOrEmpty(shippingAddress?.Country) ? string.Empty : new RegionInfo(shippingAddress.Country).DisplayName }, MerchantOrganizationNumber = _personStorage.CurrentSelectedOrganization?.Id, CompanyName = organizationName }; return(orderDetails); }
private void CreateBasicMaping(StructureInfo structureInfo) { //Visitor Group structureInfo.Mappings.Add(structureInfo.Foundation.VisitorGroupId, (_groupService.Get <Group>("Visitors") ?? _groupService.Get <Group>("Besökare"))?.SystemId ?? CreateVisitorGroup()); //Language Map foreach (var item in structureInfo.Foundation.LanguageMap) { var culture = new CultureInfo(item.Value); structureInfo.Mappings.Add(item.Key, Solution.Instance.Languages.Exists(culture) ? Solution.Instance.Languages[culture].ID : Solution.Instance.Languages.CreateLanguage(culture.NativeName, culture, false, ModuleProductCatalog.Instance.AdminToken).ID); } //Currency Map foreach (var item in structureInfo.Foundation.Currencies) { var cu = _currencyService.Get(item.Id); if (cu == null) { cu = new Currency(item.Id); _currencyService.Create(cu); } if (!structureInfo.Mappings.ContainsKey(item.SystemId)) { structureInfo.Mappings.Add(item.SystemId, cu.SystemId); } } //Relation map if (structureInfo.Foundation.RelationTemplates != null) { var relationTemplates = _fieldTemplateService.GetAll().ToList(); foreach (var template in structureInfo.Foundation.RelationTemplates) { var fieldTemplate = relationTemplates.FirstOrDefault(x => x.Id == template.Value); if (fieldTemplate != null) { structureInfo.Mappings.Add(template.Key, fieldTemplate.SystemId); } } } // Template foreach (var marketTemplate in structureInfo.Website.MarketTemplateMap) { var template = _fieldTemplateService.Get <MarketFieldTemplate>(marketTemplate.Value); structureInfo.Mappings.Add(marketTemplate.Key, template?.SystemId ?? Guid.Empty); } // Market mappings structureInfo.Mappings.Add(structureInfo.Website.Market.SystemId, Guid.NewGuid()); //Channel foreach (var channelTemplate in structureInfo.Website.ChannelTemplateMap) { var template = _fieldTemplateService.Get <ChannelFieldTemplate>(channelTemplate.Value); structureInfo.Mappings.Add(channelTemplate.Key, template?.SystemId ?? Guid.Empty); } structureInfo.Mappings.Add(structureInfo.Website.Channel.SystemId, Guid.NewGuid()); //Website structureInfo.Mappings.Add(structureInfo.Website.Website.SystemId, Guid.NewGuid()); foreach (var websiteTemplate in structureInfo.Website.WebsiteTemplateMap) { var template = _fieldTemplateService.Get <WebsiteFieldTemplate>(websiteTemplate.Value); structureInfo.Mappings.Add(websiteTemplate.Key, template?.SystemId ?? Guid.Empty); } }