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);
        }
Esempio n. 2
0
        public decimal?GetMarketDefaultPrice(decimal sourcePrice,
                                             MarketType market,
                                             string marketplaceId,
                                             IDictionary <string, decimal?> rateForMarketplace)
        {
            var defaultPrice =
                RateHelper.CalculateForMarket(market,
                                              marketplaceId,
                                              sourcePrice,
                                              rateForMarketplace[MarketplaceKeeper.AmazonComMarketplaceId],
                                              rateForMarketplace[MarketplaceKeeper.AmazonCaMarketplaceId],
                                              rateForMarketplace[MarketplaceKeeper.AmazonUkMarketplaceId],
                                              rateForMarketplace[MarketplaceKeeper.AmazonAuMarketplaceId],
                                              RateService.GetMarketShippingAmount(MarketType.Amazon, MarketplaceKeeper.AmazonComMarketplaceId),
                                              RateService.GetMarketShippingAmount((MarketType)market, marketplaceId),
                                              RateService.GetMarketExtraAmount((MarketType)market, marketplaceId));

            return(defaultPrice);
        }