VirtoCommerce / vc-module-cart

Shopping cart management module
12 stars 15 forks source link

Cart returned without recalculated totals #127

Closed azapotoczny-forte closed 5 months ago

azapotoczny-forte commented 1 year ago

When fetching the shopping cart using CartModuleController.GetCartById the totals are set to zero. This endpoint loads the cart using CartResponseGroup.Full. However, the class ShoppingCartService seems to have a bug in the ProcessModel method:

protected override ShoppingCart ProcessModel(string responseGroup, ShoppingCartEntity entity, ShoppingCart model)
{
    //Calculate totals only for full responseGroup
    if (responseGroup == null)
    {
        _totalsCalculator.CalculateTotals(model);
    }
    model.ReduceDetails(responseGroup);
    return model;
}

I guess the code should look like this:

protected override ShoppingCart ProcessModel(string responseGroup, ShoppingCartEntity entity, ShoppingCart model)
{
    //Calculate totals only for full responseGroup
    if (responseGroup == null || responseGroup == CartResponseGroup.Full.ToString()) 
    {
        _totalsCalculator.CalculateTotals(model);
    }
    model.ReduceDetails(responseGroup);
    return model;
}

I assume that not specified response group (null) means Full.

mvktsk commented 1 year ago

Task https://virtocommerce.atlassian.net/browse/VP-8426 has been created

OlegoO commented 5 months ago

Created https://github.com/VirtoCommerce/vc-module-cart/pull/148

OlegoO commented 5 months ago

Fixed https://github.com/VirtoCommerce/vc-module-cart/releases/tag/3.809.0