Exemple #1
0
        static public bool ShippingIsAllValid(CartItemCollection CartItems)
        {
            bool isRealTime = Shipping.GetActiveShippingCalculationID().Equals(ShippingCalculationEnum.UseRealTimeRates);

            // EVERY non-download item must have a shipping address and shipping method:
            foreach (CartItem c in CartItems)
            {
                if (isRealTime)
                {
                    String selMethod = c.ShippingMethod.Split('|')[0];

                    if (selMethod == AppLogic.AppConfig("RTShipping.CallForShippingPrompt") || selMethod == AppLogic.GetString("RTShipping.LocalPickupMethodName", Customer.Current.LocaleSetting))
                    {
                        return(true);
                    }
                }

                if (!c.IsDownload && !c.FreeShipping && !GiftCard.s_IsEmailGiftCard(c.ProductID) && c.Shippable)
                {
                    // at the time this routine is called, ALL of these must be filled in!
                    if (c.ShippingAddressID == 0 || c.ShippingMethodID == 0 || c.ShippingMethod.Length == 0)
                    {
                        return(false);
                    }
                }
            }

            // if any invalid state/country/shipping method combinations found, then shipping is not valid:
            List <int> AlreadyCheckedAddressIDs = new List <int>();

            foreach (CartItem c in CartItems)
            {
                if (!AlreadyCheckedAddressIDs.Contains(c.ShippingAddressID))
                {
                    if (!c.IsDownload && !c.FreeShipping && !c.IsSystem && !GiftCard.s_IsEmailGiftCard(c.ProductID) && !c.Shippable)
                    {
                        Address sa = new Address();
                        sa.LoadFromDB(c.ShippingAddressID);

                        if (sa.State.Trim().Length == 0)
                        {
                            throw new ArgumentException("State field in address record is BLANK. That is not allowed!");
                        }
                        if (sa.Country.Trim().Length == 0)
                        {
                            throw new ArgumentException("Country field in address record is BLANK. That is not allowed!");
                        }
                        if (!Shipping.ShippingMethodIsValid(c.ShippingMethodID, sa.State, sa.Country))
                        {
                            return(false);
                        }
                    }
                }
                AlreadyCheckedAddressIDs.Add(c.ShippingAddressID);
            }
            // all seems ok
            return(true);
        }
Exemple #2
0
 static public bool IsAllFreeShippingComponents(CartItemCollection CartItems)
 {
     // CartItemCollection inherits from List, so .Count in C# doesn't directly
     // translate to LINQ in VB. Use .Where(Func predicate).Count() instead...
     //JH 10.20.2010  - free shipping componentes include freeshipping, not shipable, not email gift card, and download products (as it was in 8012)
     return(CartItems.All(ci => ci.FreeShipping || !ci.Shippable || ci.IsDownload || GiftCard.s_IsEmailGiftCard(ci.ProductID)));
 }