Esempio n. 1
0
        /// <summary>
        /// Sets the billing addresses.
        /// </summary>
        private void SetBillingAddresses()
        {
            OrderAddress address = null;

            if (Cart.OrderAddresses.ToArray().Length > 0)
            {
                string billingAddressId = Cart.OrderForms[0].BillingAddressId;
                address = CartHelper.FindAddressByName(billingAddressId);
            }
            else
            {
                var currentContact = CustomerContext.Current.CurrentContact;

                var defaultBillingAddress = currentContact == null ? null : currentContact.ContactAddresses.FirstOrDefault(
                    a => currentContact.PreferredBillingAddressId.HasValue &&
                    currentContact.PreferredBillingAddressId.Value == a.PrimaryKeyId.Value);
                // Set default billing address to new order.
                if (defaultBillingAddress != null)
                {
                    address = new OrderAddress();
                    CustomerAddress.CopyCustomerAddressToOrderAddress(defaultBillingAddress, address);

                    Cart.OrderAddresses.Add(address);
                    Cart.OrderForms[0].BillingAddressId = address.Name;
                }
            }

            BillingAddressInfo.OrderAddress = address;
            BillingAddressInfo.DataBind();
        }
Esempio n. 2
0
        /// <summary>
        /// Sets the shipping addresses.
        /// </summary>
        private void SetShippingAddresses()
        {
            OrderAddress address = null;

            var currentContact = CustomerContext.Current.CurrentContact;

            if (Cart.OrderForms[0].Shipments.Count > 0 && !string.IsNullOrEmpty(CartHelper.Cart.OrderForms[0].Shipments[0].ShippingAddressId))
            {
                string shippingAddressId = CartHelper.Cart.OrderForms[0].Shipments[0].ShippingAddressId;

                var cusomterAddress = currentContact == null ? null : currentContact.ContactAddresses.FirstOrDefault(ca => ca.Name.ToString().Equals(shippingAddressId));
                if (cusomterAddress != null)
                {
                    address = new OrderAddress();
                    CustomerAddress.CopyCustomerAddressToOrderAddress(cusomterAddress, address);
                }
                else
                {
                    address = CartHelper.FindAddressByName(shippingAddressId);
                }
            }
            else
            {
                var defaultShippingAdd = currentContact == null ? null : currentContact.ContactAddresses.FirstOrDefault(
                    a => currentContact.PreferredShippingAddressId.HasValue &&
                    currentContact.PreferredShippingAddressId.Value == a.PrimaryKeyId.Value);
                // Set default shipping address to new order.
                if (defaultShippingAdd != null)
                {
                    address = new OrderAddress();
                    CustomerAddress.CopyCustomerAddressToOrderAddress(defaultShippingAdd, address);

                    var shipment = Cart.OrderForms[0].Shipments[0];

                    shipment.ShippingAddressId = address.Name;

                    Cart.OrderAddresses.Add(address);
                }
            }

            ShippingAddressInfo.OrderAddress = address;
            ShippingAddressInfo.DataBind();
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the default shipping addresses.
        /// </summary>
        private OrderAddress GetDefaultShippingAddresses()
        {
            OrderAddress address = null;

            var currentContact = CustomerContext.Current.CurrentContact;

            {
                var defaultShippingAdd = currentContact == null ? null : currentContact.ContactAddresses.FirstOrDefault(
                    a => currentContact.PreferredShippingAddressId.HasValue &&
                    currentContact.PreferredShippingAddressId.Value == a.PrimaryKeyId.Value);
                // Set default shipping address to new order.
                if (defaultShippingAdd != null)
                {
                    address = new OrderAddress();
                    CustomerAddress.CopyCustomerAddressToOrderAddress(defaultShippingAdd, address);
                }
            }

            return(address);
        }
Esempio n. 4
0
        /// <summary>
        /// Get shipping address
        /// </summary>
        /// <param name="shipmentIndex">Shipment Index</param>
        /// <returns></returns>
        private OrderAddress GetShippingAddress(int shipmentIndex)
        {
            OrderAddress address = null;

            var currentContact = CustomerContext.Current.CurrentContact;

            if (Cart.OrderForms[0].Shipments.Count > 0 && !string.IsNullOrEmpty(CartHelper.Cart.OrderForms[0].Shipments[shipmentIndex].ShippingAddressId))
            {
                string shippingAddressId = CartHelper.Cart.OrderForms[0].Shipments[shipmentIndex].ShippingAddressId;

                var cusomterAddress = currentContact == null ? null : currentContact.ContactAddresses.FirstOrDefault(ca => ca.Name.ToString().Equals(shippingAddressId));
                if (cusomterAddress != null)
                {
                    address = new OrderAddress();
                    CustomerAddress.CopyCustomerAddressToOrderAddress(cusomterAddress, address);
                }
                else
                {
                    address = CartHelper.FindAddressByName(shippingAddressId);
                }
            }

            return(address);
        }
Esempio n. 5
0
        /// <summary>
        /// Handles the ItemCommand event of the addressBook control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.ListViewCommandEventArgs"/> instance containing the event data.</param>
        void addressBook_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            if (string.IsNullOrEmpty(e.CommandArgument.ToString()) || _currentContact == null)
            {
                return;
            }

            var addressId = e.CommandArgument.ToString();
            var ca        = _currentContact.ContactAddresses.FirstOrDefault(x => x.AddressId.ToString().ToLower().Equals(addressId.ToLower()));

            if (ca == null)
            {
                return;
            }

            var address = _cartHelper.FindAddressByName(ca.Name);

            if (address == null)
            {
                address = ConvertCustomerToOrderAddress(ca);
                Cart.OrderAddresses.Add(address);
            }
            else
            {
                CustomerAddress.CopyCustomerAddressToOrderAddress(ca, address);
            }

            // Add address to BillingAddressId/ShippingAddressId
            if (addressType.Value.Equals("billing"))
            {
                Cart.OrderForms[0].BillingAddressId = address.Name;
            }
            else
            {
                int shipId;
                if (int.TryParse(shipmentId.Value, out shipId))
                {
                    var shipment = Cart.OrderForms[0].Shipments.ToArray().FirstOrDefault(s => s.Id == shipId);
                    if (shipment != null)
                    {
                        shipment.ShippingAddressId = ca.Name;
                        OrderGroupWorkflowManager.RunWorkflow(Cart, OrderGroupWorkflowManager.CartPrepareWorkflowName);
                    }
                }
                else
                {
                    var shipment = Cart.OrderForms[0].Shipments.ToArray().FirstOrDefault()
                                   ?? new Shipment()
                    {
                        CreatorId = SecurityContext.Current.CurrentUserId.ToString(),
                        Created   = DateTime.UtcNow
                    };

                    shipment.ShippingAddressId = address.Name;

                    if (Cart.OrderForms[0].Shipments.Count < 1)
                    {
                        Cart.OrderForms[0].Shipments.Add(shipment);
                    }

                    if (!shipment.ShippingMethodId.Equals(Guid.Empty))
                    {
                        //Calculate shipping in case choosing shipping method first.
                        OrderGroupWorkflowManager.RunWorkflow(Cart, OrderGroupWorkflowManager.CartPrepareWorkflowName);
                    }
                }
            }

            Cart.AcceptChanges();
            //redirect after post
            Context.RedirectFast(Request.RawUrl + "#ShippingRegion" + shipmentId.Value);
        }