diff --git a/app/assets/javascripts/darkswarm/controllers/shop_variant_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/shop_variant_controller.js.coffee index 4b5b3e6a6e..94e2686c3e 100644 --- a/app/assets/javascripts/darkswarm/controllers/shop_variant_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/shop_variant_controller.js.coffee @@ -6,6 +6,8 @@ Darkswarm.controller "ShopVariantCtrl", ($scope, $modal, Cart) -> return if old_value[0] == null && new_value[0] == null Cart.adjust($scope.variant.line_item) + $scope.variant.line_item.quantity ||= 0 + if $scope.variant.product.group_buy $scope.$watch "variant.line_item.quantity", -> item = $scope.variant.line_item diff --git a/app/assets/javascripts/templates/partials/shop_variant_no_group_buy.html.haml b/app/assets/javascripts/templates/partials/shop_variant_no_group_buy.html.haml index bec3b64fdc..e0f6d16aae 100644 --- a/app/assets/javascripts/templates/partials/shop_variant_no_group_buy.html.haml +++ b/app/assets/javascripts/templates/partials/shop_variant_no_group_buy.html.haml @@ -1,11 +1,11 @@ .small-5.medium-3.large-3.columns.variant-quantity-column.text-right{"ng-if" => "::!variant.product.group_buy"} - .variant-quantity-inputs{ng: {if: "!variant.line_item.quantity"}} + .variant-quantity-inputs{ng: {if: "variant.line_item.quantity == 0"}} %button.add-variant{type: "button", ng: {click: "add(1)", disabled: "!canAdd(1)"}} {{ "js.shopfront.variant.add_to_cart" | t }} - .variant-quantity-inputs{ng: {if: "variant.line_item.quantity"}} - %button.variant-quantity{type: "button", ng: {click: "add(-1)"}}> + .variant-quantity-inputs{ng: {if: "variant.line_item.quantity != 0"}} + %button.variant-quantity{type: "button", ng: {click: "add(-1)", disabled: "!canAdd(-1)"}}> -# U+FF0D Fullwidth Hyphen-Minus - %input.variant-quantity{type: "number", min: "0", max: "{{ available() }}", ng: {model: "variant.line_item.quantity"}}> diff --git a/spec/javascripts/unit/darkswarm/controllers/checkout/shop_variant_controller_spec.js.coffee b/spec/javascripts/unit/darkswarm/controllers/checkout/shop_variant_controller_spec.js.coffee index c1d459dabf..3ca2e6394a 100644 --- a/spec/javascripts/unit/darkswarm/controllers/checkout/shop_variant_controller_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/controllers/checkout/shop_variant_controller_spec.js.coffee @@ -12,12 +12,15 @@ describe "ShopVariantCtrl", -> on_demand: true product: {group_buy: true} line_item: { - quantity: 0 - max_quantity: 0 + quantity: undefined + max_quantity: undefined } } ctrl = $controller 'ShopVariantCtrl', {$scope: scope, $modal: $modal, Cart: null} + it "initializes the quantity for shop display", -> + expect(scope.variant.line_item.quantity).toEqual 0 + it "adds an item to the cart", -> scope.add 1 expect(scope.variant.line_item.quantity).toEqual 1