From 87cf596a30848b6d2bd3e49acb1632618c85417c Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 17 Jan 2014 16:02:05 +1100 Subject: [PATCH] For a product with one or more on_demand variants, don't show 'On demand' at the product level --- .../admin/bulk_product_update.js.coffee | 4 ++++ .../spree/admin/products/bulk_edit.html.haml | 2 +- .../features/admin/bulk_product_update_spec.rb | 2 +- .../unit/bulk_product_update_spec.js.coffee | 18 ++++++++++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/admin/bulk_product_update.js.coffee b/app/assets/javascripts/admin/bulk_product_update.js.coffee index 8abe1ff17a..66bdc54916 100644 --- a/app/assets/javascripts/admin/bulk_product_update.js.coffee +++ b/app/assets/javascripts/admin/bulk_product_update.js.coffee @@ -316,6 +316,10 @@ productsApp.controller "AdminBulkProductsCtrl", [ Object.keys(product.variants).length > 0 + $scope.hasOnDemandVariants = (product) -> + (variant for id, variant of product.variants when variant.on_demand).length > 0 + + $scope.updateProducts = (productsToSubmit) -> $scope.displayUpdating() $http( diff --git a/app/views/spree/admin/products/bulk_edit.html.haml b/app/views/spree/admin/products/bulk_edit.html.haml index 2c4ab6995b..6fbdf258c5 100644 --- a/app/views/spree/admin/products/bulk_edit.html.haml +++ b/app/views/spree/admin/products/bulk_edit.html.haml @@ -121,7 +121,7 @@ %td{ 'ng-show' => 'columns.price.visible' } %input{ 'ng-model' => 'product.price', 'ofn-decimal' => :true, :name => 'price', 'ofn-track-product' => 'price', :type => 'text' } %td{ 'ng-show' => 'columns.on_hand.visible' } - %span{ 'ng-bind' => 'product.on_hand', :name => 'on_hand', 'ng-show' => 'hasVariants(product) || product.on_demand' } + %span{ 'ng-bind' => 'product.on_hand', :name => 'on_hand', 'ng-show' => '!hasOnDemandVariants(product) && (hasVariants(product) || product.on_demand)' } %input.field{ 'ng-model' => 'product.on_hand', :name => 'on_hand', 'ofn-track-product' => 'on_hand', 'ng-hide' => 'hasVariants(product) || product.on_demand', :type => 'number' } %td{ 'ng-show' => 'columns.available_on.visible' } %input{ 'ng-model' => 'product.available_on', :name => 'available_on', 'ofn-track-product' => 'available_on', 'datetimepicker' => 'product.available_on', type: "text" } diff --git a/spec/features/admin/bulk_product_update_spec.rb b/spec/features/admin/bulk_product_update_spec.rb index 351feb6c2c..352c3d14c7 100644 --- a/spec/features/admin/bulk_product_update_spec.rb +++ b/spec/features/admin/bulk_product_update_spec.rb @@ -148,7 +148,7 @@ feature %q{ visit '/admin/products/bulk_edit' first("a.view-variants").click - page.should have_selector "span[name='on_hand']", text: "On demand" + page.should_not have_selector "span[name='on_hand']", text: "On demand", visible: true page.should have_field "variant_on_hand", with: "4" page.should_not have_field "variant_on_hand", with: "", visible: true page.should have_selector "span[name='variant_on_hand']", text: "On demand" diff --git a/spec/javascripts/unit/bulk_product_update_spec.js.coffee b/spec/javascripts/unit/bulk_product_update_spec.js.coffee index 1be9cc2bb6..ceeadfa50f 100644 --- a/spec/javascripts/unit/bulk_product_update_spec.js.coffee +++ b/spec/javascripts/unit/bulk_product_update_spec.js.coffee @@ -555,6 +555,24 @@ describe "AdminBulkProductsCtrl", -> expect(scope.onHand(not_variants: [])).toEqual "error" + describe "determining whether a product has variants that are available on demand", -> + it "returns true when at least one variant does", -> + product = + variants: [ + {on_demand: false} + {on_demand: true} + ] + expect(scope.hasOnDemandVariants(product)).toBe(true) + + it "returns false otherwise", -> + product = + variants: [ + {on_demand: false} + {on_demand: false} + ] + expect(scope.hasOnDemandVariants(product)).toBe(false) + + describe "submitting products to be updated", -> describe "packing products", -> it "extracts variant_unit_with_scale into variant_unit and variant_unit_scale", ->