Esempio n. 1
0
        private decimal?CalculatePrice(double?weight,
                                       string shippingSize,
                                       decimal usListingPrice,
                                       IList <RateByCountryDTO> allRates,
                                       MarketType forMarket,
                                       string forMarketplaceId)
        {
            var usShipping = RateService.GetMarketShippingAmount(MarketType.Amazon,
                                                                 MarketplaceKeeper.AmazonComMarketplaceId); // 4.49M;
            var currency   = PriceHelper.GetCurrencyAbbr(forMarket, forMarketplaceId);
            var caShipping = PriceHelper.ConvertToUSD(RateService.GetMarketShippingAmount(forMarket, forMarketplaceId), currency);

            var item = new OrderItemRateInfo()
            {
                Quantity     = 1,
                ShippingSize = shippingSize
            };

            IList <RateByCountryDTO> rates = null;

            if (weight.HasValue && weight > 0)
            {
                rates = allRates.Where(r => r.Weight == Math.Floor(weight.Value)).ToList();
            }

            var localPackageType = PackageTypeCode.Flat;

            if (!String.IsNullOrEmpty(shippingSize))
            {
                localPackageType = ShippingServiceUtils.IsSupportFlatEnvelope(new List <OrderItemRateInfo>()
                {
                    item
                })
                        ? PackageTypeCode.Flat
                        : PackageTypeCode.Regular;
            }

            decimal?caRateActualCostRegular = null;
            decimal?usRateActualCost        = null;

            if (rates != null && rates.Any())
            {
                var usPackageType = localPackageType.ToString();

                caRateActualCostRegular = rates.FirstOrDefault(r => r.Country == "CA" && r.PackageType == "Regular")?.Cost;
                usRateActualCost        = rates.FirstOrDefault(r => r.Country == "US" && r.PackageType == usPackageType)?.Cost;
            }
            if (!caRateActualCostRegular.HasValue ||
                !usRateActualCost.HasValue)
            {
                return(null);
            }

            var usIncome = usListingPrice + usShipping - usRateActualCost.Value;
            var newPrice = usIncome - (caShipping - caRateActualCostRegular.Value);

            newPrice = PriceHelper.ConvertFromUSD(newPrice, currency);

            return(newPrice);
        }