Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Found it... it looked fishy that at one point cart was properly populated(_checkoutCalculator.GetTotals), but at another not(GetCartItem), but the trick was that GetCartItem is just a delegate so there's no guarantees when it gets evaluated. A simple .ToList() at the end of the .Select() solved it.
protected virtual ICartResponse CreateCartResponse<TResponseType>(ICart cart, IPrincipal user, IDictionary<ILineItem, List<ValidationIssue>> validationIssues = null, IList<CouponCodeValidation> couponCodeValidationIssues = null) where TResponseType : ICartResponse, new()
{
if (cart == null)
{
return CreateEmptyCartResponse<TResponseType>();
}
List<ILineItem> list = cart.GetAllLineItems().ToList();
List<RewardDescription> list2 = (from r in ApplyDiscounts(cart).ToList()
where r.AppliedCoupon != null
select r).ToList();
List<CartItemValidation> removedLineitemValidationIssues = GetRemovedLineitemValidationIssues(list, validationIssues);
OrderTotals totals = _checkoutCalculator.GetTotals(cart);
Dictionary<string, object> dictionary = new Dictionary<string, object>();
if (cart.Properties != null)
{
foreach (object key in cart.Properties.Keys)
{
dictionary.Add(key.ToString(), cart.Properties[key]);
}
}
return new TResponseType
{
AppliedCouponCodes = list2.Select((RewardDescription r) => CreateCouponCodeResponse(cart, r)),
CouponCodeValidationIssues = GetCouponCodeValidations(list2, couponCodeValidationIssues?.ToList()),
Items = list.Select((ILineItem li) => GetCartItem(cart, li, validationIssues?.FirstOrDefault((KeyValuePair<ILineItem, List<ValidationIssue>> x) => x.Key.Code.Equals(li.Code)).Value)),
Currency = cart.Currency.CurrencyCode,
TotalQuantity = list.Sum((ILineItem li) => li.Quantity),
SubTotalPrice = totals.SubTotalPrice,
DiscountTotalPrice = totals.DiscountTotalPrice,
TaxTotal = totals.TaxTotal,
TotalPrice = totals.TotalPrice,
TotalPriceWithoutTax = totals.TotalPriceWithoutTax,
ShipmentTotalPrice = totals.ShipmentTotalPrice,
ShipmentDiscountPrice = totals.ShipmentDiscountPrice,
ShipmentTaxTotal = totals.ShipmentTaxTotal,
ValidationIssues = removedLineitemValidationIssues,
Properties = dictionary,
Name = cart.Name,
Notes = cart.Notes.Select((IOrderNote x) => CreateOrderNoteResponse(cart, x))
};
}
I am debugging on my local environment why _lineItemCalculator.GetDiscountedPrice(lineItem, cart.Currency); returns 0 for a discounted item. The calculator is the default one(DefaultLineItemCalculator). When I check in the database the entry amount is correctly set:
But in the code, i.e.
shows zero.
I also notice that 'IsSalesTaxUpToDate' is false so it seems some extended properties are set to defaults.