Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Gets the cart items.
- /// Apply Discount promo to cart items if required
- /// </summary>
- /// <param name="cartId"></param>
- /// <param name="currencyId">The currency identifier.</param>
- /// <param name="promoCodeValue"></param>
- /// <param name="isMobile"></param>
- /// <returns></returns>
- public List<ShoppingCartItemDto> GetCartItems(int cartId, int currencyId, string promoCodeValue = null, bool isMobile = false)
- {
- var shoppingcartitems = new List<ShoppingCartItemDto>();
- var shoppiningCartItems = _bookingService.GetShoppingCartItems(cartId);
- try
- {
- string displayCurrencyCode = DataAccess.DataAccess.GetCurrency(currencyId).Label;
- var userPromoCodes = DataAccess.DataAccess.GetPromoCodeDiscountList(promoCodeValue);
- foreach (var item in shoppiningCartItems)
- {
- AppLogger.Debug("item serialized: " + JsonConvert.SerializeObject(item));
- //set the productprice and salesprice
- var paxChild = item.totChild ?? 0;
- var paxInfants = item.totInfants ?? 0;
- //get option price (use cache value if available)
- var tourOptionPriceCondition = DataAccess.DataAccess.GetTourOptionTotalPrice(item.totAdults, paxChild, 0, paxInfants, item.PriceId, item.TourDate, true);
- var origProductPrice = tourOptionPriceCondition.Totalprice;
- AppLogger.Debug($"[Checkout.GetCartItems] GetTourOptionTotalPrice.Totalprice: '{tourOptionPriceCondition.Totalprice:0.00}'");
- var totalProductPrice = userPromoCodes.Any()
- ? userPromoCodes.ApplyDiscount2Price(item.ProductId, tourOptionPriceCondition.Totalprice)
- : tourOptionPriceCondition.Totalprice;
- item.BookingDiscount = Convert.ToDecimal(Math.Round((origProductPrice - totalProductPrice), 2));
- item.PromoCode = promoCodeValue;
- AppLogger.Debug($"+ ProductPriceDiscount: '{item.BookingDiscount:0.00}'");
- item.ProductPrice = (decimal)totalProductPrice;
- item.SalePrice = (decimal)DataAccess.DataAccess.MultiCurrency((double)item.ProductPrice, item.ProductCurrency, displayCurrencyCode);
- item.SalesCurrency = displayCurrencyCode;
- var priceInfo = new ProductPriceDto
- {
- PriceId = item.PriceId,
- ProductPrices = Helper.FormatAllCurrenciesAndConvert((double)item.ProductPrice, item.ProductCurrency),
- ProductSalesPrices = Helper.FormatAllCurrenciesAndConvert((double)item.SalePrice, item.SalesCurrency),
- TotAdults = item.totAdults,
- TotChild = item.totChild ?? 0,
- TotInfants = item.totInfants ?? 0,
- SalePricesDiscount = Helper.FormatAllCurrenciesAndConvert(DataAccess.DataAccess.MultiCurrency((double)item.BookingDiscount, item.ProductCurrency, item.SalesCurrency), item.SalesCurrency)
- };
- AppLogger.Info("priceInfo: " + JsonConvert.SerializeObject(priceInfo));
- var content = _umbracoService.GetUmbracoCache();
- var tourDetail = content.XPathSelectElement($"tours/tour[@id={item.externalId}]");
- AppLogger.Info("tourDetail: " + JsonConvert.SerializeObject(priceInfo));
- var cwWebSvr = new DataAccess.websrvCW.ServiceClient();
- var tourData = cwWebSvr.getTourListFullCW_DateSearch(_citywondersSiteId, item.ProductId.ToString(), DateTime.MinValue, DateTime.MaxValue, DefaultUserId, RomeCityId, VaticanFlag).FirstOrDefault();
- AppLogger.Info("tourData: " + tourData);
- if (tourDetail != null)
- {
- priceInfo.SaleStrikeoutTotalPricesAdult = Helper.FormatAllCurrenciesAndConvert(tourDetail.XPathSelectElement("saleStrikeoutPriceAdult").Parse<double>() * (double)priceInfo.TotAdults, item.ProductCurrency);
- priceInfo.SaleStrikeoutTotalPricesChild = Helper.FormatAllCurrenciesAndConvert(tourDetail.XPathSelectElement("saleStrikeoutPriceChild").Parse<double>() * (double)priceInfo.TotChild, item.ProductCurrency);
- priceInfo.SaleStrikeoutTotalPricesInfant = Helper.FormatAllCurrenciesAndConvert(tourDetail.XPathSelectElement("saleStrikeoutPriceInfant").Parse<double>() * (double)priceInfo.TotInfants, item.ProductCurrency);
- }
- // set per PAX price including discount.
- AppLogger.Info("promoCodeValue: " + promoCodeValue);
- AppLogger.Info("userPromoCodes: " + userPromoCodes);
- if (Helper.IsPromoCodeValid(promoCodeValue, userPromoCodes))
- {
- decimal discountPercentage = item.BookingDiscount / (item.ProductPrice + item.BookingDiscount);
- priceInfo.PricesBase = Helper.FormatAllCurrenciesAndConvert((double)(item.priceBase - item.priceBase * discountPercentage), item.ProductCurrency);
- priceInfo.PricesAdult = Helper.FormatAllCurrenciesAndConvert((double)(item.priceAdult - item.priceAdult * discountPercentage), item.ProductCurrency);
- priceInfo.PricesChild = Helper.FormatAllCurrenciesAndConvert((double)(item.priceChild - item.priceChild * discountPercentage), item.ProductCurrency);
- priceInfo.PricesInfant = Helper.FormatAllCurrenciesAndConvert((double)(item.priceInfant - item.priceInfant * discountPercentage), item.ProductCurrency);
- }
- else
- {
- priceInfo.PricesBase = Helper.FormatAllCurrenciesAndConvert((double)item.priceBase, item.ProductCurrency);
- priceInfo.PricesAdult = Helper.FormatAllCurrenciesAndConvert((double)item.priceAdult, item.ProductCurrency);
- priceInfo.PricesChild = Helper.FormatAllCurrenciesAndConvert((double)item.priceChild, item.ProductCurrency);
- priceInfo.PricesInfant = Helper.FormatAllCurrenciesAndConvert((double)item.priceInfant, item.ProductCurrency);
- }
- priceInfo.PaxPerBase = item.paxPerBase;
- var cityId = tourDetail.XPathSelectElement("citylist").Parse<int>();
- var city = content.XPathSelectElement($"cities/city[@id={cityId}]/cityName");
- var cityName = city.Parse<string>().DeserializeXElement<string>(DataAccess.DataAccess.Defaultculture);
- shoppingcartitems.Add(new ShoppingCartItemDto
- {
- CityName = cityName,
- ReviewAverage = tourData != null ? (double)tourData?.tourAvg : 0,
- ReviewCount = tourData?.numeroFeedback ?? 0, //if null use 0
- InfantNotAllowed = tourDetail.XPathSelectElement("infantNotAllowed").Parse<bool>(),
- IsAdultOnly = tourDetail.XPathSelectElement("adultOnly").Parse<bool>(),
- PriceInfo = priceInfo,
- CartId = item.CartId,
- ProductId = item.ProductId,
- PriceId = item.PriceId,
- ProductCurrency = item.ProductCurrency,
- SalesCurrency = item.SalesCurrency,
- TourDate = item.TourDate.ToString("yyyy-MM-dd"),
- EuroPrice = item.ProductCurrency == "EUR" ? (double)item.ProductPrice : DataAccess.DataAccess.MultiCurrency((double)item.ProductPrice, item.ProductCurrency, "EUR"),
- BookingDiscount = item.BookingDiscount,
- SalePriceDiscount = (decimal)DataAccess.DataAccess.MultiCurrency((double)item.BookingDiscount, item.ProductCurrency, item.SalesCurrency),
- PromoCode = item.PromoCode,
- TotAdults = item.totAdults,
- TotChild = item.totChild,
- TotInfants = item.totInfants,
- ProductThumb = int.Parse(item.ProductThumb).GetCropImage(isMobile, (int)ImageEnum.Checkout),
- ProductThumbMini = int.Parse(item.ProductThumb).GetCropImage(isMobile, (int)ImageEnum.MiniCart),
- PriceStartTime = item.PriceStartTime.TimeSpanTo24HrString((int)HourEnum.HourMin),
- ProductTitle = item.ProductTitle,
- ProductUrl = item.ProductURL,
- NodeId = item.externalId,
- SiteId = item.SiteID
- });
- }
- return shoppingcartitems;
- }
- catch (Exception ex)
- {
- AppLogger.Error($"Cart [GetCartItems] error: {ex.Message}");
- throw new Exception(ex.Message);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement