mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
Admin can assign units to a product
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user