/// <summary>
        /// Handles the SelectedIndexChanged event of the AddressesList control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        protected void AddressesList_SelectedIndexChanged(Object sender, EventArgs e)
        {
            CustomerProfile ci = ProfileContext.Current.Profile;

            int selectedAddress = Int32.Parse(AddressesList.SelectedValue);

            foreach (CustomerAddress addr in ci.Account.Addresses)
            {
                if (addr.AddressId == selectedAddress)
                {
                    AddressViewModule.AddressInfo = StoreHelper.ConvertToOrderAddress(addr);
                    AddressViewModule.DataBind();

                    //upAddresses.Update();
                    break;
                }
            }
        }
Exemple #2
0
        protected void SaveShippingAddress()
        {
            if (this.UserIsLevelA)
            {
                //TODO: Save level A address
                //this.ShippingAddress =  CheckoutCartHelper.FindAddressById(this.ddlLevelAShippingAddress.SelectedValue);

                foreach (CustomerAddress address in this.UserOrganization.Addresses)
                {
                    if (address.Name == ddlLevelAShippingAddress.SelectedValue)
                    {
                        //convert the selected address into an OrderAddress, including custom meta data.
                        OrderAddress shippingAddress = StoreHelper.ConvertToOrderAddress(address);
                        shippingAddress["TaxRate"]          = address["TaxRate"];
                        shippingAddress["IsFreightTaxable"] = address["IsFreightTaxable"];
                        shippingAddress["SBOAddressId"]     = address["SBOAddressId"];

                        this.ShippingAddress = shippingAddress;
                    }
                }
            }
            else
            {
                //Save the level B Address
                ShippingAddress.City               = tbShippingCity.Text;
                ShippingAddress.State              = ssShippingState.SelectedState;
                ShippingAddress.Line1              = tbShippingAddress.Text;
                ShippingAddress.PostalCode         = tbShippingZip.Text;
                ShippingAddress.DaytimePhoneNumber = pnShippingDayPhone.Text;
                ShippingAddress.FaxNumber          = pnShippingFax.Text;
                ShippingAddress.AcceptChanges();
            }

            //save the meta data
            this.CheckoutCart["ShippingInstructions"] = this.tbShippingSpecialInstructions.Text;

            //set the line item addresses
            foreach (LineItem lineItem in this.CheckoutCartHelper.LineItems)
            {
                lineItem.ShippingAddressId = ShippingAddress.Name;
            }
            //TODO:Save the shipping Meta Data
            this.CheckoutCart.AcceptChanges();
        }
Exemple #3
0
        /// <summary>
        /// Saves the shipping address based on the form information. For level B users, fields are filled out.
        /// For level A users, billing address is selected from a dropdown of exising addresses
        /// </summary>
        protected bool SaveShippingAddress()
        {
            if (this.UserIsLevelA)
            {
                if (ddlLevelAShippingAddress.SelectedIndex == 0)
                {
                    return(false);
                }

                foreach (CustomerAddress address in this.UserOrganization.Addresses)
                {
                    if (address.Name == ddlLevelAShippingAddress.SelectedValue)
                    {
                        //convert the selected address into an OrderAddress, including custom meta data.
                        OrderAddress shippingAddress = StoreHelper.ConvertToOrderAddress(address);
                        shippingAddress["TaxRate"]          = address["TaxRate"];
                        shippingAddress["IsFreightTaxable"] = address["IsFreightTaxable"];
                        shippingAddress["SBOAddressId"]     = address["SBOAddressId"];

                        this.ShippingAddress = shippingAddress;
                    }
                }
            }
            else
            {
                //Save the level B Address

                //this._shippingAddress = CheckoutCartHelper.FindAddressByName(NWTD.Orders.Cart.SHIPPING_ADDRESS_NAME);
                //if there is none, create one
                if (this.ShippingAddress == null && !UserIsLevelA)
                {
                    OrderAddress address = new OrderAddress()
                    {
                        Name = NWTD.Orders.Cart.SHIPPING_ADDRESS_NAME
                    };

                    address["TaxRate"]          = 0;
                    address["IsFreightTaxable"] = false;
                    address["SBOAddressId"]     = string.Empty;

                    this.ShippingAddress = address;
                }

                ShippingAddress.FirstName  = tbShippingAddressName.Text;
                ShippingAddress.City       = tbShippingCity.Text;
                ShippingAddress.State      = ddlShippingState.SelectedValue;
                ShippingAddress.Line1      = tbShippingAddress.Text;
                ShippingAddress.PostalCode = tbShippingZip.Text;
                //ShippingAddress.DaytimePhoneNumber = pnShippingDayPhone.Text;
                //ShippingAddress.FaxNumber = pnShippingFax.Text;
                ShippingAddress.AcceptChanges();
                bool hasAddress = false;
                foreach (OrderAddress address in this.CheckoutCart.OrderAddresses)
                {
                    if (address.Name == ShippingAddress.Name)
                    {
                        hasAddress = true;
                    }
                }
                if (!hasAddress)
                {
                    this.CheckoutCart.OrderAddresses.Add(ShippingAddress);
                }
            }


            //set the line item addresses
            foreach (LineItem lineItem in this.CheckoutCartHelper.LineItems)
            {
                lineItem.ShippingAddressId = ShippingAddress.Name;
            }
            //TODO:Save the shipping Meta Data
            this.CheckoutCart.AcceptChanges();
            return(true);
        }
        /// <summary>
        /// Binds the billing address.
        /// </summary>
        private void BindBillingAddress()
        {
            CustomerProfile ci = ProfileContext.Current.Profile;

            if (ci == null || ci.Account == null || ci.Account.Addresses == null || ci.Account.Addresses.Count == 0)
            {
                tblAddresses.Visible = false;
                OrderAddress address = CartHelper.FindAddressByName(CartHelper.OrderForm.BillingAddressId);
                if (address != null)
                {
                    AddressNewModule1.AddressInfo = address;
                }
                else
                {
                    if (CartHelper.Cart.OrderAddresses.Count > 0)
                    {
                        AddressNewModule1.AddressInfo = CartHelper.Cart.OrderAddresses[0];
                    }
                }

                rbBillingNewAddress.Checked = true;
                return;
            }

            //bool bSearch = CurrentOrderInfo.BillingAddress!=null;
            //bool bFound = false;
            AddressesList.Items.Clear();

            if (ci.Account.Addresses.Count > 0)
            {
                AddressesList.DataSource = ci.Account.Addresses;
                AddressesList.DataBind();

                AddressViewModule.AddressInfo = StoreHelper.ConvertToOrderAddress(ci.Account.Addresses[0]);
                AddressViewModule.DataBind();

                CommonHelper.SelectListItem(AddressesList, Profile.PreferredBillingAddress);

                if (!rbBillingNewAddress.Checked)
                {
                    rbBillingAddress.Checked = true;
                }
            }
            else
            {
            }

            /*
             * foreach (AddressInfo info in ci.Addresses)
             * {
             *  string strAddress = MakeAddressString(info);
             *  AddressesList.Items.Add(new ListItem(strAddress, info.AddressId));
             *  if(bSearch && (info.AddressId == CurrentOrderInfo.BillingAddress.AddressId))
             *      bFound = true;
             * }
             * */

            /*
             * if (!bFound)
             * {
             *  if (CurrentOrderInfo.BillingAddress != null)
             *  {
             *      AddressNewModule1.AddressInfo = CurrentOrderInfo.BillingAddress;
             *  }
             *  else
             *  {
             *      // bind shipping address
             *      if (CurrentOrderInfo.Shipments != null && CurrentOrderInfo.Shipments.Length > 0 && CurrentOrderInfo.Shipments[0].Details.DeliveryAddress != null)
             *      {
             *          // need to set AddressId to 0 to avoid replacing corresponding address' fields if new address' fields will be changed
             *          AddressInfo ai = CurrentOrderInfo.Shipments[0].Details.DeliveryAddress;
             *          ai.AddressId = "0";
             *          AddressNewModule1.AddressInfo = ai;
             *      }
             *  }
             *
             *  rbBillingNewAddress.Checked = true;
             *
             *  // Bind view address
             *  if (ci != null && ci.Addresses != null && ci.Addresses.Length != 0)
             *  {
             *      AddressViewModule.AddressInfo = ci.Addresses[0];
             *      AddressViewModule.DataBind();
             *  }
             * }
             * else
             * {
             *  if (BillingAddress != null && !String.IsNullOrEmpty(BillingAddress.AddressId))
             *  {
             *      CommonHelper.SelectListItem(AddressesList, BillingAddress.AddressId);
             *      AddressViewModule.AddressInfo = BillingAddress;
             *      AddressViewModule.DataBind();
             *  }
             *  else
             *  {
             *      CommonHelper.SelectListItem(AddressesList, AddressesList.Items[0].Value);
             *      AddressViewModule.AddressInfo = ci.Addresses[0];
             *      AddressViewModule.DataBind();
             *  }
             *  rbBillingAddress.Checked = true;
             * }
             * */
        }
        private int PlaceOneClickOrder(CartHelper cartHelper, PlaceOrderInfo orderInfo)
        {
            Cart cart = cartHelper.Cart;

            CustomerContact currentContact = CustomerContext.Current.GetContactById(orderInfo.CustomerId);

            if (currentContact == null)
            {
                throw new NullReferenceException("Cannot load customer with id: " + orderInfo.CustomerId.ToString());
            }

            OrderGroupWorkflowManager.RunWorkflow(cart, OrderGroupWorkflowManager.CartCheckOutWorkflowName);
            cart.CustomerId   = orderInfo.CustomerId;
            cart.CustomerName = currentContact.FullName;

            if (currentContact.PreferredBillingAddress != null)
            {
                OrderAddress orderBillingAddress = StoreHelper.ConvertToOrderAddress(currentContact.PreferredBillingAddress);
                int          billingAddressId    = cart.OrderAddresses.Add(orderBillingAddress);
                cart.OrderForms[0].BillingAddressId = orderBillingAddress.Name;
            }
            if (currentContact.PreferredShippingAddress != null)
            {
                int shippingAddressId = cart.OrderAddresses.Add(StoreHelper.ConvertToOrderAddress(currentContact.PreferredShippingAddress));
            }

            if (cart.OrderAddresses.Count == 0)
            {
                CustomerAddress address = currentContact.ContactAddresses.FirstOrDefault();
                if (address != null)
                {
                    int defaultAddressId = cart.OrderAddresses.Add(StoreHelper.ConvertToOrderAddress(address));
                    cart.OrderForms[0].BillingAddressId = address.Name;
                }
            }

            var po = cart.SaveAsPurchaseOrder();

            // These does not persist
            po.OrderForms[0].Created  = orderInfo.OrderDate;
            po.OrderForms[0].Modified = orderInfo.OrderDate;
            po.Created  = orderInfo.OrderDate;
            po.Modified = orderInfo.OrderDate;

            currentContact.LastOrder = po.Created;
            currentContact.SaveChanges();

            // Add note to purchaseOrder
            OrderNotesManager.AddNoteToPurchaseOrder(po, "", OrderNoteTypes.System, orderInfo.CustomerId);
            // OrderNotesManager.AddNoteToPurchaseOrder(po, "Created: " + po.Created, OrderNoteTypes.System, orderInfo.CustomerId);

            po.AcceptChanges();

            SetOrderDates(po.Id, orderInfo.OrderDate);

            //Add do Find index
            // OrderHelper.CreateOrderToFind(po);

            // Remove old cart
            cart.Delete();
            cart.AcceptChanges();
            return(po.Id);
        }