Exemplo n.º 1
0
        private PackageList PreparePackages(Warehouse origin, Address destination, BasketItemCollection contents)
        {
            PackageList plist = PackageManager.GetPackageList(contents);

            if (plist == null || plist.Count == 0)
            {
                return(null);
            }

            ProviderUnits pUnits = GetProviderUnits(origin.Country);
            //GET UNITS USED BY STORE
            Store           store = Token.Instance.Store;
            MeasurementUnit storeMeasurementUnit = store.MeasurementUnit;
            WeightUnit      storeWeightUnit      = store.WeightUnit;

            bool requireMC = storeMeasurementUnit != pUnits.MeasurementUnit;
            bool requireWC = storeWeightUnit != pUnits.WeightUnit;

            if (requireMC && requireWC)
            {
                plist.ConvertBoth(pUnits.WeightUnit, pUnits.MeasurementUnit);
            }
            else if (requireWC)
            {
                plist.ConvertWeight(pUnits.WeightUnit);
            }
            else if (requireMC)
            {
                plist.ConvertDimensions(pUnits.MeasurementUnit);
            }

            WeightUnit sourceUnit = (Token.Instance.Store.WeightUnit == WeightUnit.Grams || Token.Instance.Store.WeightUnit == WeightUnit.Kilograms) ? WeightUnit.Kilograms : WeightUnit.Pounds;
            LSDecimal  maxWeight  = LocaleHelper.ConvertWeight(sourceUnit, MaxPackageWeight, pUnits.WeightUnit);
            LSDecimal  minWeight  = LocaleHelper.ConvertWeight(sourceUnit, MinPackageWeight, pUnits.WeightUnit);

            if (EnablePackageBreakup && maxWeight > 0)
            {
                //compose packages (splits items larger than the maximum carrier weight)
                plist.Compose(maxWeight, minWeight);
            }
            else
            {
                plist.EnsureMinimumWeight(minWeight);
            }

            //convert weight and dimensions to whole numbers
            plist.ConvertDimsToWholeNumbers();
            plist.RoundWeight(1);

            return(plist);
        }