public CartItem[] GetShoppingCartItems(bool showPrices = true) { var items = ECommerceContext.CurrentShoppingCart.CartItems; var displayProductionAndShipping = resources.GetSettingsKey("KDA_Checkout_ShowProductionAndShipping").ToLower() == "true"; var result = items .Where(cartItem => !cartItem.IsProductOption) .Select(i => { var cartItem = new CartItem() { Id = i.CartItemID, CartItemText = i.CartItemText, DesignFileKey = i.GetValue("ArtworkLocation", string.Empty), MailingListGuid = i.GetValue("MailingListGuid", Guid.Empty), // seem to be redundant parameter, microservice doesn't use it ChiliEditorTemplateId = i.GetValue("ChilliEditorTemplateID", Guid.Empty), ProductChiliPdfGeneratorSettingsId = i.GetValue("ProductChiliPdfGeneratorSettingsId", Guid.Empty), ProductChiliWorkspaceId = i.GetValue("ProductChiliWorkspaceId", Guid.Empty), ChiliTemplateId = i.GetValue("ChiliTemplateID", Guid.Empty), DesignFilePathTaskId = i.GetValue("DesignFilePathTaskId", Guid.Empty), SKUName = !string.IsNullOrEmpty(i.CartItemText) ? i.CartItemText : i.SKU?.SKUName, SKUNumber = i.SKU?.SKUNumber, TotalTax = 0.0m, UnitPrice = showPrices ? (decimal)i.UnitPrice : 0.0m, UnitOfMeasure = "EA", Image = URLHelper.GetAbsoluteUrl(i.SKU.SKUImagePath), ProductType = i.GetValue("ProductType", string.Empty), Quantity = i.CartItemUnits, TotalPrice = showPrices ? (decimal)i.UnitPrice * i.CartItemUnits : 0.0m, PriceText = showPrices ? string.Format("{0:#,0.00}", i.UnitPrice * i.CartItemUnits) : string.Empty, PricePrefix = showPrices ? resources.GetResourceString("Kadena.Checkout.ItemPricePrefix") : string.Empty, QuantityPrefix = resources.GetResourceString("Kadena.Checkout.QuantityPrefix"), MailingListName = i.GetValue("MailingListName", string.Empty), Template = !string.IsNullOrEmpty(i.CartItemText) ? i.CartItemText : i.SKU.SKUName, EditorTemplateId = i.GetValue("ChilliEditorTemplateID", string.Empty), ProductPageId = i.GetIntegerValue("ProductPageID", 0), SKUID = i.SKUID, StockQuantity = i.SKU.SKUAvailableItems, MailingListPrefix = resources.GetResourceString("Kadena.Checkout.MailingListLabel"), TemplatePrefix = resources.GetResourceString("Kadena.Checkout.TemplateLabel"), ProductionTime = displayProductionAndShipping ? i.GetValue("ProductProductionTime", string.Empty) : null, ShipTime = displayProductionAndShipping ? i.GetValue("ProductShipTime", string.Empty) : null }; if (cartItem.IsTemplated) { cartItem.EditorURL = $@"{documents.GetDocumentUrl(resources.GetSettingsKey("KDA_Templating_ProductEditorUrl")?.TrimStart('~'))} ?nodeId={cartItem.ProductPageId} &templateId={cartItem.EditorTemplateId} &workspaceid={cartItem.ProductChiliWorkspaceId} &containerId={cartItem.MailingListGuid} &quantity={cartItem.Quantity} &customName={URLHelper.URLEncode(cartItem.CartItemText)}"; } return(cartItem); } ).ToArray(); return(result); }
public SearchResultPage Search(string phrase, int results = 100) { var searchResultPages = SearchPages(phrase, results); var searchResultProducts = SearchProducts(phrase, results); return(new SearchResultPage() { NoResultMessage = resources.GetResourceString("Kadena.Search.NoResults"), Pages = searchResultPages, Products = searchResultProducts }); }
public string MapOrderStatus(string microserviceStatus) { var genericStatusItem = CustomTableItemProvider.GetItems("KDA.OrderStatusMapping") .FirstOrDefault(i => i["MicroserviceStatus"].ToString().ToLower() == microserviceStatus.ToLower()); var resourceKey = genericStatusItem?.GetValue("GenericStatus")?.ToString(); return(string.IsNullOrEmpty(resourceKey) ? microserviceStatus : resource.GetResourceString(resourceKey)); }
public CheckTaCResult CheckTaC(LoginRequest request) { if (!login.CheckPasword(request.LoginEmail, request.Password)) { return(CheckTaCResult.GetFailedResult("loginEmail", resources.GetResourceString("Kadena.Logon.LogonFailed"))); } var tacEnabled = resources.GetSettingsKey("KDA_TermsAndConditionsLogin").ToLower() == "true"; var showTaC = false; if (tacEnabled) { var user = kenticoUsers.GetUser(request.LoginEmail); showTaC = !UserHasAcceptedTac(user); } return(new CheckTaCResult { LogonSuccess = true, ShowTaC = showTaC, Url = showTaC ? GetTacPageUrl() : string.Empty }); }
public string GenerateOrder(int openCampaignID, int campaignClosingUserID) { var usersWithShoppingCartItems = shoppingCartProvider.GetUserIDsWithShoppingCart(openCampaignID, 1); var orderTemplateSettingKey = kenticoresourceService.GetSettingsKey("KDA_OrderReservationEmailTemplate"); var failedOrderTemplateSettingKey = kenticoresourceService.GetSettingsKey("KDA_FailedOrdersEmailTemplate"); var failedOrdersUrl = kenticoresourceService.GetSettingsKey("KDA_FailedOrdersPageUrl"); var unprocessedDistributorIDs = new List <Tuple <int, string> >(); usersWithShoppingCartItems.ForEach(shoppingCartUser => { var salesPerson = KenticoUserProvider.GetUserByUserId(shoppingCartUser); var salesPersonrCartIDs = shoppingCartProvider.GetShoppingCartIDByInventoryType(shoppingCartUser, 2, openCampaignID); }); var distributors = kenticoAddressBookService.GetAddressesByAddressIds(unprocessedDistributorIDs.Select(x => x.Item1).ToList()).Select(x => { return(new { AddressID = x?.Id, AddressPersonalName = x?.AddressPersonalName }); }).ToList(); var listofFailedOrders = unprocessedDistributorIDs.Select(x => { var distributor = distributors.Where(y => y.AddressID == x.Item1).FirstOrDefault(); return(new { Name = distributor.AddressPersonalName, Reason = x.Item2 }); }).ToList(); var user = KenticoUserProvider.GetUserByUserId(campaignClosingUserID); if (user?.Email != null && listofFailedOrders.Count > 0) { object[,] orderdata = { { "url", $"{SiteContext.CurrentSite.DomainName}{failedOrdersUrl}?campid={openCampaignID}" }, { "failedordercount", listofFailedOrders.Count } }; UpdatetFailedOrders(openCampaignID, true); } if (listofFailedOrders.Count == 0) { UpdatetFailedOrders(openCampaignID, false); } return(kenticoresourceService.GetResourceString("KDA.OrderSchedular.TaskSuccessfulMessage")); }
public CartEmptyInfo CreateCartEmptyInfo() { return(new CartEmptyInfo { Text = resources.GetResourceString("Kadena.Checkout.CartIsEmpty"), DashboardButtonText = resources.GetResourceString("Kadena.Checkout.ButtonDashboard"), DashboardButtonUrl = documents.GetDocumentUrl(resources.GetSettingsKey("KDA_EmptyCart_DashboardUrl")), ProductsButtonText = resources.GetResourceString("Kadena.Checkout.ButtonProducts"), ProductsButtonUrl = documents.GetDocumentUrl(resources.GetSettingsKey("KDA_EmptyCart_ProductsUrl")) }); }
public SettingsAddresses GetAddresses() { var customer = _kenticoUsers.GetCurrentCustomer(); var billingAddresses = _kenticoUsers.GetCustomerAddresses(AddressType.Billing); var shippingAddresses = _kenticoUsers.GetCustomerAddresses(AddressType.Shipping); var shippingAddressesSorted = shippingAddresses .Where(sa => sa.Id == customer.DefaultShippingAddressId) .Concat(shippingAddresses.Where(sa => sa.Id != customer.DefaultShippingAddressId)) .ToList(); var states = _localization.GetStates(); var countries = _localization.GetCountries(); var canEdit = _permissions.UserCanModifyShippingAddress(); var maxShippingAddressesSetting = _resources.GetSettingsKey("KDA_ShippingAddressMaxLimit"); var userNotification = string.Empty; var userNotificationLocalizationKey = _site.GetCurrentSiteCodeName() + ".Kadena.Settings.Address.NotificationMessage"; if (!_localization.IsCurrentCultureDefault()) { userNotification = _resources.GetResourceString(userNotificationLocalizationKey) == userNotificationLocalizationKey ? string.Empty : _resources.GetResourceString(userNotificationLocalizationKey); } var maxShippingAddresses = 3; if (!string.IsNullOrWhiteSpace(maxShippingAddressesSetting)) { maxShippingAddresses = int.Parse(maxShippingAddressesSetting); } return(new SettingsAddresses { Billing = new object(), ////// TODO Uncomment when billing addresses will be developed ////new Addresses ////{ //// Title = _resources.GetResourceString("Kadena.Settings.Addresses.BillingAddress"), //// AddButton = new //// { //// Exists = false, //// Tooltip = _resources.GetResourceString("Kadena.Settings.Addresses.AddBilling") //// }, //// Addresses = billingAddresses.ToList() ////}, Shipping = new AddressList { Title = _resources.GetResourceString("Kadena.Settings.Addresses.ShippingAddresses"), AllowAddresses = maxShippingAddresses, AddButton = new PageButton { Exists = true, Text = _resources.GetResourceString("Kadena.Settings.Addresses.AddShipping") }, EditButton = new PageButton { Exists = canEdit, Text = _resources.GetResourceString("Kadena.Settings.Addresses.Edit") }, RemoveButton = new PageButton { Exists = false, Text = _resources.GetResourceString("Kadena.Settings.Addresses.Remove") }, DefaultAddress = new DefaultAddress { Id = customer.DefaultShippingAddressId, LabelDefault = _resources.GetResourceString("Kadena.Settings.Addresses.Primary"), LabelNonDefault = _resources.GetResourceString("Kadena.Settings.Addresses.NotPrimary"), Tooltip = _resources.GetResourceString("Kadena.Settings.Addresses.SetUnset"), SetUrl = "api/usersettings/setdefaultshippingaddress", UnsetUrl = "api/usersettings/unsetdefaultshippingaddress" }, Addresses = shippingAddressesSorted }, Dialog = new AddressDialog { UserNotification = userNotification, Types = new DialogType { Add = _resources.GetResourceString("Kadena.Settings.Addresses.AddAddress"), Edit = _resources.GetResourceString("Kadena.Settings.Addresses.EditAddress") }, Buttons = new DialogButton { Discard = _resources.GetResourceString("Kadena.Settings.Addresses.DiscardChanges"), Save = _resources.GetResourceString("Kadena.Settings.Addresses.SaveAddress") }, Fields = new List <DialogField> { new DialogField { Id = "address1", Label = _resources.GetResourceString("Kadena.Settings.Addresses.AddressLine1"), Type = "text" }, new DialogField { Id = "address2", Label = _resources.GetResourceString("Kadena.Settings.Addresses.AddressLine2"), Type = "text", IsOptional = true }, new DialogField { Id = "city", Label = _resources.GetResourceString("Kadena.Settings.Addresses.City"), Type = "text" }, new DialogField { Id = "state", Label = _resources.GetResourceString("Kadena.Settings.Addresses.State"), Type = "select", Values = new List <object>() }, new DialogField { Id = "zip", Label = _resources.GetResourceString("Kadena.Settings.Addresses.Zip"), Type = "text" }, new DialogField { Id = "country", Label = "Country", Values = countries .GroupJoin(states, c => c.Id, s => s.CountryId, (c, sts) => (object)new { Id = c.Id.ToString(), Name = c.Name, Values = sts.Select(s => new { Id = s.Id.ToString(), Name = s.StateDisplayName }).ToArray() }).ToList() } } } }); }
public async Task <OrderHead> GetHeaders() { var orderList = _mapper.Map <OrderList>(await GetOrders(1)); MapOrdersStatusToGeneric(orderList?.Orders); int pages = 0; if (EnablePaging && _pageCapacity > 0) { pages = orderList.TotalCount / _pageCapacity + (orderList.TotalCount % _pageCapacity > 0 ? 1 : 0); } return(new OrderHead { Headings = new List <string> { _kenticoResources.GetResourceString("Kadena.OrdersList.OrderNumber"), _kenticoResources.GetResourceString("Kadena.OrdersList.OrderDate"), _kenticoResources.GetResourceString("Kadena.OrdersList.OrderedItems"), _kenticoResources.GetResourceString("Kadena.OrdersList.OrderStatus"), _kenticoResources.GetResourceString("Kadena.OrdersList.ShippingDate"), string.Empty }, PageInfo = new Pagination { RowsCount = orderList.TotalCount, RowsOnPage = _pageCapacity, PagesCount = pages }, NoOrdersMessage = _kenticoResources.GetResourceString("Kadena.OrdersList.NoOrderItems"), Rows = orderList.Orders.Select(o => { o.ViewBtn = new Button { Text = _kenticoResources.GetResourceString("Kadena.OrdersList.View"), Url = $"{_orderDetailUrl}?orderID={o.Id}" }; return o; }) }); }
public async Task <ProductTemplates> GetTemplatesByProduct(int nodeId) { var productTemplates = new ProductTemplates { Title = _resources.GetResourceString("KADENA.PRODUCT.ManageProducts"), OpenInDesignBtn = _resources.GetResourceString("Kadena.Product.ManageProducts.OpenInDesign"), Header = new [] { new ProductTemplatesHeader { Name = nameof(ProductTemplate.Image).ToCamelCase(), Title = _resources.GetResourceString("KADENA.PRODUCT.IMAGE"), Sorting = SortingType.None }, new ProductTemplatesHeader { Name = nameof(ProductTemplate.ProductName).ToCamelCase(), Title = _resources.GetResourceString("KADENA.PRODUCT.NAME"), Sorting = SortingType.None }, new ProductTemplatesHeader { Name = nameof(ProductTemplate.CreatedDate).ToCamelCase(), Title = _resources.GetResourceString("KADENA.PRODUCT.DATECREATED"), Sorting = SortingType.None }, new ProductTemplatesHeader { Name = nameof(ProductTemplate.UpdatedDate).ToCamelCase(), Title = _resources.GetResourceString("KADENA.PRODUCT.DATEUPDATED"), Sorting = SortingType.Desc }, }, Data = new ProductTemplate[0] }; var product = _products.GetProductByNodeId(nodeId); if (product != null && !product.HasProductTypeFlag(ProductTypes.TemplatedProduct)) { return(productTemplates); } var requestResult = await _templateClient .GetTemplates(_users.GetCurrentUser().UserId, product.ProductChiliTemplateID); var productEditorUrl = _resources.GetSettingsKey("KDA_Templating_ProductEditorUrl")?.TrimStart('~'); if (string.IsNullOrWhiteSpace(productEditorUrl)) { _logger.LogError("GET TEMPLATE LIST", "Product editor URL is not configured"); } else { productEditorUrl = _documents.GetDocumentUrl(productEditorUrl); } Func <DateTime, DateTime, bool> IsNewTemplate = (created, updated) => { var diff = updated - created; var isNew = diff.TotalSeconds < 10; return(isNew); }; if (requestResult.Success) { var defaultQuantity = 1; productTemplates.Data = requestResult.Payload .Where(t => !IsNewTemplate(t.Created, t.Updated ?? t.Created)) .Select(t => { int quantity = defaultQuantity; if (t.MailingList != null) { quantity = t.MailingList.RowCount; } else { if (t.MetaData.quantity != null) { quantity = t.MetaData.quantity.Value; } } return(new ProductTemplate { EditorUrl = BuildTemplateEditorUrl(productEditorUrl, nodeId, t.TemplateId.ToString(), product.ProductChiliWorkgroupID.ToString(), quantity, t.MailingList?.ContainerId, t.Name), TemplateId = t.TemplateId, CreatedDate = t.Created, UpdatedDate = t.Updated, ProductName = t.Name, Image = t.PreviewUrls?.FirstOrDefault() }); }) .OrderByDescending(t => t.UpdatedDate) .ToArray(); } else { _logger.LogError("GET TEMPLATE LIST", requestResult.ErrorMessages); } return(productTemplates); }
public async Task <OrderDetail> GetOrderDetail(string orderId) { CheckOrderDetailPermisson(orderId, kenticoUsers.GetCurrentCustomer()); var microserviceResponse = await orderViewClient.GetOrderByOrderId(orderId); if (!microserviceResponse.Success || microserviceResponse.Payload == null) { kenticoLog.LogError("GetOrderDetail", microserviceResponse.ErrorMessages); throw new Exception("Failed to obtain order detail from microservice"); // TODO refactor using checking null } var data = microserviceResponse.Payload; var genericStatus = kenticoOrder.MapOrderStatus(data.Status); var orderDetail = new OrderDetail() { DateTimeNAString = resources.GetResourceString("Kadena.Order.ItemShippingDateNA"), CommonInfo = new CommonInfo() { OrderDate = new TitleValuePair <DateTime> { Title = resources.GetResourceString("Kadena.Order.OrderDateTitle"), Value = data.OrderDate }, ShippingDate = new TitleValuePair <DateTime?> { Title = resources.GetResourceString("Kadena.Order.ShippingDatePrefix"), Value = data.ShippingInfo?.ShippingDate }, Status = new TitleValuePair <string> { Title = resources.GetResourceString("Kadena.Order.StatusPrefix"), Value = genericStatus }, TotalCost = new TitleValuePair <string> { Title = resources.GetResourceString("Kadena.Order.TotalCostPrefix"), Value = String.Format("$ {0:#,0.00}", data.PaymentInfo.Summary + data.PaymentInfo.Shipping + data.PaymentInfo.Tax) } }, PaymentInfo = new PaymentInfo() { Date = null, // TODO payment date unknown yet PaidBy = data.PaymentInfo.PaymentMethod, PaymentDetail = string.Empty, PaymentIcon = GetPaymentMethodIcon(data.PaymentInfo.PaymentMethod), Title = resources.GetResourceString("Kadena.Order.PaymentSection"), DatePrefix = resources.GetResourceString("Kadena.Order.PaymentDatePrefix"), BUnitLabel = resources.GetResourceString("Kadena.Order.BusinessUnitLabel"), BUnitName = businessUnits.GetDistributorBusinessUnit(data.campaign != null ? data.campaign.DistributorID : 0) }, PricingInfo = new PricingInfo() { Title = resources.GetResourceString("Kadena.Order.PricingSection"), Items = new List <PricingInfoItem>() { new PricingInfoItem() { Title = resources.GetResourceString("Kadena.Order.PricingSummary"), Value = String.Format("$ {0:#,0.00}", data.PaymentInfo.Summary) }, new PricingInfoItem() { Title = resources.GetResourceString("Kadena.Order.PricingShipping"), Value = String.Format("$ {0:#,0.00}", data.PaymentInfo.Shipping) }, new PricingInfoItem() { Title = resources.GetResourceString("Kadena.Order.PricingSubtotal"), Value = String.Format("$ {0:#,0.00}", data.PaymentInfo.Summary + data.PaymentInfo.Shipping) }, new PricingInfoItem() { Title = resources.GetResourceString("Kadena.Order.PricingTax"), Value = String.Format("$ {0:#,0.00}", data.PaymentInfo.Tax) }, new PricingInfoItem() { Title = resources.GetResourceString("Kadena.Order.PricingTotals"), Value = String.Format("$ {0:#,0.00}", data.PaymentInfo.Summary + data.PaymentInfo.Shipping + data.PaymentInfo.Tax) } } }, OrderedItems = new OrderedItems() { Title = resources.GetResourceString("Kadena.Order.OrderedItemsSection"), Items = await MapOrderedItems(data.Items) } }; var mailingTypeCode = OrderItemTypeDTO.Mailing.ToString(); var hasOnlyMailingListProducts = data.Items.All(item => item.Type == mailingTypeCode); if (hasOnlyMailingListProducts) { orderDetail.ShippingInfo = new ShippingInfo { Title = resources.GetResourceString("Kadena.Order.ShippingSection"), Message = resources.GetResourceString("Kadena.Checkout.UndeliverableText") }; } else { orderDetail.ShippingInfo = new ShippingInfo { Title = resources.GetResourceString("Kadena.Order.ShippingSection"), DeliveryMethod = shoppingCart.GetShippingProviderIcon(data.ShippingInfo.Provider), Address = mapper.Map <DeliveryAddress>(data.ShippingInfo.AddressTo), Tracking = null // TODO Track your package url unknown }; orderDetail.ShippingInfo.Address.Country = localization .GetCountries() .FirstOrDefault(s => s.Code.Equals(data.ShippingInfo.AddressTo.isoCountryCode)); } if (!permissions.UserCanSeePrices()) { orderDetail.HidePrices(); } return(orderDetail); }
public CheckoutPage GetCheckoutPage() { var addresses = kenticoUsers.GetCustomerAddresses(AddressType.Shipping); var paymentMethods = shoppingCart.GetPaymentMethods(); var emailConfirmationEnabled = resources.GetSettingsKey("KDA_UseNotificationEmailsOnCheckout") == bool.TrueString; var checkoutPage = new CheckoutPage() { EmptyCart = checkoutfactory.CreateCartEmptyInfo(), Products = GetCartItems(), DeliveryAddresses = GetDeliveryAddresses(), PaymentMethods = checkoutfactory.CreatePaymentMethods(paymentMethods), Submit = checkoutfactory.CreateSubmitButton(), ValidationMessage = resources.GetResourceString("Kadena.Checkout.ValidationError"), EmailConfirmation = checkoutfactory.CreateNotificationEmail(emailConfirmationEnabled) }; CheckCurrentOrDefaultAddress(checkoutPage); checkoutPage.PaymentMethods.CheckDefault(); checkoutPage.PaymentMethods.CheckPayability(); checkoutPage.SetDisplayType(); return(checkoutPage); }