Updating the commerce to 13.7.1 - OrderRepository.Save method

Vote:
 

Hi,

 When i update the qunatity of a line item, the following error occurs  on saving the cart. This product is provided with valid quantity and price but still this error occurs:

"Invalid order group total calculation"

The following code is used for updating the cart:

var lineItem = GetLineItem(cartDetail.Code);
if (lineItem != null)
{
status.Success = true;

if (cartDetail.Quantity > 0)
{
lineItem.Quantity = cartDetail.Quantity;
}
else
{
PurchaseOrderManager.RemoveLineItemFromOrder(Cart as OrderGroup, lineItem.LineItemId);
}
lineItem.SetCustomField(MetaFieldNames.LineComment, cartDetail.LineComment);
}
else
{
status.WarningMessage = "Can't find product with code " + cartDetail.Code;
updateActionStatus.Success = false;
}
updateActionStatus.CartActionStatuses.Add(status);

orderRepository.Save(cart);

Please help in resolving this issue.

Commerce Version Used : 13.7.1

Thanks in Advance.

#207911
Edited, Oct 08, 2019 14:33
Vote:
 

nik2911 ,

you don't have to create a new thread for same problem. I will delete your other (older) thread.
This look like you didn't set the price for the lineitem. You should call cart.UpdatePlacedPriceOrRemoveLineItems(), or even better OrderValidationService.ValidateOrder
Also you should not use PurchaseOrderManager.RemoveLineItemFromOrder to remove the lineitem, just remove it from Shipment.LineItems 

#207913
Edited, Oct 08, 2019 14:44
Vote:
 

Even after setting the price to the LineItem I get the following error

at EPiServer.Commerce.Marketing.Internal.MoneyExtensions.ThrowIfNegative(Money money, String validationErrorMessage)
at EPiServer.Commerce.Order.Calculator.DefaultOrderGroupCalculator.ValidateTotal(Money money)
at EPiServer.Commerce.Order.Calculator.DefaultOrderGroupCalculator.GetTotal(IOrderGroup orderGroup)
at EPiServer.Commerce.Order.Calculator.DefaultOrderGroupCalculator.GetOrderGroupTotals(IOrderGroup orderGroup)
at EPiServer.Commerce.Order.OrderGroupExtensions.CalculateTotals(OrderGroup orderGroup, IOrderGroupCalculator orderGroupCalculator, ReferenceConverter referenceConverter, IContentLoader contentLoader, ICatalogSystem catalogSystem, IRelationRepository relationRepository, LanguageResolver languageResolver)
at EPiServer.Commerce.Order.Internal.CartProvider.Save(ICart cart)
at EPiServer.Commerce.Order.Internal.DefaultOrderRepository.Save(IOrderGroup order)
at SnS.Infrastructure.Services.Implementations.CartService.SaveCartChanges(ICart cart)
at SnS.Infrastructure.Services.Implementations.CartService.UpdateCart(IEnumerable`1 cartDetails)
at SnS.Infrastructure.ApiControllers.CartController.<UpdateCart>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Threading.Tasks.TaskHelpersExtensions.<CastToObject>d__3`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()

#207920
Oct 08, 2019 15:45
Vote:
 

We use custom price logic and we have order promotions  applied to the cart also. Does this have any impact?

Once the promotions are removed and tested the products quantity are updating appropriately.Kindly help resolving this issue.

#207922
Edited, Oct 08, 2019 16:59
Vote:
 

Sounds like something you should contact developer support service for 

#207923
Oct 08, 2019 17:09
Vote:
 

In our case, we needed to apply discount on every update in cart.   cart.ApplyDiscounts(this.promotionEngine, new PromotionEngineSettings());

#317885
Feb 28, 2024 7:31
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.