mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-14 23:47:48 +00:00
Merge branch 'master' into checkout
This commit is contained in:
@@ -1,3 +1,13 @@
|
||||
Spree::Admin::VariantsController.class_eval do
|
||||
helper 'spree/products'
|
||||
|
||||
|
||||
protected
|
||||
|
||||
def create_before
|
||||
option_values = params[:new_variant]
|
||||
option_values.andand.each_value {|id| @object.option_values << OptionValue.find(id)}
|
||||
@object.save
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -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
|
||||
@@ -2,7 +2,7 @@
|
||||
.alpha.six.columns
|
||||
= f.field_container :supplier do
|
||||
= f.label :supplier
|
||||
= f.collection_select(:supplier_id, Enterprise.is_primary_producer.managed_by(spree_current_user), :id, :name, {:include_blank => true}, {:class => "select2 fullwidth"})
|
||||
= f.collection_select(:supplier_id, Enterprise.is_primary_producer.managed_by(spree_current_user).by_name, :id, :name, {:include_blank => true}, {:class => "select2 fullwidth"})
|
||||
= f.error_message_on :supplier
|
||||
.four.columns
|
||||
= f.field_container :group_buy do
|
||||
@@ -17,4 +17,4 @@
|
||||
.omega.six.columns
|
||||
= f.field_container :group_buy_unit_size do
|
||||
= f.label :group_buy_unit_size
|
||||
= f.text_field :group_buy_unit_size, :class => "fullwidth"
|
||||
= f.text_field :group_buy_unit_size, :class => "fullwidth"
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -7,6 +7,27 @@ feature %q{
|
||||
include AuthenticationWorkflow
|
||||
include WebHelper
|
||||
|
||||
scenario "creating a new variant" do
|
||||
# Given a product with a unit-related option type
|
||||
p = create(:simple_product, variant_unit: "weight", variant_unit_scale: "1")
|
||||
|
||||
# When I create a variant on the product
|
||||
login_to_admin_section
|
||||
click_link 'Products'
|
||||
within('#sub_nav') { click_link 'Products' }
|
||||
click_link p.name
|
||||
click_link 'Variants'
|
||||
click_link 'New Variant'
|
||||
|
||||
fill_in 'variant_unit_value', with: '1'
|
||||
fill_in 'variant_unit_description', with: 'foo'
|
||||
click_button 'Create'
|
||||
|
||||
# Then the variant should have been created
|
||||
page.should have_content "Variant \"#{p.name}\" has been successfully created!"
|
||||
end
|
||||
|
||||
|
||||
scenario "editing unit value and description for a variant" do
|
||||
# Given a product with unit-related option types, with a variant
|
||||
p = create(:simple_product, variant_unit: "weight", variant_unit_scale: "1")
|
||||
|
||||
Reference in New Issue
Block a user