diff --git a/app/assets/stylesheets/darkswarm/shop.css.sass b/app/assets/stylesheets/darkswarm/shop.css.sass index b949227655..12b081335d 100644 --- a/app/assets/stylesheets/darkswarm/shop.css.sass +++ b/app/assets/stylesheets/darkswarm/shop.css.sass @@ -102,10 +102,12 @@ input margin: 0 width: 8em + display: inline .columns padding-top: 1em padding-bottom: 1em + line-height: 2.4em .row.summary, .row.variants @include csstrans diff --git a/app/models/spree/variant_decorator.rb b/app/models/spree/variant_decorator.rb index 2ffb07d4e1..f2b641b680 100644 --- a/app/models/spree/variant_decorator.rb +++ b/app/models/spree/variant_decorator.rb @@ -45,6 +45,14 @@ Spree::Variant.class_eval do self.option_values.destroy ovs end + def name_to_display + display_name || product.name + end + + def unit_to_display + display_as || options_text + end + private diff --git a/app/views/shop/products.rabl b/app/views/shop/products.rabl index b1567a311a..eb5d62644a 100644 --- a/app/views/shop/products.rabl +++ b/app/views/shop/products.rabl @@ -25,7 +25,7 @@ child :primary_taxon => :primary_taxon do end child :master => :master do - attributes :id, :is_master, :count_on_hand, :options_text, :count_on_hand, :on_demand + attributes :id, :is_master, :count_on_hand, :name_to_display, :unit_to_display, :count_on_hand, :on_demand child :images => :images do attributes :id, :alt node do |img| @@ -40,7 +40,8 @@ node :variants do |product| {id: v.id, is_master: v.is_master, count_on_hand: v.count_on_hand, - options_text: v.options_text, + name_to_display: v.name_to_display, + unit_to_display: v.unit_to_display, on_demand: v.on_demand, price: v.price_with_fees(current_distributor, current_order_cycle), images: v.images.map { |i| {id: i.id, alt: i.alt, small_url: i.attachment.url(:small, false)} } diff --git a/app/views/shop/products/_master.html.haml b/app/views/shop/products/_master.html.haml index e8972082dd..59c0911cfd 100644 --- a/app/views/shop/products/_master.html.haml +++ b/app/views/shop/products/_master.html.haml @@ -3,37 +3,40 @@   .small-4.columns - {{ product.master.options_text }} + {{ product.master.name_to_display }} -# WITHOUT GROUP BUY .small-5.columns{"bo-if" => "!product.group_buy"} %input{type: :number, min: 0, + placeholder: "0", "ofn-disable-scroll" => true, max: "{{product.on_demand && 9999 || product.count_on_hand }}", name: "variants[{{product.master.id}}]", id: "variants_{{product.master.id}}", "ng-model" => "product.quantity"} + {{ product.master.unit_to_display }} -# WITH GROUP BUY .small-2.columns{"bo-if" => "product.group_buy"} %input{type: :number, min: 0, + placeholder: "min", "ofn-disable-scroll" => true, max: "{{product.on_demand && 9999 || product.count_on_hand }}", name: "variants[{{product.master.id}}]", id: "variants_{{product.master.id}}", "ng-model" => "product.quantity"} - (min) .small-3.columns{"bo-if" => "product.group_buy"} %input{type: :number, min: 0, + placeholder: "max", "ofn-disable-scroll" => true, max: "{{product.on_demand && 9999 || product.count_on_hand }}", name: "variant_attributes[{{product.master.id}}][max_quantity]", "ng-model" => "product.max_quantity"} - (max) + {{ product.master.unit_to_display }} .small-2.columns.text-right {{ product.price | currency }} diff --git a/app/views/shop/products/_variants.html.haml b/app/views/shop/products/_variants.html.haml index 6751f8c62c..1863bf7c1c 100644 --- a/app/views/shop/products/_variants.html.haml +++ b/app/views/shop/products/_variants.html.haml @@ -6,37 +6,40 @@   .small-4.columns - {{ variant.options_text }} + {{ variant.name_to_display }} -# WITHOUT GROUP BUY .small-5.columns{"bo-if" => "!product.group_buy"} %input{type: :number, value: nil, min: 0, + placeholder: "0", "ofn-disable-scroll" => true, max: "{{variant.on_demand && 9999 || variant.count_on_hand }}", name: "variants[{{variant.id}}]", id: "variants_{{variant.id}}", "bo-model" => "variant.quantity"} + {{ variant.unit_to_display }} -# WITH GROUP BUY .small-2.columns{"bo-if" => "product.group_buy"} %input{type: :number, value: nil, min: 0, + placeholder: "min", "ofn-disable-scroll" => true, max: "{{variant.on_demand && 9999 || variant.count_on_hand }}", name: "variants[{{variant.id}}]", id: "variants_{{variant.id}}", "bo-model" => "variant.quantity"} - (min) .small-3.columns{"bo-if" => "product.group_buy"} %input{type: :number, min: 0, + placeholder: "max", "ofn-disable-scroll" => true, max: "{{variant.on_demand && 9999 || variant.count_on_hand }}", name: "variant_attributes[{{variant.id}}][max_quantity]", "ng-model" => "variant.max_quantity"} - (max) + {{ variant.unit_to_display }} .small-2.columns.text-right.price {{ variant.price | currency }} diff --git a/spec/features/consumer/shopping/shopping_spec.rb b/spec/features/consumer/shopping/shopping_spec.rb index 78937ecb47..a1adde5ee0 100644 --- a/spec/features/consumer/shopping/shopping_spec.rb +++ b/spec/features/consumer/shopping/shopping_spec.rb @@ -64,6 +64,8 @@ feature "As a consumer I want to shop with a distributor", js: true do end it "shows products after selecting an order cycle" do + product.master.update_attribute(:display_name, "kitten") + product.master.update_attribute(:display_as, "rabbit") exchange1.variants << product.master ## add product to exchange visit shop_path page.should_not have_content product.name @@ -74,6 +76,9 @@ feature "As a consumer I want to shop with a distributor", js: true do page.should have_content "Next order closing in 2 days" Spree::Order.last.order_cycle.should == oc1 page.should have_content product.name + save_screenshot "/Users/willmarshall/Desktop/shop.png" + page.should have_content product.master.display_name + page.should have_content product.master.display_as end end end diff --git a/spec/models/spree/product_spec.rb b/spec/models/spree/product_spec.rb index 08939532f6..47b7fa165e 100644 --- a/spec/models/spree/product_spec.rb +++ b/spec/models/spree/product_spec.rb @@ -579,5 +579,6 @@ module Spree product.taxons.should == [product.primary_taxon] end end + end end diff --git a/spec/models/spree/variant_spec.rb b/spec/models/spree/variant_spec.rb index 69002d2aa4..bf13cf978c 100644 --- a/spec/models/spree/variant_spec.rb +++ b/spec/models/spree/variant_spec.rb @@ -124,6 +124,31 @@ module Spree end describe "unit value/description" do + describe "getting name for display" do + it "returns display_name if present" do + v = create(:variant, display_name: "foo") + v.name_to_display.should == "foo" + end + + it "returns product name if display_name is empty" do + v = create(:variant, product: create(:product)) + v.name_to_display.should == v.product.name + end + end + + describe "getting unit for display" do + it "returns display_as if present" do + v = create(:variant, display_as: "foo") + v.unit_to_display.should == "foo" + end + + it "returns options_text if display_as is empty" do + v = create(:variant) + v.stub(:options_text).and_return "ponies" + v.unit_to_display.should == "ponies" + end + end + describe "setting the variant's weight from the unit value" do it "sets the variant's weight when unit is weight" do p = create(:simple_product, variant_unit: nil, variant_unit_scale: nil) @@ -265,7 +290,7 @@ module Spree let!(:p) { create(:simple_product, variant_unit: 'weight', variant_unit_scale: 1) } let!(:v) { create(:variant, product: p, unit_value: 5, unit_description: 'bar', display_as: 'FOOS!') } - it "requests the name of the new option_value from OptionValueName" do + it "does not request the name of the new option_value from OptionValueName" do OpenFoodNetwork::OptionValueNamer.any_instance.should_not_receive(:name) v.update_attributes!(unit_value: 10, unit_description: 'foo') ov = v.option_values.last