awesto / django-shop

A Django based shop system
http://www.django-shop.org
BSD 3-Clause "New" or "Revised" License
3.17k stars 1.04k forks source link

Entries of cart.extra_rows are not removed only added via angular when modifying the cart #786

Closed moellering closed 4 years ago

moellering commented 4 years ago

Situation:

I have a use case where the shipping costs are only applied up to a specific subtotal value. When showing the modifiable cart the customer can increase and decrease the amount of products they want to order.

Expectation:

Once the subtotal exceeds X € the shipping costs should disappear. Once it falls below X € the shipping costs should be listed between subtotal and total.

Problem:

While the numbers in total and subtotal are correct, the shipping cost entry is still listed when the subtotal exceeds X €. Only a page reload (e.g. pressing F5) makes the shipping cost entry disappear. The other direction works fine: if there is no shipping fee shown removing items until the subtotal drops below X € makes the shipping cost appear.

Assumption:

The function refreshCart(cart) inside cart.js only adds extra rows but does not remove them:

function refreshCart(cart) {
    angular.extend($scope.cart.extra_rows, cart.extra_rows);
    $scope.cart.total_quantity = cart.total_quantity;
    $scope.cart.num_items = cart.num_items;
    $scope.cart.subtotal = cart.subtotal;
    $scope.cart.total = cart.total;
}