mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-05 22:26:07 +00:00
Fix users removing last item of confirmed order on /cart page
This commit is contained in:
committed by
Andy Brett
parent
b3610e035d
commit
651bdad7b9
@@ -1,12 +1,19 @@
|
||||
Darkswarm.controller "EditBoughtOrderController", ($scope, $resource, Cart) ->
|
||||
Darkswarm.controller "EditBoughtOrderController", ($scope, $resource, $timeout, Cart) ->
|
||||
$scope.showBought = false
|
||||
$scope.removeEnabled = true
|
||||
|
||||
$scope.deleteLineItem = (id) ->
|
||||
params = {id: id}
|
||||
success = (response) ->
|
||||
$(".line-item-" + id).remove()
|
||||
Cart.removeFinalisedLineItem(id)
|
||||
fail = (error) ->
|
||||
console.log error
|
||||
if Cart.check_last_finalised_item()
|
||||
$scope.removeEnabled = false
|
||||
$timeout (->
|
||||
$scope.removeEnabled = true
|
||||
), 10000
|
||||
else
|
||||
params = {id: id}
|
||||
success = (response) ->
|
||||
$(".line-item-" + id).remove()
|
||||
Cart.removeFinalisedLineItem(id)
|
||||
fail = (error) ->
|
||||
console.log error
|
||||
|
||||
$resource("/line_items/:id").delete(params, success, fail)
|
||||
$resource("/line_items/:id").delete(params, success, fail)
|
||||
|
||||
@@ -115,6 +115,12 @@ Darkswarm.factory 'Cart', (CurrentOrder, Variants, $timeout, $http, $modal, $roo
|
||||
@line_items = []
|
||||
localStorageService.clearAll() # One day this will have to be moar GRANULAR
|
||||
|
||||
check_last_finalised_item: =>
|
||||
if @line_items_finalised.length == 1
|
||||
Messages.error(t 'orders_cannot_remove_the_final_item')
|
||||
|
||||
@line_items_finalised.length == 1
|
||||
|
||||
removeFinalisedLineItem: (id) =>
|
||||
@line_items_finalised = @line_items_finalised.filter (item) ->
|
||||
item.id != id
|
||||
|
||||
@@ -28,5 +28,5 @@
|
||||
= line_item.display_amount_with_adjustments.to_html unless line_item.quantity.nil?
|
||||
|
||||
%td.bought-item-delete.text-center
|
||||
%a{ng: {click: "deleteLineItem(#{line_item.id})"}}
|
||||
%a{ng: {click: "removeEnabled && deleteLineItem(#{line_item.id})"}}
|
||||
%i.ofn-i_026-trash
|
||||
|
||||
@@ -222,6 +222,16 @@ describe 'Cart service', ->
|
||||
expect(li.quantity).toEqual 1
|
||||
expect(li.max_quantity).toEqual 1
|
||||
|
||||
describe "when modifying a confirmed order", ->
|
||||
it "displays flash error when attempting to remove final item", ->
|
||||
spyOn(RailsFlashLoader, 'loadFlash')
|
||||
li = {variant: {id: 1}, quantity: 3}
|
||||
Cart.line_items_finalised = [li]
|
||||
Cart.check_last_finalised_item()
|
||||
expect(RailsFlashLoader.loadFlash).toHaveBeenCalledWith(
|
||||
{error: t 'orders_cannot_remove_the_final_item'}
|
||||
)
|
||||
|
||||
it "pops the queue", ->
|
||||
Cart.update_enqueued = true
|
||||
spyOn(Cart, 'scheduleUpdate')
|
||||
|
||||
Reference in New Issue
Block a user