Example #1
0
        public bool ShippingZoneRemoveArea(long zoneId, string countryIso3, string regionAbbreviation)
        {
            Zone z = ShippingZones.Find(zoneId);

            if (z != null)
            {
                if (z.Id == zoneId)
                {
                    ZoneArea located = null;
                    foreach (ZoneArea a in z.Areas)
                    {
                        if (a.CountryIsoAlpha3 == countryIso3 &&
                            a.RegionAbbreviation == regionAbbreviation)
                        {
                            located = a;
                            break;
                        }
                    }
                    if (located != null)
                    {
                        if (z.Areas.Remove(located))
                        {
                            return(ShippingZones.Update(z));
                        }
                    }
                }
            }
            return(false);
        }
Example #2
0
 public void EnsureDefaultZones(long storeId)
 {
     CreateAndReassign(ShippingZones.UnitedStatesAll());
     CreateAndReassign(ShippingZones.UnitedStates48Contiguous());
     CreateAndReassign(ShippingZones.UnitedStatesAlaskaAndHawaii());
     CreateAndReassign(ShippingZones.International("USA"));
 }
Example #3
0
        public bool ShippingZoneAddArea(long zoneId, string countryIso3, string regionAbbreviation)
        {
            Zone z = ShippingZones.Find(zoneId);

            if (z != null)
            {
                if (z.Id == zoneId)
                {
                    bool exists = false;
                    foreach (ZoneArea a in z.Areas)
                    {
                        if (a.CountryIsoAlpha3 == countryIso3 &&
                            a.RegionAbbreviation == regionAbbreviation)
                        {
                            exists = true;
                            break;
                        }
                    }
                    if (!exists)
                    {
                        z.Areas.Add(new ZoneArea()
                        {
                            CountryIsoAlpha3 = countryIso3, RegionAbbreviation = regionAbbreviation
                        });
                        return(ShippingZones.Update(z));
                    }
                }
            }
            return(false);
        }
Example #4
0
        public IHttpActionResult Get(string zip)
        {
            ZipZone zipZone = ShippingZones.GetOne(zip);

            if (zipZone == null)
            {
                return(NotFound());
            }
            return(Ok(zipZone));
        }
Example #5
0
        public void GetOne_GoodZip_Edges()
        {
            ZipZone zipZone = ShippingZones.GetOne("55555");

            Assert.IsTrue(zipZone.Zip == "55555");
            Assert.IsTrue(zipZone.Zone == "4");

            zipZone = ShippingZones.GetOne("55557");
            Assert.IsTrue(zipZone.Zip == "55557");
            Assert.IsTrue(zipZone.Zone == "9");
        }
Example #6
0
        private void CreateAndReassign(Zone zone)
        {
            var methods = ShippingMethods.FindForZones(new List <Zone> {
                zone
            });

            if (ShippingZones.Create(zone))
            {
                methods.ForEach(m =>
                {
                    m.ZoneId = zone.Id;
                    ShippingMethods.Update(m);
                });
            }
        }
Example #7
0
        public Utilities.SortableCollection <Shipping.ShippingRateDisplay> FindAvailableShippingRates(Order o)
        {
            Utilities.SortableCollection <Shipping.ShippingRateDisplay> result = new Utilities.SortableCollection <Shipping.ShippingRateDisplay>();

            // Get all the methods that apply to this shipping address and store
            List <Zone>           zones   = ShippingZones.FindAllZonesForAddress(o.ShippingAddress, o.StoreId);
            List <ShippingMethod> methods = new List <ShippingMethod>();

            methods = this.ShippingMethods.FindForZones(zones);

            // Get Rates for each Method
            foreach (Shipping.ShippingMethod m in methods)
            {
                Collection <Shipping.ShippingRateDisplay> tempRates = m.GetRates(o);
                if (tempRates != null)
                {
                    for (int i = 0; i <= tempRates.Count - 1; i++)
                    {
                        ShippingRateDisplay fRate = tempRates[i].GetCopy();
                        //fRate.AdjustRate(m.AdjustmentType, m.Adjustment);
                        result.Add(fRate);
                    }
                }
            }

            // Tally up extra ship fees
            decimal totalExtraFees = 0m;

            foreach (LineItem li in o.Items)
            {
                if (li.ExtraShipCharge > 0)
                {
                    totalExtraFees += li.ExtraShipCharge;
                }
            }

            // update results with extra ship fees and handling
            foreach (Shipping.ShippingRateDisplay displayRate in result)
            {
                displayRate.Rate += totalExtraFees + o.TotalHandling;
            }


            // Apply promotions to rates here:

            // Run workflow to get shipping rate discounts
            //BusinessRules.ShippingTaskContext c = new BusinessRules.ShippingTaskContext();
            //c.Rates = result;
            //c.UserId = this.UserID;
            //c.Order = this;
            //BusinessRules.Workflow.RunByName(c, BusinessRules.WorkflowNames.ApplyShippingDiscounts);


            // Sort Rates
            result.Sort("Rate", Utilities.SortDirection.Ascending);

            if (result.Count < 1)
            {
                if (o.IsOrderFreeShipping())
                {
                    result.Add(new Shipping.ShippingRateDisplay("Free Shipping.", "", "", 0m, "FREESHIPPING"));
                }
                else
                {
                    string value = Content.SiteTerms.GetTerm(Content.SiteTermIds.ShippingUnknown);
                    if (!string.IsNullOrEmpty(value))
                    {
                        result.Add(new Shipping.ShippingRateDisplay(value, "", "", 0m, "UNKNOWN"));
                    }
                    else
                    {
                        result.Add(new Shipping.ShippingRateDisplay("To Be Determined. Contact Store for Details", "", "", 0m, "TOBEDETERMINED"));
                    }
                }
            }

            return(result);
        }
Example #8
0
 public IEnumerable <ZipZone> Get()
 {
     return(ShippingZones.GetAll());
 }
Example #9
0
        private SortableCollection <ShippingRateDisplay> FindAvailableShippingRatesInternal(Order order,
                                                                                            string shippingMethodIdFilter = null)
        {
            if (order == null)
            {
                return(new SortableCollection <ShippingRateDisplay>());
            }

            var result = new SortableCollection <ShippingRateDisplay>();

            // Get all the methods that apply to this shipping address and store
            var zones   = ShippingZones.FindAllZonesForAddress(order.ShippingAddress, order.StoreId);
            var methods = ShippingMethods.FindForZones(zones);

            if (!string.IsNullOrEmpty(shippingMethodIdFilter))
            {
                methods = methods.Where(m => m.Bvin == shippingMethodIdFilter).ToList();
            }

            // Get Rates for each Method
            if (!order.IsOrderFreeShipping())
            {
                var tasks = new List <Task <Collection <ShippingRateDisplay> > >();
                foreach (var method in methods)
                {
                    var task = Task.Factory.StartNew(hccContext =>
                    {
                        HccRequestContext.Current = hccContext as HccRequestContext;
                        return(method.GetRates(order, Context.CurrentStore));
                    },
                                                     HccRequestContext.Current);
                    tasks.Add(task);
                }
                Task.WaitAll(tasks.ToArray());

                foreach (var task in tasks)
                {
                    var tempRates = task.Result;
                    if (tempRates != null)
                    {
                        for (var i = 0; i <= tempRates.Count - 1; i++)
                        {
                            var fRate = tempRates[i].GetCopy();
                            result.Add(fRate);
                        }
                    }
                }
            }

            // Update results with extra ship fees and handling
            foreach (ShippingRateDisplay displayRate in result)
            {
                // Tally up extra ship fees
                var totalExtraFees = 0m;
                foreach (var li in order.Items)
                {
                    if (li.ExtraShipCharge > 0 && !li.MarkedForFreeShipping(displayRate.ShippingMethodId) &&
                        li.ShippingCharge == ShippingChargeType.ChargeShippingAndHandling ||
                        li.ShippingCharge == ShippingChargeType.ChargeShipping)
                    {
                        totalExtraFees += li.ExtraShipCharge * li.Quantity;
                    }
                }

                displayRate.Rate += totalExtraFees + order.TotalHandling;
            }


            // Apply promotions to rates here
            var             membershipServices = Factory.CreateService <MembershipServices>();
            CustomerAccount currentUser        = null;

            if (order.UserID != string.Empty)
            {
                currentUser = membershipServices.Customers.Find(order.UserID);
            }

            var marketingServices = Factory.CreateService <MarketingService>();
            var offers            = marketingServices.Promotions.FindAllPotentiallyActive(DateTime.UtcNow,
                                                                                          PromotionType.OfferForShipping);

            foreach (ShippingRateDisplay displayRate in result)
            {
                foreach (var offer in offers)
                {
                    if (offer.DoNotCombine && order.HasAnyNonSaleDiscounts)
                    {
                        continue;
                    }

                    var newRate = offer.ApplyToShippingRate(Context, order, currentUser, displayRate.ShippingMethodId,
                                                            displayRate.Rate);

                    if (newRate < displayRate.Rate)
                    {
                        var discount = -1 * (newRate - displayRate.Rate);

                        displayRate.PotentialDiscount = discount;
                    }
                }
            }

            //Changes to have free shipping available for single item in cart by promotion set for "Order Items" - 9May2016-Tushar

            var offersForLineItems = marketingServices.Promotions.FindAllPotentiallyActive(DateTime.UtcNow,
                                                                                           PromotionType.OfferForLineItems);

            foreach (ShippingRateDisplay displayRate in result)
            {
                foreach (var offer in offersForLineItems)
                {
                    var context = new PromotionContext(Context, PromotionType.OfferForLineItems, offer.Id)
                    {
                        Order                   = order,
                        CurrentCustomer         = currentUser,
                        CustomerDescription     = offer.CustomerDescription,
                        CurrentShippingMethodId = displayRate.ShippingMethodId,
                        AdjustedShippingRate    = displayRate.Rate,
                        OtherOffersApplied      = order.HasAnyNonSaleDiscounts
                    };

                    var isQualified = offer.ApplyForFreeShipping(context);
                    if (order.Items.Count == 1 || order.IsOrderHasAllItemsQualifiedFreeShipping())
                    {
                        var isFreeShippingAction =
                            offer.Actions.Where(
                                p =>
                                p.TypeId.ToString() == LineItemFreeShipping.TypeIdString &&
                                p.Settings.ContainsKey("methodids") &&
                                p.Settings["methodids"].ToUpperInvariant()
                                .Contains(displayRate.ShippingMethodId.ToUpperInvariant())).ToList();

                        if (isFreeShippingAction.Count > 0 && isQualified)
                        {
                            displayRate.PotentialDiscount = displayRate.Rate;
                        }
                    }
                }
            }
            //End changes to have free shipping available for single item in cart by promotion set for "Order Items" - 9May2016-Tushar

            FilterRatesByShippingMethods(result, order);

            // Sort Rates
            result.Sort("Rate", SortDirection.Ascending);

            if (result.Count < 1)
            {
                if (order.IsOrderFreeShipping())
                {
                    var rateName = order.TotalHandling > 0
                        ? GlobalLocalization.GetString("Handling")
                        : GlobalLocalization.GetString("FreeShipping");
                    result.Add(new ShippingRateDisplay(rateName, "", "", order.TotalHandling,
                                                       ShippingMethod.MethodFreeShipping));
                }
                else
                {
                    result.Add(new ShippingRateDisplay(GlobalLocalization.GetString("ToBeDetermined"), string.Empty,
                                                       string.Empty, 0m, ShippingMethod.MethodToBeDetermined));
                }
            }

            return(result);
        }
Example #10
0
 public void GetOne_BadZip()
 {
     Assert.IsNull(ShippingZones.GetOne("55"));
     Assert.IsNull(ShippingZones.GetOne("55550"));
     Assert.IsNull(ShippingZones.GetOne("ABC"));
 }
Example #11
0
 public void GetAll_Returns_Array()
 {
     ZipZone[] zones = ShippingZones.GetAll();
     Assert.IsNotNull(zones);
     Assert.IsInstanceOfType(zones[0], typeof(ZipZone));
 }