Notify when stock limit reached on shopfront rather than silently capping

This commit is contained in:
Rohan Mitchell
2016-04-27 15:05:44 +10:00
parent f691636c75
commit 1220ff8a06
4 changed files with 22 additions and 2 deletions

View File

@@ -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)

View File

@@ -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}}"}

View File

@@ -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,

View File

@@ -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