Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.18 KB | None | 0 0
  1. /// <summary>
  2. /// Gets the cart items.
  3. /// Apply Discount promo to cart items if required
  4. /// </summary>
  5. /// <param name="cartId"></param>
  6. /// <param name="currencyId">The currency identifier.</param>
  7. /// <param name="promoCodeValue"></param>
  8. /// <param name="isMobile"></param>
  9. /// <returns></returns>
  10. public List<ShoppingCartItemDto> GetCartItems(int cartId, int currencyId, string promoCodeValue = null, bool isMobile = false)
  11. {
  12. var shoppingcartitems = new List<ShoppingCartItemDto>();
  13. var shoppiningCartItems = _bookingService.GetShoppingCartItems(cartId);
  14. try
  15. {
  16. string displayCurrencyCode = DataAccess.DataAccess.GetCurrency(currencyId).Label;
  17.  
  18. var userPromoCodes = DataAccess.DataAccess.GetPromoCodeDiscountList(promoCodeValue);
  19.  
  20. foreach (var item in shoppiningCartItems)
  21. {
  22. AppLogger.Debug("item serialized: " + JsonConvert.SerializeObject(item));
  23. //set the productprice and salesprice
  24. var paxChild = item.totChild ?? 0;
  25. var paxInfants = item.totInfants ?? 0;
  26.  
  27. //get option price (use cache value if available)
  28. var tourOptionPriceCondition = DataAccess.DataAccess.GetTourOptionTotalPrice(item.totAdults, paxChild, 0, paxInfants, item.PriceId, item.TourDate, true);
  29. var origProductPrice = tourOptionPriceCondition.Totalprice;
  30. AppLogger.Debug($"[Checkout.GetCartItems] GetTourOptionTotalPrice.Totalprice: '{tourOptionPriceCondition.Totalprice:0.00}'");
  31. var totalProductPrice = userPromoCodes.Any()
  32. ? userPromoCodes.ApplyDiscount2Price(item.ProductId, tourOptionPriceCondition.Totalprice)
  33. : tourOptionPriceCondition.Totalprice;
  34. item.BookingDiscount = Convert.ToDecimal(Math.Round((origProductPrice - totalProductPrice), 2));
  35. item.PromoCode = promoCodeValue;
  36. AppLogger.Debug($"+ ProductPriceDiscount: '{item.BookingDiscount:0.00}'");
  37. item.ProductPrice = (decimal)totalProductPrice;
  38. item.SalePrice = (decimal)DataAccess.DataAccess.MultiCurrency((double)item.ProductPrice, item.ProductCurrency, displayCurrencyCode);
  39. item.SalesCurrency = displayCurrencyCode;
  40.  
  41. var priceInfo = new ProductPriceDto
  42. {
  43. PriceId = item.PriceId,
  44. ProductPrices = Helper.FormatAllCurrenciesAndConvert((double)item.ProductPrice, item.ProductCurrency),
  45. ProductSalesPrices = Helper.FormatAllCurrenciesAndConvert((double)item.SalePrice, item.SalesCurrency),
  46. TotAdults = item.totAdults,
  47. TotChild = item.totChild ?? 0,
  48. TotInfants = item.totInfants ?? 0,
  49. SalePricesDiscount = Helper.FormatAllCurrenciesAndConvert(DataAccess.DataAccess.MultiCurrency((double)item.BookingDiscount, item.ProductCurrency, item.SalesCurrency), item.SalesCurrency)
  50. };
  51. AppLogger.Info("priceInfo: " + JsonConvert.SerializeObject(priceInfo));
  52. var content = _umbracoService.GetUmbracoCache();
  53. var tourDetail = content.XPathSelectElement($"tours/tour[@id={item.externalId}]");
  54. AppLogger.Info("tourDetail: " + JsonConvert.SerializeObject(priceInfo));
  55. var cwWebSvr = new DataAccess.websrvCW.ServiceClient();
  56. var tourData = cwWebSvr.getTourListFullCW_DateSearch(_citywondersSiteId, item.ProductId.ToString(), DateTime.MinValue, DateTime.MaxValue, DefaultUserId, RomeCityId, VaticanFlag).FirstOrDefault();
  57. AppLogger.Info("tourData: " + tourData);
  58. if (tourDetail != null)
  59. {
  60. priceInfo.SaleStrikeoutTotalPricesAdult = Helper.FormatAllCurrenciesAndConvert(tourDetail.XPathSelectElement("saleStrikeoutPriceAdult").Parse<double>() * (double)priceInfo.TotAdults, item.ProductCurrency);
  61. priceInfo.SaleStrikeoutTotalPricesChild = Helper.FormatAllCurrenciesAndConvert(tourDetail.XPathSelectElement("saleStrikeoutPriceChild").Parse<double>() * (double)priceInfo.TotChild, item.ProductCurrency);
  62. priceInfo.SaleStrikeoutTotalPricesInfant = Helper.FormatAllCurrenciesAndConvert(tourDetail.XPathSelectElement("saleStrikeoutPriceInfant").Parse<double>() * (double)priceInfo.TotInfants, item.ProductCurrency);
  63. }
  64.  
  65.  
  66. // set per PAX price including discount.
  67. AppLogger.Info("promoCodeValue: " + promoCodeValue);
  68. AppLogger.Info("userPromoCodes: " + userPromoCodes);
  69. if (Helper.IsPromoCodeValid(promoCodeValue, userPromoCodes))
  70. {
  71. decimal discountPercentage = item.BookingDiscount / (item.ProductPrice + item.BookingDiscount);
  72. priceInfo.PricesBase = Helper.FormatAllCurrenciesAndConvert((double)(item.priceBase - item.priceBase * discountPercentage), item.ProductCurrency);
  73. priceInfo.PricesAdult = Helper.FormatAllCurrenciesAndConvert((double)(item.priceAdult - item.priceAdult * discountPercentage), item.ProductCurrency);
  74. priceInfo.PricesChild = Helper.FormatAllCurrenciesAndConvert((double)(item.priceChild - item.priceChild * discountPercentage), item.ProductCurrency);
  75. priceInfo.PricesInfant = Helper.FormatAllCurrenciesAndConvert((double)(item.priceInfant - item.priceInfant * discountPercentage), item.ProductCurrency);
  76. }
  77. else
  78. {
  79. priceInfo.PricesBase = Helper.FormatAllCurrenciesAndConvert((double)item.priceBase, item.ProductCurrency);
  80. priceInfo.PricesAdult = Helper.FormatAllCurrenciesAndConvert((double)item.priceAdult, item.ProductCurrency);
  81. priceInfo.PricesChild = Helper.FormatAllCurrenciesAndConvert((double)item.priceChild, item.ProductCurrency);
  82. priceInfo.PricesInfant = Helper.FormatAllCurrenciesAndConvert((double)item.priceInfant, item.ProductCurrency);
  83. }
  84. priceInfo.PaxPerBase = item.paxPerBase;
  85. var cityId = tourDetail.XPathSelectElement("citylist").Parse<int>();
  86. var city = content.XPathSelectElement($"cities/city[@id={cityId}]/cityName");
  87. var cityName = city.Parse<string>().DeserializeXElement<string>(DataAccess.DataAccess.Defaultculture);
  88. shoppingcartitems.Add(new ShoppingCartItemDto
  89. {
  90. CityName = cityName,
  91. ReviewAverage = tourData != null ? (double)tourData?.tourAvg : 0,
  92. ReviewCount = tourData?.numeroFeedback ?? 0, //if null use 0
  93. InfantNotAllowed = tourDetail.XPathSelectElement("infantNotAllowed").Parse<bool>(),
  94. IsAdultOnly = tourDetail.XPathSelectElement("adultOnly").Parse<bool>(),
  95. PriceInfo = priceInfo,
  96. CartId = item.CartId,
  97. ProductId = item.ProductId,
  98. PriceId = item.PriceId,
  99. ProductCurrency = item.ProductCurrency,
  100. SalesCurrency = item.SalesCurrency,
  101. TourDate = item.TourDate.ToString("yyyy-MM-dd"),
  102. EuroPrice = item.ProductCurrency == "EUR" ? (double)item.ProductPrice : DataAccess.DataAccess.MultiCurrency((double)item.ProductPrice, item.ProductCurrency, "EUR"),
  103. BookingDiscount = item.BookingDiscount,
  104. SalePriceDiscount = (decimal)DataAccess.DataAccess.MultiCurrency((double)item.BookingDiscount, item.ProductCurrency, item.SalesCurrency),
  105. PromoCode = item.PromoCode,
  106. TotAdults = item.totAdults,
  107. TotChild = item.totChild,
  108. TotInfants = item.totInfants,
  109. ProductThumb = int.Parse(item.ProductThumb).GetCropImage(isMobile, (int)ImageEnum.Checkout),
  110. ProductThumbMini = int.Parse(item.ProductThumb).GetCropImage(isMobile, (int)ImageEnum.MiniCart),
  111. PriceStartTime = item.PriceStartTime.TimeSpanTo24HrString((int)HourEnum.HourMin),
  112. ProductTitle = item.ProductTitle,
  113. ProductUrl = item.ProductURL,
  114. NodeId = item.externalId,
  115. SiteId = item.SiteID
  116. });
  117. }
  118. return shoppingcartitems;
  119. }
  120. catch (Exception ex)
  121. {
  122. AppLogger.Error($"Cart [GetCartItems] error: {ex.Message}");
  123. throw new Exception(ex.Message);
  124. }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement