Beispiel #1
0
        public CustomerData GetCustomerData(int siteId, int customerId)
        {
            var customer = kenticoUsers.GetCustomer(customerId);

            if (customer == null)
            {
                return(null);
            }

            var claims = GetCustomerClaims(siteId, customer.UserID);

            var customerData = new CustomerData()
            {
                FirstName         = customer.FirstName,
                LastName          = customer.LastName,
                Email             = customer.Email,
                Phone             = customer.Phone,
                PreferredLanguage = customer.PreferredLanguage,
                Address           = null,
                Claims            = claims,
            };

            var address = kenticoUsers.GetCustomerAddresses(customerId, AddressType.Shipping).FirstOrDefault();

            if (address != null)
            {
                var country = kenticoLocalization.GetCountries().FirstOrDefault(c => c.Id == address.Country.Id);
                var state   = kenticoLocalization.GetStates().FirstOrDefault(s => s.Id == address.State.Id);

                customerData.Address = new CustomerAddress
                {
                    Street = new List <string> {
                        address.Address1, address.Address2
                    },
                    City    = address.City,
                    Country = country.Name,
                    State   = state?.StateDisplayName,
                    Zip     = address.Zip
                };
            }

            return(customerData);
        }
        public Models.Checkout.AddressDialog GetOtherAddressDialog()
        {
            var countries        = kenticoLocalization.GetCountries();
            var states           = kenticoLocalization.GetStates();
            var defaultCountryId = int.Parse(resources.GetSettingsKey("KDA_AddressDefaultCountry"));

            return(new Models.Checkout.AddressDialog
            {
                Title = resources.GetResourceString("Kadena.Checkout.NewAddress"),
                DiscardBtnLabel = resources.GetResourceString("Kadena.Settings.Addresses.DiscardChanges"),
                SubmitBtnLabel = resources.GetResourceString("Kadena.Settings.Addresses.SaveAddress"),
                RequiredErrorMessage = resources.GetResourceString("Kadena.Settings.RequiredField"),
                SaveAddressCheckbox = resources.GetResourceString("Kadena.Checkout.PersistAddressCheckbox"),
                Fields = new[] {
                    new DialogField
                    {
                        Id = "customerName",
                        Label = resources.GetResourceString("Kadena.Settings.CustomerName"),
                        Type = "text"
                    },
                    new DialogField
                    {
                        Id = "address1",
                        Label = resources.GetResourceString("Kadena.Settings.Addresses.AddressLine1"),
                        Type = "text"
                    },
                    new DialogField
                    {
                        Id = "address2",
                        Label = resources.GetResourceString("Kadena.Settings.Addresses.AddressLine2"),
                        IsOptional = true,
                        Type = "text"
                    },
                    new DialogField
                    {
                        Id = "city",
                        Label = resources.GetResourceString("Kadena.Settings.Addresses.City"),
                        Type = "text"
                    },
                    new DialogField
                    {
                        Id = "state",
                        Label = resources.GetResourceString("Kadena.Settings.Addresses.State"),
                        IsOptional = true,
                        Type = "select",
                        Values = new List <object>()
                    },
                    new DialogField
                    {
                        Id = "zip",
                        Label = resources.GetResourceString("Kadena.Settings.Addresses.Zip"),
                        Type = "text"
                    },
                    new DialogField
                    {
                        Id = "country",
                        Label = resources.GetResourceString("Kadena.Settings.Addresses.Country"),
                        Type = "select",
                        Values = countries
                                 .GroupJoin(states, c => c.Id, s => s.CountryId, (c, sts) => (object)new
                        {
                            Id = c.Id.ToString(),
                            Name = c.Name,
                            IsDefault = (c.Id == defaultCountryId),
                            Values = sts.Select(s => new
                            {
                                Id = s.Id.ToString(),
                                Name = s.StateDisplayName
                            }).ToArray()
                        }).ToList()
                    },
                    new DialogField
                    {
                        Id = "phone",
                        Label = resources.GetResourceString("Kadena.ContactForm.Phone"),
                        IsOptional = true,
                        Type = "text"
                    },
                    new DialogField
                    {
                        Id = "email",
                        Label = resources.GetResourceString("Kadena.ContactForm.Email"),
                        Type = "text"
                    }
                }
            });
        }
        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()
                        }
                    }
                }
            });
        }
Beispiel #4
0
        public async Task <OrderDTO> GetSubmitOrderData(SubmitOrderRequest request)
        {
            Customer customer = kenticoUsers.GetCurrentCustomer();

            var notificationEmails = request.EmailConfirmation.Union(new[] { customer.Email });

            if ((request?.DeliveryAddress?.Id ?? 0) < 0)
            {
                shoppingCart.SetShoppingCartAddress(request.DeliveryAddress);
                customer.FirstName = request.DeliveryAddress.CustomerName;
                customer.LastName  = string.Empty;
                customer.Email     = request.DeliveryAddress.Email;
                customer.Phone     = request.DeliveryAddress.Phone;
            }

            var shippingAddress = shoppingCart.GetCurrentCartShippingAddress();

            shippingAddress.Country = localization.GetCountries().FirstOrDefault(c => c.Id == shippingAddress.Country.Id);
            shippingAddress.State   = localization.GetStates().FirstOrDefault(c => c.Id == shippingAddress.State.Id);
            var billingAddress = shoppingCart.GetDefaultBillingAddress();
            var billingState   = localization.GetStates().FirstOrDefault(c => c.Id == billingAddress.StateId);
            var site           = siteProvider.GetKenticoSite();
            var paymentMethod  = shoppingCart.GetPaymentMethod(request.PaymentMethod.Id);
            var cartItems      = shoppingCart.GetShoppingCartItems();
            var currency       = siteProvider.GetSiteCurrency();
            var totals         = shoppingCart.GetShoppingCartTotals();

            totals.TotalTax = await taxService.EstimateTotalTax(shippingAddress);

            if (string.IsNullOrWhiteSpace(customer.Company))
            {
                customer.Company = settings.DefaultCustomerCompanyName;
            }

            foreach (var item in cartItems.Where(i => i.IsTemplated))
            {
                var taskId = await CallRunGeneratePdfTask(item);

                item.DesignFilePathTaskId = taskId;
            }

            var orderDto = new OrderDTO()
            {
                BillingAddress  = orderDataFactory.CreateBillingAddress(billingAddress, billingState?.StateDisplayName),
                ShippingAddress = orderDataFactory.CreateShippingAddress(shippingAddress, customer),
                Customer        = orderDataFactory.CreateCustomer(customer),
                OrderDate       = DateTime.Now,
                PaymentOption   = orderDataFactory.CreatePaymentOption(paymentMethod, request),
                Site            = new SiteDTO()
                {
                    KenticoSiteID   = site.Id,
                    KenticoSiteName = site.Name,
                    ErpCustomerId   = site.ErpCustomerId
                },
                OrderCurrency = new CurrencyDTO()
                {
                    CurrencyCode      = currency.Code,
                    KenticoCurrencyID = currency.Id
                },
                OrderStatus = new OrderStatusDTO()
                {
                    KenticoOrderStatusID = kenticoOrder.GetOrderStatusId("Pending"),
                    OrderStatusName      = "PENDING"
                },
                TotalPrice        = totals.TotalItemsPrice,
                TotalShipping     = totals.TotalShipping,
                TotalTax          = totals.TotalTax,
                Items             = cartItems.Select(item => MapCartItemTypeToOrderItemType(item)),
                NotificationsData = notificationEmails.Select(e => new NotificationInfoDto
                {
                    Email    = e,
                    Language = customer.PreferredLanguage
                })
            };

            // If only mailing list items in cart, we are not picking any delivery option
            if (!cartItems.All(i => i.IsMailingList))
            {
                var deliveryMethod = shoppingCart.GetShippingOption(request.DeliveryMethod);
                orderDto.ShippingOption = new ShippingOptionDTO()
                {
                    KenticoShippingOptionID = deliveryMethod.Id,
                    CarrierCode             = deliveryMethod.SAPName,
                    ShippingCompany         = deliveryMethod.CarrierCode,
                    ShippingService         = deliveryMethod.Service.Replace("#", "")
                };
            }

            return(orderDto);
        }
Beispiel #5
0
        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);
        }