mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-31 06:31:41 +00:00
Show a modal when available stock levels have reduced
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
Darkswarm.factory 'Cart', (CurrentOrder, Variants, $timeout, $http, storage)->
|
||||
Darkswarm.factory 'Cart', (CurrentOrder, Variants, $timeout, $http, $modal, $rootScope, storage)->
|
||||
# Handles syncing of current cart/order state to server
|
||||
new class Cart
|
||||
dirty: false
|
||||
@@ -41,21 +41,30 @@ Darkswarm.factory 'Cart', (CurrentOrder, Variants, $timeout, $http, storage)->
|
||||
@update_running = false
|
||||
|
||||
compareAndNotifyStockLevels: (stockLevels) =>
|
||||
scope = $rootScope.$new(true)
|
||||
scope.variants = []
|
||||
|
||||
# TODO: These changes to quantity/max_quantity trigger another cart update, which
|
||||
# is unnecessary.
|
||||
|
||||
for li in @line_items_present()
|
||||
if !stockLevels[li.variant.id]?
|
||||
alert "Variant out of stock: #{li.variant.id}"
|
||||
li.quantity = 0
|
||||
li.max_quantity = 0 if li.max_quantity?
|
||||
li.variant.count_on_hand = 0
|
||||
scope.variants.push li.variant
|
||||
else
|
||||
if stockLevels[li.variant.id].quantity < li.quantity
|
||||
alert "Variant quantity reduced: #{li.variant.id}"
|
||||
li.quantity = stockLevels[li.variant.id].quantity
|
||||
scope.variants.push li.variant
|
||||
if stockLevels[li.variant.id].max_quantity < li.max_quantity
|
||||
alert "Variant max_quantity reduced: #{li.variant.id}"
|
||||
li.max_quantity = stockLevels[li.variant.id].max_quantity
|
||||
scope.variants.push li.variant
|
||||
li.variant.count_on_hand = stockLevels[li.variant.id].on_hand
|
||||
|
||||
if scope.variants.length > 0
|
||||
$modal.open(templateUrl: "out_of_stock.html", scope: scope, windowClass: 'out-of-stock-modal')
|
||||
|
||||
popQueue: =>
|
||||
@update_enqueued = false
|
||||
@scheduleUpdate()
|
||||
|
||||
10
app/assets/javascripts/templates/out_of_stock.html.haml
Normal file
10
app/assets/javascripts/templates/out_of_stock.html.haml
Normal file
@@ -0,0 +1,10 @@
|
||||
%h3 Reduced stock available
|
||||
|
||||
%p While you've been shopping, the stock levels for one or more of the products in your cart have reduced. Here's what's changed:
|
||||
|
||||
%p{'ng-repeat' => "v in variants"}
|
||||
%em {{ v.name_to_display }} - {{ v.unit_to_display }}
|
||||
%span{'ng-if' => "v.count_on_hand == 0"}
|
||||
is now out of stock.
|
||||
%span{'ng-if' => "v.count_on_hand > 0"}
|
||||
now only has {{ v.count_on_hand }} remaining.
|
||||
Reference in New Issue
Block a user