mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Notify when stock limit reached on shopfront rather than silently capping
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
Darkswarm.directive "ofnOnHand", ->
|
||||
restrict: 'A'
|
||||
link: (scope, elem, attr) ->
|
||||
on_hand = parseInt(attr.ofnOnHand)
|
||||
elem.bind 'change', (e) ->
|
||||
if parseInt(elem.val()) > on_hand
|
||||
scope.$apply ->
|
||||
alert t('insufficient_stock', {on_hand: on_hand})
|
||||
elem.val(on_hand)
|
||||
@@ -7,6 +7,6 @@
|
||||
placeholder: "0",
|
||||
"ofn-disable-scroll" => true,
|
||||
"ng-model" => "variant.line_item.quantity",
|
||||
max: "{{variant.on_demand && 9999 || variant.count_on_hand }}",
|
||||
"ofn-on-hand" => "{{variant.on_demand && 9999 || variant.count_on_hand }}",
|
||||
"ng-disabled" => "!variant.on_demand && variant.count_on_hand == 0",
|
||||
name: "variants[{{variant.id}}]", id: "variants_{{variant.id}}"}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"ng-model" => "variant.line_item.quantity",
|
||||
placeholder: "{{'shop_variant_quantity_min' | t}}",
|
||||
"ofn-disable-scroll" => true,
|
||||
max: "{{variant.on_demand && 9999 || variant.count_on_hand }}",
|
||||
"ofn-on-hand" => "{{variant.on_demand && 9999 || variant.count_on_hand }}",
|
||||
name: "variants[{{variant.id}}]", id: "variants_{{variant.id}}"}
|
||||
%span.bulk-input
|
||||
%input.bulk.second{type: :number,
|
||||
|
||||
@@ -238,6 +238,17 @@ feature "As a consumer I want to shop with a distributor", js: true do
|
||||
Spree::LineItem.where(id: li).should be_empty
|
||||
end
|
||||
|
||||
it "alerts us when we enter a quantity greater than the stock available" do
|
||||
variant.update_attributes on_hand: 5
|
||||
visit shop_path
|
||||
|
||||
accept_alert 'Insufficient stock available, only 5 remaining' do
|
||||
fill_in "variants[#{variant.id}]", with: '10'
|
||||
end
|
||||
|
||||
page.should have_field "variants[#{variant.id}]", with: '5'
|
||||
end
|
||||
|
||||
describe "when a product goes out of stock just before it's added to the cart" do
|
||||
it "stops the attempt, shows an error message and refreshes the products asynchronously" do
|
||||
variant.update_attributes! on_hand: 0
|
||||
|
||||
Reference in New Issue
Block a user