/// <summary> /// Converts the billing address into an order address and saves it. If any changes to the address should be saved for future usage /// then the address will also be converted as a customer addresses and gets related to the current contact. /// </summary> /// <param name="checkoutViewModel">The view model representing the purchase order.</param> private void SaveBillingAddress(CheckoutViewModel checkoutViewModel) { if (!_addressBookService.CanSave(checkoutViewModel.BillingAddress)) { return; } var orderAddress = _checkoutService.AddNewOrderAddress(); _addressBookService.MapModelToOrderAddress(checkoutViewModel.BillingAddress, orderAddress); orderAddress.Name = Guid.NewGuid().ToString(); orderAddress.AcceptChanges(); _checkoutService.UpdateBillingAddressId(orderAddress.Name); if (checkoutViewModel.BillingAddress.SaveAddress && User.Identity.IsAuthenticated) { var currentContact = _customerContext.CurrentContact.CurrentContact; var customerAddress = currentContact.ContactAddresses.FirstOrDefault(x => x.AddressId == checkoutViewModel.BillingAddress.AddressId) ?? CustomerAddress.CreateInstance(); _addressBookService.MapModelToCustomerAddress(checkoutViewModel.BillingAddress, customerAddress); if (checkoutViewModel.BillingAddress.AddressId == null) { currentContact.AddContactAddress(customerAddress); } else { BusinessManager.Update(customerAddress); } currentContact.SaveChanges(); } }
public MultiShipmentViewModelFactoryTests() { var market = new MarketImpl(new MarketId(Currency.USD)); _cart = new FakeCart(market, Currency.USD); _cart.Forms.Single().Shipments.Single().LineItems.Add(new InMemoryLineItem()); _cart.Forms.Single().CouponCodes.Add("couponcode"); var addressBookServiceMock = new Mock <IAddressBookService>(); addressBookServiceMock.Setup(x => x.List()).Returns(() => new List <AddressModel> { new AddressModel { AddressId = "addressid" } }); var preferredBillingAddress = CustomerAddress.CreateInstance(); preferredBillingAddress.Name = "preferredBillingAddress"; addressBookServiceMock.Setup(x => x.GetPreferredBillingAddress()).Returns(preferredBillingAddress); addressBookServiceMock.Setup(x => x.UseBillingAddressForShipment()).Returns(true); _startPage = new StartPage(); var contentLoaderMock = new Mock <IContentLoader>(); contentLoaderMock.Setup(x => x.Get <StartPage>(It.IsAny <PageReference>())).Returns(_startPage); var urlResolverMock = new Mock <UrlResolver>(); var httpcontextMock = new Mock <HttpContextBase>(); var requestMock = new Mock <HttpRequestBase>(); requestMock.Setup(x => x.Url).Returns(new Uri("http://site.com")); requestMock.Setup(x => x.UrlReferrer).Returns(new Uri("http://site.com")); httpcontextMock.Setup(x => x.Request).Returns(requestMock.Object); var marketServiceMock = new Mock <IMarketService>(); marketServiceMock.Setup(x => x.GetMarket(It.IsAny <MarketId>())).Returns(market); var shipmentViewModelFactoryMock = new Mock <ShipmentViewModelFactory>(null, null, null, null, null, marketServiceMock.Object); shipmentViewModelFactoryMock.Setup(x => x.CreateShipmentsViewModel(It.IsAny <ICart>())).Returns(() => new[] { new ShipmentViewModel { CartItems = new[] { new CartItemViewModel { Quantity = 1 } } } }); _subject = new MultiShipmentViewModelFactory( new MemoryLocalizationService(), addressBookServiceMock.Object, contentLoaderMock.Object, urlResolverMock.Object, (() => httpcontextMock.Object), shipmentViewModelFactoryMock.Object); }
private FoundationAddress CreateAddress() { var address = new FoundationAddress(CustomerAddress.CreateInstance()); address.AddressId = BusinessManager.Create(address.Address); return(address); }
private CustomerAddress CreateVippsAddress(VippsAddressType addressType) { var vippsAddress = CustomerAddress.CreateInstance(); vippsAddress.SetVippsAddressType(addressType); return(vippsAddress); }
private CustomerAddress CreateOrUpdateCustomerAddress(CustomerContact contact, AddressModel addressModel) { var customerAddress = GetAddress(contact, addressModel.AddressId); var isNew = customerAddress == null; IEnumerable <PrimaryKeyId> existingId = contact.ContactAddresses.Select(a => a.AddressId).ToList(); if (isNew) { customerAddress = CustomerAddress.CreateInstance(); } MapToAddress(addressModel, customerAddress); if (isNew) { contact.AddContactAddress(customerAddress); } else { contact.UpdateContactAddress(customerAddress); } contact.SaveChanges(); if (isNew) { customerAddress.AddressId = contact.ContactAddresses .Where(a => !existingId.Contains(a.AddressId)) .Select(a => a.AddressId) .Single(); addressModel.AddressId = customerAddress.Name; } return(customerAddress); }
public void MapVippsAddress() { var mapper = new VippsLoginMapper(); var customerAddress = CustomerAddress.CreateInstance(); var vippsAddressType = VippsAddressType.Work; var vippsStreetAddress = "Vipps Street Address"; var region = "Oslo"; var country = "NO"; var postalCode = "0151"; mapper.MapVippsAddressFields(customerAddress, new VippsAddress { AddressType = vippsAddressType, StreetAddress = vippsStreetAddress, Region = region, Country = country, PostalCode = postalCode }); Assert.Equal(vippsAddressType, customerAddress.GetVippsAddressType()); Assert.Equal(vippsStreetAddress, customerAddress.Line1); Assert.Equal(region, customerAddress.City); Assert.Equal("NOR", customerAddress.CountryCode); Assert.Equal(postalCode, customerAddress.PostalCode); }
public void AddressTypeNullIfSetToNull() { var customerAddress = CustomerAddress.CreateInstance(); customerAddress.SetVippsAddressType(null); Assert.Null(customerAddress.GetVippsAddressType()); }
public void FindsOneAddressIfOneVippsAddressAndOthers() { var customerAddress = new[] { CustomerAddress.CreateInstance(), CreateVippsAddress(VippsAddressType.Work), CustomerAddress.CreateInstance() }; var result = customerAddress.FindAllVippsAddresses(); Assert.Equal(1, result.Count()); }
public void FindsNoAddressIfNoVippsAddress() { var customerAddress = new[] { CustomerAddress.CreateInstance() }; var result = customerAddress.FindAllVippsAddresses(); Assert.Empty(result); }
public void AddressTypeHomeIfSetToHome() { var customerAddress = CustomerAddress.CreateInstance(); customerAddress.SetVippsAddressType(VippsAddressType.Home); Assert.Equal(VippsAddressType.Home, customerAddress.GetVippsAddressType()); }
public void AddressTypeNullIfSetToUnknownString() { var customerAddress = CustomerAddress.CreateInstance(); customerAddress[MetadataConstants.VippsAddressTypeFieldName] = "unknown"; Assert.Null(customerAddress.GetVippsAddressType()); }
public void MapVippsAddressFieldsThrowsIfVippsInfoIsNull() { var mapper = new VippsLoginMapper(); var customerAddress = CustomerAddress.CreateInstance(); Assert.Throws <ArgumentNullException>(() => mapper.MapVippsAddressFields(customerAddress, null)); }
public async Task <ActionResult> RegisterAccount(RegisterAccountViewModel viewModel) { if (viewModel.CurrentPage == null) { viewModel.CurrentPage = ContentReference.IsNullOrEmpty(StartPage.LoginRegistrationPage) ? new LoginRegistrationPage() : _contentLoader.Get <LoginRegistrationPage>(StartPage.LoginRegistrationPage); } if (!ModelState.IsValid) { _addressBookService.LoadAddress(viewModel.Address); return(View(viewModel)); } viewModel.Address.BillingDefault = true; viewModel.Address.ShippingDefault = true; viewModel.Address.Email = viewModel.Email; var customerAddress = CustomerAddress.CreateInstance(); _addressBookService.MapToAddress(viewModel.Address, customerAddress); var user = new SiteUser { UserName = viewModel.Email, Email = viewModel.Email, Password = viewModel.Password, FirstName = viewModel.Address.FirstName, LastName = viewModel.Address.LastName, RegistrationSource = "Registration page", AcceptMarketingEmail = viewModel.AcceptMarketingEmail, Addresses = new List <CustomerAddress>(new[] { customerAddress }), IsApproved = true }; var registration = await UserService.RegisterAccount(user); if (registration.Result.Succeeded) { if (user.AcceptMarketingEmail) { var token = await _optinService.CreateOptinTokenData(user.Id); SendMarketingEmailConfirmationMail(user.Id, registration.Contact, token); } var returnUrl = GetSafeReturnUrl(Request.UrlReferrer); return(Json(new { ReturnUrl = returnUrl }, JsonRequestBehavior.DenyGet)); } _addressBookService.LoadAddress(viewModel.Address); AddErrors(registration.Result.Errors); return(PartialView("RegisterAccount", viewModel)); }
public static CustomerAddress CreateCustomerAddress(UserAddressModel addressModel, Guid userGuid) { var customerAddress = CustomerAddress.CreateInstance(); UpdateContactAddressData(customerAddress, addressModel); customerAddress.ContactId = new PrimaryKeyId(userGuid); customerAddress.AddressId = new PrimaryKeyId(Guid.NewGuid()); return(customerAddress); }
private IOrderAddress AddAddressToOrder(ICart cart) { IOrderAddress shippingAddress = null; if (CustomerContext.Current.CurrentContact == null) { IShipment shipment = cart.GetFirstShipment(); if (shipment.ShippingAddress != null) { //using the cart.GetFirstShipment() seems only useful if we are checking for an existing address, otherwise //the solution code's recommended 'new school' approach doesn't use it. } IOrderAddress myOrderAddress = _orderGroupFactory.CreateOrderAddress(cart); myOrderAddress.CountryName = "United States"; myOrderAddress.Id = "HomersShippingAddress"; myOrderAddress.Email = "*****@*****.**"; shippingAddress = myOrderAddress; } else { //User is logged in if (CustomerContext.Current.CurrentContact.PreferredShippingAddress == null) { CustomerAddress newCustAddress = CustomerAddress.CreateInstance(); newCustAddress.AddressType = CustomerAddressTypeEnum.Shipping | CustomerAddressTypeEnum.Public; //mandatory newCustAddress.ContactId = CustomerContext.Current.CurrentContact.PrimaryKeyId; newCustAddress.CountryCode = "USA"; newCustAddress.CountryName = "United States"; newCustAddress.Name = "Wilbur's customer address"; // mandatory newCustAddress.DaytimePhoneNumber = "9008675309"; newCustAddress.FirstName = CustomerContext.Current.CurrentContact.FirstName; newCustAddress.LastName = CustomerContext.Current.CurrentContact.LastName; newCustAddress.Email = "*****@*****.**"; // note: Line1 & City is what is shown in CM at a few places... not the Name CustomerContext.Current.CurrentContact.AddContactAddress(newCustAddress); CustomerContext.Current.CurrentContact.SaveChanges(); // ... needs to be in this order CustomerContext.Current.CurrentContact.PreferredShippingAddress = newCustAddress; CustomerContext.Current.CurrentContact.SaveChanges(); // need this ...again // then, for the cart //.Cart.OrderAddresses.Add(new OrderAddress(newCustAddress)); - OLD shippingAddress = new OrderAddress(newCustAddress); // - NEW } else { shippingAddress = new OrderAddress(CustomerContext.Current.CurrentContact.PreferredShippingAddress); } } return(shippingAddress); }
public void FindsWorkAddressIfWorkVippsAddressAndOthers() { var vippsAddress = CreateVippsAddress(VippsAddressType.Work); var customerAddress = new[] { CustomerAddress.CreateInstance(), CreateVippsAddress(VippsAddressType.Home), vippsAddress, CreateVippsAddress(VippsAddressType.Other), CustomerAddress.CreateInstance() }; var result = customerAddress.FindVippsAddress(VippsAddressType.Work); Assert.Equal(vippsAddress, result); }
public void Setup() { _address1 = CustomerAddress.CreateInstance(); _address1.AddressId = new PrimaryKeyId(Guid.NewGuid()); _address1.Name = _address1.AddressId.ToString(); _address2 = CustomerAddress.CreateInstance(); _address2.AddressId = new PrimaryKeyId(Guid.NewGuid()); _address2.Name = _address2.AddressId.ToString(); _currentContact = new FakeCurrentContact(new[] { _address1, _address2 }); var customerContext = new FakeCustomerContext(_currentContact); var countryManager = new FakeCountryManager(); _subject = new AddressBookService(customerContext, countryManager); }
public async Task <ActionResult> RegisterAccount(RegisterAccountViewModel viewModel) { if (!ModelState.IsValid) { _addressBookService.LoadAddress(viewModel.Address); return(View(viewModel)); } ContactIdentityResult registration = null; viewModel.Address.BillingDefault = true; viewModel.Address.ShippingDefault = true; viewModel.Address.Email = viewModel.Email; var customerAddress = CustomerAddress.CreateInstance(); _addressBookService.MapToAddress(viewModel.Address, customerAddress); var user = new SiteUser { UserName = viewModel.Email, Email = viewModel.Email, Password = viewModel.Password, FirstName = viewModel.Address.FirstName, LastName = viewModel.Address.LastName, RegistrationSource = "Registration page", NewsLetter = viewModel.Newsletter, Addresses = new List <CustomerAddress>(new[] { customerAddress }), IsApproved = true }; registration = await UserService.RegisterAccount(user); if (registration.Result.Succeeded) { var returnUrl = GetSafeReturnUrl(Request.UrlReferrer); return(Json(new { ReturnUrl = returnUrl }, JsonRequestBehavior.DenyGet)); } _addressBookService.LoadAddress(viewModel.Address); AddErrors(registration.Result.Errors); return(PartialView("RegisterAccount", viewModel)); }
public static void CreateContact(CustomerContact customerContact, Guid userId, ContactModelExtended contactModel) { customerContact.PrimaryKeyId = new PrimaryKeyId(userId); customerContact.FirstName = contactModel.FirstName; customerContact.LastName = contactModel.LastName; customerContact.Email = contactModel.Email; customerContact.UserId = "String:" + contactModel .Email; // The UserId needs to be set in the format "String:{email}". Else a duplicate CustomerContact will be created later on. customerContact.RegistrationSource = contactModel.RegistrationSource; if (contactModel.Addresses != null) { foreach (var address in contactModel.Addresses) { customerContact.AddContactAddress( address.ConvertToCustomerAddress(CustomerAddress.CreateInstance())); } } UpdateMetaFields(customerContact, contactModel, new List <string> { "FirstName", "LastName", "Email", "RegistrationSource" }); // The contact, or more likely its related addresses, must be saved to the database before we can set the preferred // shipping and billing addresses. Using an address id before its saved will throw an exception because its value // will still be null. customerContact.SaveChanges(); // Once the contact has been saved we can look for any existing addresses. var defaultAddress = customerContact.ContactAddresses.FirstOrDefault(); if (defaultAddress != null) { // If an addresses was found, it will be used as default for shipping and billing. customerContact.PreferredShippingAddress = defaultAddress; customerContact.PreferredBillingAddress = defaultAddress; // Save the address preferences also. customerContact.SaveChanges(); } }
public static CustomerAddress ToCustomerAddress(this Address address) { var customerAddress = CustomerAddress.CreateInstance(); customerAddress.Line1 = address.AddressLine1; customerAddress.Line2 = address.AddressLine2; customerAddress.City = address.City; customerAddress.CountryCode = address.CountryCode; customerAddress.CountryName = address.CountryName; customerAddress.Email = address.Email; customerAddress.DaytimePhoneNumber = address.Phone1; customerAddress.EveningPhoneNumber = address.Phone2; customerAddress.PostalCode = address.PostCode; customerAddress.State = address.State; customerAddress.FirstName = address.FirstName; customerAddress.LastName = address.LastName; customerAddress.Name = $"{address.FirstName} {address.LastName}"; return(customerAddress); }
public virtual void MapAddress( CustomerContact currentContact, CustomerAddressTypeEnum addressType, VippsAddress vippsAddress, string phoneNumber) { if (currentContact == null) { throw new ArgumentNullException(nameof(currentContact)); } if (vippsAddress == null) { throw new ArgumentNullException(nameof(vippsAddress)); } // Vipps addresses don't have an ID // They can be identified by Vipps address type var address = currentContact.ContactAddresses.FindVippsAddress(vippsAddress.AddressType); var isNewAddress = address == null; if (isNewAddress) { address = CustomerAddress.CreateInstance(); address.AddressType = addressType; } // Maps fields onto customer address: // Vipps address type, street, city, postalcode, countrycode MapVippsAddressFields(address, vippsAddress); if (!string.IsNullOrWhiteSpace(phoneNumber)) { address.DaytimePhoneNumber = address.EveningPhoneNumber = phoneNumber; } if (isNewAddress) { currentContact.AddContactAddress(address); } else { currentContact.UpdateContactAddress(address); } }
private static void MapAddressesFromCustomerToContact(CustomerPoco customer, CustomerContact contact) { foreach (var importedAddress in customer.Addresses) { var address = CustomerAddress.CreateInstance(); address.Name = importedAddress.Name; address.City = importedAddress.City; address.CountryCode = importedAddress.CountryCode; address.CountryName = importedAddress.CountryName; address.FirstName = customer.FirstName; address.LastName = customer.LastName; address.Line1 = importedAddress.Line1; address.RegionCode = importedAddress.RegionCode; address.RegionName = importedAddress.RegionName; address.AddressType = CustomerAddressTypeEnum.Public | CustomerAddressTypeEnum.Shipping | CustomerAddressTypeEnum.Billing; contact.AddContactAddress(address); } }
public AddressBookServiceTests() { _address1 = CustomerAddress.CreateInstance(); _address1.AddressId = new PrimaryKeyId(new Guid(_address1Id)); _address1.Name = _address1.AddressId.ToString(); var address2 = CustomerAddress.CreateInstance(); address2.AddressId = new PrimaryKeyId(new Guid(_address2Id)); address2.Name = address2.AddressId.ToString(); _currentContact = new FakeCurrentContact(new[] { _address1, address2 }) { PreferredBillingAddress = _address1, PreferredShippingAddress = _address1 }; var customerContext = new FakeCustomerContext(_currentContact); var countryManager = new FakeCountryManager(); _subject = new AddressBookService(customerContext, countryManager, new Mock <IOrderFactory>().Object); }
private CustomerAddress CreateCustomerAddress(IOrderAddress orderAddress, CustomerAddressTypeEnum addressType) { var address = CustomerAddress.CreateInstance(); address.Name = orderAddress.Id; address.AddressType = addressType; address.PostalCode = orderAddress.PostalCode; address.City = orderAddress.City; address.CountryCode = orderAddress.CountryCode; address.CountryName = orderAddress.CountryName; address.State = orderAddress.RegionName; address.Email = orderAddress.Email; address.FirstName = orderAddress.FirstName; address.LastName = orderAddress.LastName; address.Line1 = orderAddress.Line1; address.Line2 = orderAddress.Line2; address.DaytimePhoneNumber = orderAddress.DaytimePhoneNumber; address.EveningPhoneNumber = orderAddress.EveningPhoneNumber; address.RegionCode = orderAddress.RegionCode; address.RegionName = orderAddress.RegionName; return(address); }
/// <summary> /// Converts and saves all shipping addresses for a purchase into order addresses. If one or more addresses should be saved for future usage /// then they are also stored as customer addresses and gets related to the current contact. /// </summary> /// <param name="checkoutViewModel">The view model representing the purchase order.</param> private void SaveShippingAddresses(CheckoutViewModel checkoutViewModel) { foreach (ShippingAddress shippingAddress in checkoutViewModel.ShippingAddresses ?? Enumerable.Empty <ShippingAddress>()) { if (!_addressBookService.CanSave(shippingAddress)) { continue; } var orderAddress = _checkoutService.AddNewOrderAddress(); _addressBookService.MapModelToOrderAddress(shippingAddress, orderAddress); orderAddress.Name = Guid.NewGuid().ToString(); orderAddress.AcceptChanges(); if (shippingAddress.SaveAddress && User.Identity.IsAuthenticated) { var currentContact = _customerContext.CurrentContact.CurrentContact; var customerAddress = currentContact.ContactAddresses.FirstOrDefault(x => x.AddressId == shippingAddress.AddressId) ?? CustomerAddress.CreateInstance(); _addressBookService.MapModelToCustomerAddress(shippingAddress, customerAddress); if (shippingAddress.AddressId == null) { currentContact.AddContactAddress(customerAddress); } else { BusinessManager.Update(customerAddress); } currentContact.SaveChanges(); } var shipment = _checkoutService.CreateShipment(); shipment.ShippingAddressId = orderAddress.Name; var shippingRate = _checkoutService.GetShippingRate(shipment, shippingAddress.ShippingMethodId); _checkoutService.UpdateShipment(shipment, shippingRate); } }
/// <summary> /// Returns a new instance of an ApplicationUser based on a previously made purchase order. /// </summary> /// <param name="purchaseOrder"></param> public ApplicationUser(PurchaseOrder purchaseOrder) { Addresses = new List <CustomerAddress>(); var firstAddress = purchaseOrder.OrderAddresses.FirstOrDefault(); if (firstAddress != null) { Email = firstAddress.Email; UserName = firstAddress.Email; FirstName = firstAddress.FirstName; LastName = firstAddress.LastName; } foreach (OrderAddress orderAddress in purchaseOrder.OrderAddresses) { CustomerAddress address = CustomerAddress.CreateInstance(); address.AddressType = CustomerAddressTypeEnum.Shipping; address.PostalCode = orderAddress.PostalCode; address.City = orderAddress.City; address.CountryCode = orderAddress.CountryCode; address.CountryName = orderAddress.CountryName; address.State = orderAddress.State; address.Email = orderAddress.Email; address.FirstName = orderAddress.FirstName; address.LastName = orderAddress.LastName; address.Created = orderAddress.Created; address.Line1 = orderAddress.Line1; address.Line2 = orderAddress.Line2; address.DaytimePhoneNumber = orderAddress.DaytimePhoneNumber; address.EveningPhoneNumber = orderAddress.EveningPhoneNumber; address.Name = orderAddress.Name; address.RegionCode = orderAddress.RegionCode; address.RegionName = orderAddress.RegionName; Addresses.Add(address); } }
/// <summary> /// Creates a <see cref="CustomerAddress"/> for each existing address in <paramref name="customer"/> and adds it to <paramref name="contact"/>. /// </summary> /// <param name="customer">The <see cref="CustomerTemplate"/> holding the details about the addresses to be created.</param> /// <param name="contact">The <see cref="CustomerContact"/> that will be given any created address.</param> private static void MapAddressesFromCustomerToContact(CustomerTemplate customer, CustomerContact contact) { foreach (var importedAddress in customer.Addresses) { var address = CustomerAddress.CreateInstance(); address.Name = "Default address"; address.PrimaryKeyId = new PrimaryKeyId(importedAddress.AddressId); address.City = importedAddress.City; address.CountryCode = importedAddress.CountryCode; address.CountryName = importedAddress.CountryName; address.FirstName = customer.FirstName; address.LastName = customer.LastName; address.Line1 = importedAddress.Line1; address.RegionCode = importedAddress.RegionCode; address.RegionName = importedAddress.RegionName; address.State = importedAddress.State; address.AddressType = CustomerAddressTypeEnum.Public | CustomerAddressTypeEnum.Shipping | CustomerAddressTypeEnum.Billing; address.Email = customer.Email; contact.AddContactAddress(address); } }
private IOrderAddress AddAddressToOrder(ICart cart) { IOrderAddress shippingAddress; if (CustomerContext.Current.CurrentContact == null) // anonymous { // Anonymous... one way of "doing it"... for example, if no other address exist var shipment = cart.GetFirstShipment(); // ... moved to shipment - prev. = .OrderAddresses.Add( if (shipment.ShippingAddress != null) { //return false/true; // Should we clean upfirst? } // New School IOrderAddress myOrderAddress = _orderGroupFactory.CreateOrderAddress(cart); myOrderAddress.CountryName = "Sweden"; myOrderAddress.Id = "MyNewAddress"; myOrderAddress.Email = "*****@*****.**"; // temp-fix this shippingAddress = myOrderAddress; // OldSchool //shippingAddress = shipment.ShippingAddress = // // new OrderAddress // { // CountryCode = "USA", // CountryName = "United States", // Name = "SomeCustomerAddressName", // DaytimePhoneNumber = "123456", // FirstName = "John", // LastName = "Smith", // Email = "*****@*****.**", // }; } // end anonymous else { // Logged in if (CustomerContext.Current.CurrentContact.PreferredShippingAddress == null) { // no pref. address set... so we set one for the contact CustomerAddress newCustAddress = CustomerAddress.CreateInstance(); newCustAddress.AddressType = CustomerAddressTypeEnum.Shipping | CustomerAddressTypeEnum.Public; // mandatory newCustAddress.ContactId = CustomerContext.Current.CurrentContact.PrimaryKeyId; newCustAddress.CountryCode = "SWE"; newCustAddress.CountryName = "Sweden"; newCustAddress.Name = "new customer address"; // mandatory newCustAddress.DaytimePhoneNumber = "123456"; newCustAddress.FirstName = CustomerContext.Current.CurrentContact.FirstName; newCustAddress.LastName = CustomerContext.Current.CurrentContact.LastName; newCustAddress.Email = "*****@*****.**"; // note: Line1 & City is what is shown in CM at a few places... not the Name CustomerContext.Current.CurrentContact.AddContactAddress(newCustAddress); CustomerContext.Current.CurrentContact.SaveChanges(); // ... needs to be in this order CustomerContext.Current.CurrentContact.PreferredShippingAddress = newCustAddress; CustomerContext.Current.CurrentContact.SaveChanges(); // need this ...again // then, for the cart //.Cart.OrderAddresses.Add(new OrderAddress(newCustAddress)); - OLD shippingAddress = new OrderAddress(newCustAddress); // - NEW } else { // ...a 3:rd vay, there is a preferred address set shippingAddress = new OrderAddress( CustomerContext.Current.CurrentContact.PreferredShippingAddress); } } return(shippingAddress); }
public CheckoutViewModelFactoryTests() { _cart = new FakeCart(new MarketImpl(new MarketId(Currency.USD)), Currency.USD); _cart.Forms.Single().Shipments.Single().LineItems.Add(new InMemoryLineItem()); _cart.Forms.Single().CouponCodes.Add("couponcode"); var paymentServiceMock = new Mock <IPaymentService>(); paymentServiceMock.Setup(x => x.GetPaymentMethodsByMarketIdAndLanguageCode(It.IsAny <string>(), "en")).Returns( new[] { new PaymentMethodViewModel() { PaymentMethodId = Guid.NewGuid(), Description = "Lorem ipsum", FriendlyName = "payment method 1", SystemKeyword = cashPaymentName }, new PaymentMethodViewModel() { PaymentMethodId = Guid.NewGuid(), Description = "Lorem ipsum", FriendlyName = "payment method 2", SystemKeyword = creditPaymentName, IsDefault = true } }); var marketMock = new Mock <IMarket>(); var currentMarketMock = new Mock <ICurrentMarket>(); var languageServiceMock = new Mock <LanguageService>(null, null, null); currentMarketMock.Setup(x => x.GetCurrentMarket()).Returns(marketMock.Object); languageServiceMock.Setup(x => x.GetCurrentLanguage()).Returns(new CultureInfo("en-US")); var cashOnDeliveryPaymentOption = new CashOnDeliveryPaymentOption(null, null, currentMarketMock.Object, languageServiceMock.Object, paymentServiceMock.Object); var creaditPaymentOption = new GenericCreditCardPaymentOption(null, null, currentMarketMock.Object, languageServiceMock.Object, paymentServiceMock.Object); var paymentOptions = new List <IPaymentOption>(); paymentOptions.Add(cashOnDeliveryPaymentOption as IPaymentOption); paymentOptions.Add(creaditPaymentOption as IPaymentOption); _creditPayment = creaditPaymentOption; var paymentMethodViewModelFactory = new PaymentMethodViewModelFactory(currentMarketMock.Object, languageServiceMock.Object, paymentServiceMock.Object, paymentOptions); var orderGroupFactoryMock = new Mock <IOrderGroupFactory>(); orderGroupFactoryMock.Setup(x => x.CreatePayment(It.IsAny <IOrderGroup>())).Returns((IOrderGroup orderGroup) => new FakePayment()); var serviceLocatorMock = new Mock <IServiceLocator>(); serviceLocatorMock.Setup(x => x.GetInstance <IOrderGroupFactory>()).Returns(orderGroupFactoryMock.Object); ServiceLocator.SetLocator(serviceLocatorMock.Object); _addressBookServiceMock = new Mock <IAddressBookService>(); _addressBookServiceMock.Setup(x => x.List()).Returns(() => new List <AddressModel> { new AddressModel { AddressId = "addressid" } }); _preferredBillingAddress = CustomerAddress.CreateInstance(); _preferredBillingAddress.Name = "preferredBillingAddress"; _addressBookServiceMock.Setup(x => x.GetPreferredBillingAddress()).Returns(_preferredBillingAddress); _addressBookServiceMock.Setup(x => x.UseBillingAddressForShipment()).Returns(true); _startPage = new StartPage(); var contentLoaderMock = new Mock <IContentLoader>(); contentLoaderMock.Setup(x => x.Get <StartPage>(It.IsAny <PageReference>())).Returns(_startPage); var urlResolverMock = new Mock <UrlResolver>(); var httpcontextMock = new Mock <HttpContextBase>(); var requestMock = new Mock <HttpRequestBase>(); requestMock.Setup(x => x.Url).Returns(new Uri("http://site.com")); requestMock.Setup(x => x.UrlReferrer).Returns(new Uri("http://site.com")); httpcontextMock.Setup(x => x.Request).Returns(requestMock.Object); var shipmentViewModelFactoryMock = new Mock <ShipmentViewModelFactory>(null, null, null, null, null); shipmentViewModelFactoryMock.Setup(x => x.CreateShipmentsViewModel(It.IsAny <ICart>())).Returns(() => new[] { new ShipmentViewModel { CartItems = new[] { new CartItemViewModel { Quantity = 1 } } } }); _subject = new CheckoutViewModelFactory( new MemoryLocalizationService(), (() => paymentMethodViewModelFactory), _addressBookServiceMock.Object, contentLoaderMock.Object, urlResolverMock.Object, (() => httpcontextMock.Object), shipmentViewModelFactoryMock.Object); }
private void SaveToAddressBookIfNeccessary(ShippingAddress address) { if (address.SaveAddress && User.Identity.IsAuthenticated && _addressBookService.CanSave(address)) { var currentContact = _customerContext.CurrentContact.CurrentContact; var customerAddress = currentContact.ContactAddresses.FirstOrDefault(x => x.AddressId == address.AddressId) ?? CustomerAddress.CreateInstance(); _addressBookService.MapModelToCustomerAddress(address, customerAddress); if (address.AddressId == null) { currentContact.AddContactAddress(customerAddress); } else { BusinessManager.Update(customerAddress); } currentContact.SaveChanges(); } }