Reworking the variant display of units and names

This commit is contained in:
Will Marshall
2014-06-12 13:05:12 +10:00
parent 1a4e3c20ad
commit 7a062b0310
8 changed files with 57 additions and 9 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -579,5 +579,6 @@ module Spree
product.taxons.should == [product.primary_taxon]
end
end
end
end

View File

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