示例#1
0
        public void BuildCart(IShoppingCartService ShoppingCartService, ShoppingCart Cart)
        {
            LocationsStateRecord state = null;
            LocationsCountryRecord country = null;

            // Based on user selected location
            Int32 countryId = ShoppingCartService.GetProperty<int>("CountryId");
            if (countryId > 0) {
                country = _locationsService.GetCountry(countryId);
                Int32 stateId = ShoppingCartService.GetProperty<int>("StateId");
                if (stateId > 0) {
                    state = _locationsService.GetState(stateId);
                }
            }
            else {
                // Set default country
                country = _locationsService.GetDefaultCountry();
                if (country != null) {
                    ShoppingCartService.SetProperty<int>("CountryId", country.Id);
                }
            }

            Cart.Properties["BillingCountry"] = country;
            Cart.Properties["BillingState"] = state;
            Cart.Properties["ShippingCountry"] = country;
            Cart.Properties["ShippingState"] = state;
        }
示例#2
0
 public void BuildCart(IShoppingCartService ShoppingCartService, ShoppingCart Cart)
 {
     var shippingPrice = Cart.Shipping as IPrice;
     var shippingVat = (Cart.Shipping as IContent).GetVatRate();
     if (shippingPrice != null && shippingVat != null && shippingPrice.Price != 0) {
         Cart.AddTax(shippingVat, shippingPrice.Price);
     }
 }
示例#3
0
 public void BuildCart(IShoppingCartService ShoppingCartService, ShoppingCart Cart)
 {
     foreach (var entry in Cart.Items) {
         var vat = entry.Item.GetVatRate();
         if (vat != null && entry.SubTotal() != 0) {
             Cart.AddTax(vat, entry.SubTotal());
         }
     }
 }
示例#4
0
        public void BuildCart(IShoppingCartService ShoppingCartService, ShoppingCart Cart)
        {
            var country = Cart.Properties["ShippingCountry"] as LocationsCountryRecord;
            var state = Cart.Properties["ShippingState"] as LocationsStateRecord;

            if (state != null && state.Enabled && state.ShippingZoneRecord != null) {
                Cart.Properties["ShippingZone"] = state.ShippingZoneRecord;
            }
            else if (country != null && country.Enabled && country.ShippingZoneRecord != null) {
                Cart.Properties["ShippingZone"] = country.ShippingZoneRecord;
            }
        }
示例#5
0
        public void BuildCart(IShoppingCartService ShoppingCartService, ShoppingCart Cart)
        {
            var cartRecords = ShoppingCartService.ListItems();
            var shippingParts = ListShippingParts(cartRecords);

            if (shippingParts.Any()) {
                var shippingInfos = Cart.Properties["ShippingInfos"] as IList<Tuple<int, IShippingInfo>> ?? new List<Tuple<int, IShippingInfo>>();
                foreach (var cartRecord in cartRecords) {
                    var shippingPart = shippingParts.Where(p => p.Id == cartRecord.ItemId).FirstOrDefault();

                    if (shippingPart != null) {
                        shippingInfos.Add(new Tuple<int, IShippingInfo>(cartRecord.Quantity, shippingPart));
                    }
                }
                Cart.Properties["ShippingInfos"] = shippingInfos;
            }
        }
示例#6
0
        public void BuildCart(IShoppingCartService ShoppingCartService, ShoppingCart Cart)
        {
            var cartRecords = ShoppingCartService.ListItems();
            var products = ListProducts(cartRecords);

            foreach (var cartRecord in cartRecords.Where(cr => cr.ItemType == ProductPart.PartItemType)) {
                var product = products.Where(p => p.Id == cartRecord.ItemId).FirstOrDefault();

                if (product != null) {
                    Cart.Items.Add(new ShoppingCartItem {
                        Id = cartRecord.Id,
                        Item = product,
                        Quantity = cartRecord.Quantity
                    });
                }
            }
        }
示例#7
0
        public void BuildCart(IShoppingCartService ShoppingCartService, ShoppingCart Cart)
        {
            if (!Cart.IsShippingRequired()) {
                Cart.Shipping = null;
                return;
            }

            var zone = Cart.Properties["ShippingZone"] as ShippingZoneRecord;
            if (zone == null) {
                // Need a shipping zone
                //Cart.InvalidCart();
                Cart.Shipping = null;
                return;
            }

            var suitableProviders = _shippingService.GetSuitableProviderOptions(
                zone,
                Cart.Properties["ShippingInfos"] as IList<Tuple<int, IShippingInfo>> ?? new List<Tuple<int, IShippingInfo>>(),
                Cart.ItemsTotal()
            );

            if (!suitableProviders.Any()) {
                // Need a suitable shipping provider
                //Cart.InvalidCart();
                Cart.Shipping = null;
                return;
            }

            Int32 selectedProviderId = ShoppingCartService.GetProperty<int>("ShippingProviderId");
            var selectedProvider = suitableProviders.Where(p => p.Provider.Id == selectedProviderId).FirstOrDefault();
            if (selectedProvider != null) {
                // Apply selected provider
                Cart.Shipping = selectedProvider;
            }
            else {
                // Set cheapest option
                Cart.Shipping = suitableProviders.OrderBy(p => p.Option.Price).FirstOrDefault();
            }
        }
示例#8
0
        public void BuildCart(IShoppingCartService ShoppingCartService, ShoppingCart Cart)
        {
            var customer = _customersService.GetCustomer();

            if (customer == null) {
                return;
            }

            // Get "Checkout" property to know the Checkout provider beeing used
            var checkout = ShoppingCartService.GetProperty<string>("Checkout");

            if (string.IsNullOrWhiteSpace(checkout) && customer.DefaultAddress != null) {
                // Override default location
                ShoppingCartService.SetProperty<int>("CountryId", customer.DefaultAddress.CountryId);
                ShoppingCartService.SetProperty<int>("StateId", customer.DefaultAddress.StateId);

                Cart.Properties["BillingCountry"] = customer.DefaultAddress.Country;
                Cart.Properties["BillingState"] = customer.DefaultAddress.State;
                Cart.Properties["ShippingCountry"] = customer.DefaultAddress.Country;
                Cart.Properties["ShippingState"] = customer.DefaultAddress.State;
            }
            else if (checkout == "Checkout") {
                var billingAddress = customer.Addresses.Where(a => a.Id == ShoppingCartService.GetProperty<int>("BillingAddressId")).FirstOrDefault() ?? customer.DefaultAddress ?? customer.Addresses.FirstOrDefault();
                var shippingAddress = customer.Addresses.Where(a => a.Id == ShoppingCartService.GetProperty<int>("ShippingAddressId")).FirstOrDefault() ?? customer.DefaultAddress ?? customer.Addresses.FirstOrDefault();

                if (billingAddress != null) {
                    Cart.Properties["BillingAddress"] = billingAddress;
                    Cart.Properties["BillingCountry"] = billingAddress.Country;
                    Cart.Properties["BillingState"] = billingAddress.State;
                }

                if (shippingAddress != null) {
                    Cart.Properties["ShippingAddress"] = shippingAddress;
                    Cart.Properties["ShippingCountry"] = shippingAddress.Country;
                    Cart.Properties["ShippingState"] = shippingAddress.State;
                }
            }
        }