예제 #1
0
        //public virtual MultiShipmentViewModel CreateMultiShipmentViewModel(ICart cart, MultiShipmentPage multiShipmentPage, bool isAuthenticated)
        //{
        //    var viewModel = new MultiShipmentViewModel(multiShipmentPage)
        //    {
        //        AvailableAddresses = GetAvailableShippingAddresses(cart),
        //        CartItems = cart != null ? FlattenCartItems(_shipmentViewModelFactory.CreateShipmentsViewModel(cart).SelectMany(x => x.CartItems)) : new CartItemViewModel[0],
        //        ReferrerUrl = GetReferrerUrl()
        //    };

        //    if (!isAuthenticated)
        //    {
        //        UpdateShippingAddressesForAnonymous(viewModel);
        //    }

        //    return viewModel;
        //}

        public virtual MultiAddressViewModel CreateMultiShipmentViewModel(ICart cart, CheckoutPage checkoutPage, bool isAuthenticated)
        {
            var viewModel = new MultiAddressViewModel(checkoutPage)
            {
                AvailableAddresses                            = GetAvailableShippingAddresses(cart),
                CartItems                                     = cart != null?FlattenCartItems(_shipmentViewModelFactory.CreateShipmentsViewModel(cart).SelectMany(x => x.CartItems)) : Array.Empty <CartItemViewModel>(),
                                                  ReferrerUrl = GetReferrerUrl(),
            };

            if (!isAuthenticated && !viewModel.AvailableAddresses.Any())
            {
                UpdateShippingAddressesForAnonymous(viewModel);
            }

            return(viewModel);
        }
예제 #2
0
        //private void UpdateShippingAddressesForAnonymous(MultiShipmentViewModel viewModel)
        //{
        //    foreach (var item in viewModel.CartItems)
        //    {
        //        var anonymousShippingAddress = new AddressModel
        //        {
        //            AddressId = Guid.NewGuid().ToString(),
        //            Name = Guid.NewGuid().ToString(),
        //            CountryCode = "USA"
        //        };

        //        item.AddressId = anonymousShippingAddress.AddressId;
        //        _addressBookService.LoadCountriesAndRegionsForAddress(anonymousShippingAddress);
        //        viewModel.AvailableAddresses.Add(anonymousShippingAddress);
        //    }
        //}

        private void UpdateShippingAddressesForAnonymous(MultiAddressViewModel viewModel)
        {
            foreach (var item in viewModel.CartItems)
            {
                var anonymousShippingAddress = new AddressModel
                {
                    AddressId   = Guid.NewGuid().ToString(),
                    Name        = Guid.NewGuid().ToString(),
                    CountryCode = "USA"
                };

                item.AddressId = anonymousShippingAddress.AddressId;
                _addressBookService.LoadCountriesAndRegionsForAddress(anonymousShippingAddress);
                viewModel.AvailableAddresses.Add(anonymousShippingAddress);
            }
        }