mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-30 21:27:17 +00:00
Don't resubmit the whole cart contents for no reason.
There's a couple of places where this was causing a cart update submission where it wasn't needed, eg the items had not actually changed. The conditional here was designed to stop that from happening, but it was actually passing every time (the conditional logic was not actually catching the case it was supposed to). This is really expensive!
This commit is contained in:
@@ -1,9 +1,5 @@
|
||||
Darkswarm.controller "ShopVariantCtrl", ($scope, $modal, Cart) ->
|
||||
$scope.$watchGroup [
|
||||
'variant.line_item.quantity',
|
||||
'variant.line_item.max_quantity'
|
||||
], (new_value, old_value) ->
|
||||
return if old_value[0] == null && new_value[0] == null
|
||||
$scope.updateCart = (line_item) ->
|
||||
Cart.adjust($scope.variant.line_item)
|
||||
|
||||
$scope.variant.line_item.quantity ||= 0
|
||||
@@ -44,10 +40,12 @@ Darkswarm.controller "ShopVariantCtrl", ($scope, $modal, Cart) ->
|
||||
$scope.add = (quantity) ->
|
||||
item = $scope.variant.line_item
|
||||
item.quantity = $scope.sanitizedQuantity() + quantity
|
||||
$scope.updateCart(item)
|
||||
|
||||
$scope.addMax = (quantity) ->
|
||||
item = $scope.variant.line_item
|
||||
item.max_quantity = $scope.sanitizedMaxQuantity() + quantity
|
||||
$scope.updateCart(item)
|
||||
|
||||
$scope.canAdd = (quantity) ->
|
||||
wantedQuantity = $scope.sanitizedQuantity() + quantity
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
describe "ShopVariantCtrl", ->
|
||||
ctrl = null
|
||||
scope = null
|
||||
CartMock = null
|
||||
|
||||
beforeEach ->
|
||||
module 'Darkswarm'
|
||||
@@ -16,7 +17,10 @@ describe "ShopVariantCtrl", ->
|
||||
max_quantity: undefined
|
||||
}
|
||||
}
|
||||
ctrl = $controller 'ShopVariantCtrl', {$scope: scope, $modal: $modal, Cart: null}
|
||||
CartMock =
|
||||
adjust: ->
|
||||
true
|
||||
ctrl = $controller 'ShopVariantCtrl', {$scope: scope, $modal: $modal, Cart: CartMock}
|
||||
|
||||
it "initializes the quantity for shop display", ->
|
||||
expect(scope.variant.line_item.quantity).toEqual 0
|
||||
|
||||
Reference in New Issue
Block a user