public virtual ActionResult SaveBillingAddress(TBillingAddress model) { if (!this.ModelState.IsValid) { return(this.CurrentUmbracoPage()); } try { // Ensure billing address type is billing if (model.AddressType != AddressType.Billing) { model.AddressType = AddressType.Billing; } var address = BillingAddressFactory.Create(model); // Temporarily save the address in the checkout manager. this.CheckoutManager.Customer.SaveBillToAddress(address); if (!this.CurrentCustomer.IsAnonymous) { this.SaveCustomerBillingAddress(model); } model.WorkflowMarker = GetNextCheckoutWorkflowMarker(CheckoutStage.BillingAddress); return(this.HandleBillingAddressSaveSuccess(model)); } catch (Exception ex) { return(this.HandleBillingAddressSaveException(model, ex)); } }
/// <summary> /// Overrides the action for a successful billing address save. /// </summary> /// <param name="model"> /// The model. /// </param> /// <returns> /// The <see cref="ActionResult"/>. /// </returns> protected override ActionResult HandleBillingAddressSaveSuccess(FastTrackBillingAddressModel model) { string redirectUrl; // If the customer is logged in save the address to their default customer billing address for the next use if (!CurrentCustomer.IsAnonymous) { // In this implementation we are simply overwritting any previously saved addresses // This could can be extended to allow customers to manage multiple addresses of a given // type in other implementations. var customer = (ICustomer)CurrentCustomer; var existing = customer.DefaultCustomerAddress(AddressType.Billing); var caddress = BillingAddressFactory.Create(model, (ICustomer)CurrentCustomer, "Billing Address", AddressType.Billing); if (existing != null) { caddress.CreateDate = existing.CreateDate; caddress.Key = existing.Key; } ((ICustomer)CurrentCustomer).SaveCustomerAddress(caddress); } // NOTE: We need to do a special check here to assert that the country code is valid as it // billing addresses by default can be associated any where in the world, whereas shiping // destinations are usually constrained to specific locations. Some implementations may // opt to swap the order of the address collection to alleviate the need for this check, but // there are also cases, where items may not need to be shipped and the billing address is required // to create the invoice. if (model.UseForShipping && EnsureBillingAddressIsValidAsShippingAddress(model)) { // we use the billing address factory here since we know the model FastTrackBillingAddressModel // and only want Merchello's IAddress var address = BillingAddressFactory.Create(model); CheckoutManager.Customer.SaveShipToAddress(address); // In this implementation, we cannot save the customer shipping address to the customer as it may be a different model here // However, it is possible but more work would be required to ensure the model mapping // set the checkout stage model.WorkflowMarker = GetNextCheckoutWorkflowMarker(CheckoutStage.ShippingAddress); redirectUrl = model.SuccessUrlShipRateQuote; } else { redirectUrl = model.SuccessRedirectUrl; } return(!redirectUrl.IsNullOrWhiteSpace() ? this.Redirect(redirectUrl) : base.HandleBillingAddressSaveSuccess(model)); }
public ActionResult BillingAddressForm(string view = "") { TBillingAddress model = null; // Determine if we already have an address saved in the checkout manager var address = CheckoutManager.Customer.GetBillToAddress(); if (address != null) { model = BillingAddressFactory.Create(address); } else { // If not and the we have the configuration set to use the customer's default customer billing address // This can only be done if the customer is logged in. e.g. Not an anonymous customer if (!this.CurrentCustomer.IsAnonymous && this._useCustomerAddress) { var defaultBilling = ((ICustomer)this.CurrentCustomer).DefaultCustomerAddress(AddressType.Billing); if (defaultBilling != null) { model = BillingAddressFactory.Create((ICustomer)CurrentCustomer, defaultBilling); } } } // If the model is still null at this point, we need to generate a default model // for the country drop down list if (model == null) { model = BillingAddressFactory.Create(new Address()); } return(view.IsNullOrWhiteSpace() ? this.PartialView(model) : this.PartialView(view, model)); }