From 3196e28d889ab2e174b7ede3e525fb452a536265 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 27 Feb 2014 11:29:39 +1100 Subject: [PATCH] Admin can assign units to a product --- .../spree/products_helper_decorator.rb | 7 +++++++ .../_form/add_units_form.html.haml.deface | 16 ++++++++++++++++ .../new/add_unit_form.html.haml.deface | 17 +++++++++++++++++ .../admin/products/_supplier_form.html.haml | 2 +- spec/features/admin/products_spec.rb | 19 ++++++++++++++----- 5 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 app/overrides/spree/admin/products/_form/add_units_form.html.haml.deface create mode 100644 app/overrides/spree/admin/products/new/add_unit_form.html.haml.deface diff --git a/app/helpers/spree/products_helper_decorator.rb b/app/helpers/spree/products_helper_decorator.rb index 99596a73e9..f918a47649 100644 --- a/app/helpers/spree/products_helper_decorator.rb +++ b/app/helpers/spree/products_helper_decorator.rb @@ -14,5 +14,12 @@ module Spree def variant_unit_option_type?(option_type) Spree::Product.all_variant_unit_option_types.include? option_type end + + + def product_variant_unit_options + [['Weight', 'weight'], + ['Volume', 'volume'], + ['Items', 'items']] + end end end diff --git a/app/overrides/spree/admin/products/_form/add_units_form.html.haml.deface b/app/overrides/spree/admin/products/_form/add_units_form.html.haml.deface new file mode 100644 index 0000000000..9a5b6a87d6 --- /dev/null +++ b/app/overrides/spree/admin/products/_form/add_units_form.html.haml.deface @@ -0,0 +1,16 @@ +/ insert_top "[data-hook='admin_product_form_right']" + += f.field_container :variant_unit do + = f.label :variant_unit, 'Variant unit' + = f.select :variant_unit, product_variant_unit_options, {:include_blank => true}, {:class => "select2 fullwidth"} + = f.error_message_on :variant_unit + += f.field_container :variant_unit_scale do + = f.label :variant_unit_scale, 'Variant unit scale' + = f.text_field :variant_unit_scale + = f.error_message_on :variant_unit_scale + += f.field_container :variant_unit_name do + = f.label :variant_unit_name, 'Variant unit name' + = f.text_field :variant_unit_name + = f.error_message_on :variant_unit_name diff --git a/app/overrides/spree/admin/products/new/add_unit_form.html.haml.deface b/app/overrides/spree/admin/products/new/add_unit_form.html.haml.deface new file mode 100644 index 0000000000..03021b41d9 --- /dev/null +++ b/app/overrides/spree/admin/products/new/add_unit_form.html.haml.deface @@ -0,0 +1,17 @@ +/ insert_before "[data-hook='new_product_attrs']" + +.row + .alpha.six.columns + = f.label :variant_unit, 'Variant unit' + = f.select :variant_unit, product_variant_unit_options, {:include_blank => true}, {:class => "select2 fullwidth"} + = f.error_message_on :variant_unit + + .four.columns + = f.label :variant_unit_scale, 'Variant unit scale' + = f.text_field :variant_unit_scale, {class: "fullwidth"} + = f.error_message_on :variant_unit_scale + + .omega.six.columns + = f.label :variant_unit_name, 'Variant unit name' + = f.text_field :variant_unit_name, {class: "fullwidth"} + = f.error_message_on :variant_unit_name diff --git a/app/views/spree/admin/products/_supplier_form.html.haml b/app/views/spree/admin/products/_supplier_form.html.haml index b73a9eb462..3e5c01c2a3 100644 --- a/app/views/spree/admin/products/_supplier_form.html.haml +++ b/app/views/spree/admin/products/_supplier_form.html.haml @@ -1,5 +1,5 @@ = f.field_container :supplier do = f.label :supplier %br - = f.collection_select(:supplier_id, Enterprise.is_primary_producer.managed_by(spree_current_user), :id, :name, {:include_blank => true}, {:class => "select2"}) + = f.collection_select(:supplier_id, Enterprise.is_primary_producer.managed_by(spree_current_user).by_name, :id, :name, {:include_blank => true}, {:class => "select2"}) = f.error_message_on :supplier diff --git a/spec/features/admin/products_spec.rb b/spec/features/admin/products_spec.rb index 58d9d57775..092d5239d4 100644 --- a/spec/features/admin/products_spec.rb +++ b/spec/features/admin/products_spec.rb @@ -14,15 +14,18 @@ feature %q{ end context "creating a product" do - scenario "assigning a supplier and distributors to the product" do + scenario "assigning a supplier, distributors and units to the product" do login_to_admin_section click_link 'Products' click_link 'New Product' - fill_in 'product_name', :with => 'A new product !!!' - fill_in 'product_price', :with => '19.99' - select 'New supplier', :from => 'product_supplier_id' + fill_in 'product_name', with: 'A new product !!!' + fill_in 'product_price', with: '19.99' + select 'New supplier', from: 'product_supplier_id' + select 'Weight', from: 'product_variant_unit' + fill_in 'product_variant_unit_scale', with: 1000 + fill_in 'product_variant_unit_name', with: '' click_button 'Create' @@ -31,6 +34,11 @@ feature %q{ product.supplier.should == @supplier product.group_buy.should be_false + product.variant_unit.should == 'weight' + product.variant_unit_scale.should == 1000 + product.variant_unit_name.should == '' + product.option_types.first.name.should == 'unit_weight' + # Distributors within('#sidebar') { click_link 'Product Distributions' } @@ -46,7 +54,8 @@ feature %q{ product.product_distributions.map { |pd| pd.enterprise_fee }.should == [@enterprise_fees[0], @enterprise_fees[2]] end - scenario "making a group buy product" do + + scenario "creating a group buy product" do login_to_admin_section click_link 'Products'