mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Merge branch 'laura_and_will' into icon_font
This commit is contained in:
@@ -5,6 +5,13 @@ Spree::Admin::ProductsController.class_eval do
|
||||
|
||||
respond_to :json, :only => :clone
|
||||
|
||||
respond_override create: { html: { success: lambda {
|
||||
if params[:button] == "add_another"
|
||||
redirect_to new_admin_product_path
|
||||
else
|
||||
redirect_to '/admin/products/bulk_edit'
|
||||
end
|
||||
} } }
|
||||
#respond_override :clone => { :json => {:success => lambda { redirect_to bulk_index_admin_products_url+"?q[id_eq]=#{@new.id}" } } }
|
||||
|
||||
def product_distributions
|
||||
|
||||
@@ -4,7 +4,6 @@ Spree::Product.class_eval do
|
||||
# https://github.com/rails/rails/issues/7618
|
||||
has_many :option_types, :through => :product_option_types, :dependent => :destroy
|
||||
|
||||
|
||||
belongs_to :supplier, :class_name => 'Enterprise'
|
||||
belongs_to :primary_taxon, class_name: 'Spree::Taxon'
|
||||
|
||||
@@ -13,8 +12,9 @@ Spree::Product.class_eval do
|
||||
|
||||
accepts_nested_attributes_for :product_distributions, :allow_destroy => true
|
||||
delegate_belongs_to :master, :unit_value, :unit_description
|
||||
delegate :images_attributes=, to: :master
|
||||
|
||||
attr_accessible :supplier_id, :primary_taxon_id, :distributor_ids, :product_distributions_attributes, :group_buy, :group_buy_unit_size, :variant_unit, :variant_unit_scale, :variant_unit_name, :unit_value, :unit_description, :notes
|
||||
attr_accessible :supplier_id, :primary_taxon_id, :distributor_ids, :product_distributions_attributes, :group_buy, :group_buy_unit_size, :variant_unit, :variant_unit_scale, :variant_unit_name, :unit_value, :unit_description, :notes, :images_attributes
|
||||
|
||||
validates_presence_of :supplier
|
||||
validates_presence_of :primary_taxon
|
||||
|
||||
@@ -2,7 +2,8 @@ Spree::Variant.class_eval do
|
||||
has_many :exchange_variants, dependent: :destroy
|
||||
has_many :exchanges, through: :exchange_variants
|
||||
|
||||
attr_accessible :unit_value, :unit_description
|
||||
attr_accessible :unit_value, :unit_description, :images_attributes
|
||||
accepts_nested_attributes_for :images
|
||||
|
||||
validates_presence_of :unit_value,
|
||||
if: -> v { %w(weight volume).include? v.product.variant_unit },
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
Deface::Override.new(:virtual_path => "spree/admin/products/_form",
|
||||
:insert_top => "[data-hook='admin_product_form_right']",
|
||||
:partial => "spree/admin/products/primary_taxon_form",
|
||||
:name => "add_primary_taxon_to_admin_product")
|
||||
@@ -1,4 +0,0 @@
|
||||
Deface::Override.new(:virtual_path => "spree/admin/products/new",
|
||||
:insert_before => "[data-hook='new_product_attrs']",
|
||||
:partial => "spree/admin/products/primary_taxon_form",
|
||||
:name => "add_primary_taxon_to_admin_product_new")
|
||||
@@ -1,5 +0,0 @@
|
||||
Deface::Override.new(:virtual_path => "spree/admin/products/new",
|
||||
:insert_before => "[data-hook='new_product_attrs']",
|
||||
:partial => "spree/admin/products/supplier_and_group_buy_for_new",
|
||||
:name => "add_supplier_and_group_buy_to_admin_product_new",
|
||||
:original => '59b7ed369769267bdedb596768fcfcc2cb94f122')
|
||||
@@ -1,60 +1,79 @@
|
||||
/ replace "fieldset[data-hook='new_product']"
|
||||
|
||||
%fieldset{ id: "new_product" }
|
||||
%legend{align: "center"}= t(:new_product)
|
||||
|
||||
.row
|
||||
.alpha.eleven.columns
|
||||
= f.field_container :name do
|
||||
= f.label :name, t(:name)
|
||||
%span.required *
|
||||
.twelve.columns.alpha
|
||||
%fieldset.no-border-bottom{ id: "new_product" }
|
||||
%legend{align: "center"}= t(:new_product)
|
||||
.twelve.columns.alpha
|
||||
.six.columns.alpha
|
||||
= f.field_container :supplier do
|
||||
= f.label :supplier_id, t(:supplier)
|
||||
%span.required *
|
||||
= 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
|
||||
.six.columns.omega
|
||||
= f.field_container :name do
|
||||
= f.label :name, t(:product_name)
|
||||
%span.required *
|
||||
%br/
|
||||
= f.text_field :name, :class => 'fullwidth title'
|
||||
= f.error_message_on :name
|
||||
.twelve.columns.alpha{ 'ng-controller' => 'unitsCtrl' }
|
||||
.six.columns.alpha
|
||||
= f.field_container :units do
|
||||
= f.label :variant_unit_with_scale, :units
|
||||
%select.select2.fullwidth{ id: 'product_variant_unit_with_scale', 'ng-model' => 'product.variant_unit_with_scale', 'ng-options' => 'unit[1] as unit[0] for unit in variant_unit_options' }
|
||||
%option{'value' => '', 'ng-hide' => "hasUnit(product)"}
|
||||
%input{ type: 'hidden', 'ng-value' => 'product.variant_unit', name: 'product[variant_unit]' }
|
||||
%input{ type: 'hidden', 'ng-value' => 'product.variant_unit_scale', name: 'product[variant_unit_scale]' }
|
||||
.three.columns
|
||||
= f.field_container :unit_value do
|
||||
= f.label :product_unit_value_with_description, :value, 'ng-disabled' => "!hasUnit(product)"
|
||||
%input.fullwidth{ id: 'product_unit_value_with_description', 'ng-model' => 'product.master.unit_value_with_description', :type => 'text', placeholder: "eg. 2", 'ng-disabled' => "!hasUnit(product)" }
|
||||
%input{ type: 'hidden', 'ng-value' => 'product.master.unit_value', name: 'product[unit_value]' }
|
||||
%input{ type: 'hidden', 'ng-value' => 'product.master.unit_description', name: 'product[unit_description]' }
|
||||
.three.columns.omega{ 'ng-show' => "product.variant_unit_with_scale == 'items'" }
|
||||
= f.field_container :unit_name do
|
||||
= f.label :product_variant_unit_name, :unit_name
|
||||
%input.fullwidth{ id: 'product_variant_unit_name','ng-model' => 'product.variant_unit_name', :name => 'product[variant_unit_name]', :placeholder => 'eg. bunches', :type => 'text' }
|
||||
.twelve.columns.alpha
|
||||
.six.columns.alpha
|
||||
= render 'spree/admin/products/primary_taxon_form', f: f
|
||||
.three.columns
|
||||
= f.field_container :price do
|
||||
= f.label :price, t(:price)
|
||||
%span.required *
|
||||
%br/
|
||||
= f.text_field :price, class: 'fullwidth'
|
||||
= f.error_message_on :price
|
||||
.three.columns.omega
|
||||
= f.field_container :on_hand do
|
||||
= f.label :on_hand, t(:on_hand)
|
||||
%span.required *
|
||||
%br/
|
||||
= f.text_field :on_hand, class: 'fullwidth'
|
||||
= f.error_message_on :on_hand
|
||||
.twelve.columns.alpha
|
||||
= f.field_container :description do
|
||||
= f.label :product_description, t(:product_description)
|
||||
%br/
|
||||
= f.text_field :name, :class => 'fullwidth title'
|
||||
= f.error_message_on :name
|
||||
.five.columns.omega
|
||||
= f.field_container :supplier do
|
||||
= f.label :supplier
|
||||
%span.required *
|
||||
= 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
|
||||
|
||||
.row
|
||||
.alpha.six.columns
|
||||
= render 'spree/admin/products/primary_taxon_form', f: f
|
||||
.five.columns
|
||||
= f.field_container :price do
|
||||
= f.label :price, t(:price)
|
||||
%span.required *
|
||||
%br/
|
||||
= f.text_field :price, :class => 'fullwidth'
|
||||
= f.error_message_on :price
|
||||
.five.columns.omega
|
||||
= f.field_container :on_hand do
|
||||
= f.label :on_hand, t(:on_hand)
|
||||
%span.required *
|
||||
%br/
|
||||
= f.text_field :on_hand, :class => 'fullwidth'
|
||||
= f.error_message_on :on_hand
|
||||
|
||||
.row{ 'ng-controller' => 'unitsCtrl' }
|
||||
.six.columns.alpha
|
||||
= f.label :variant_unit_with_scale, :units
|
||||
%select.select2.fullwidth{ id: 'product_variant_unit_with_scale', 'ng-model' => 'product.variant_unit_with_scale', 'ng-options' => 'unit[1] as unit[0] for unit in variant_unit_options' }
|
||||
%option{'value' => '', 'ng-hide' => "hasUnit(product)"}
|
||||
%input{ type: 'hidden', 'ng-value' => 'product.variant_unit', name: 'product[variant_unit]' }
|
||||
%input{ type: 'hidden', 'ng-value' => 'product.variant_unit_scale', name: 'product[variant_unit_scale]' }
|
||||
.five.columns
|
||||
= f.label :product_unit_value_with_description, :value
|
||||
%input.fullwidth{ id: 'product_unit_value_with_description', 'ng-model' => 'product.master.unit_value_with_description', :type => 'text', :placeholder => 'eg. 2', 'ng-disabled' => "!hasUnit(product)" }
|
||||
%input{ type: 'hidden', 'ng-value' => 'product.master.unit_value', name: 'product[unit_value]' }
|
||||
%input{ type: 'hidden', 'ng-value' => 'product.master.unit_description', name: 'product[unit_description]' }
|
||||
.five.columns.omega{ 'ng-show' => "product.variant_unit_with_scale == 'items'" }
|
||||
= f.label :product_variant_unit_name, :unit_name
|
||||
%input.fullwidth{ id: 'product_variant_unit_name','ng-model' => 'product.variant_unit_name', :name => 'product[variant_unit_name]', :placeholder => 'eg. bunches', :type => 'text' }
|
||||
|
||||
#product-from-prototype.clearfix{"data-hook" => "product-from-prototype"}
|
||||
= render :file => 'spree/admin/prototypes/show' if @prototype
|
||||
= render :partial => 'spree/admin/shared/new_resource_links'
|
||||
= f.text_area :description, class: 'fullwidth', rows: 3
|
||||
= f.error_message_on :description
|
||||
.four.columns.omega{ style: "text-align: center" }
|
||||
%fieldset.no-border-bottom{ id: "image" }
|
||||
%legend{align: "center"}= t(:image)
|
||||
.row
|
||||
= image_tag "noimage/product.png", class: "four columns alpha"
|
||||
.row
|
||||
= f.fields_for 'images_attributes[]', f.object.images.build do |image_fields|
|
||||
= image_fields.file_field :attachment
|
||||
.sixteen.columns.alpha
|
||||
.form-buttons.filter-actions.actions{ 'data-hook' => "buttons" }
|
||||
= button t('actions.create'), 'icon-ok', :submit, value: "create"
|
||||
%span.or
|
||||
= t(:or)
|
||||
= button "Create And Add Another", 'icon-repeat', :submit, value: 'add_another'
|
||||
%span.or
|
||||
= t(:or)
|
||||
= link_to_with_icon 'icon-remove', t('actions.cancel'), collection_url, :class => 'button'
|
||||
|
||||
|
||||
:javascript
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
|
||||
.small-4.columns
|
||||
({{ product.master.options_text }})
|
||||
{{ product.master.options_text }}
|
||||
|
||||
-# WITHOUT GROUP BUY
|
||||
.small-5.columns{"bo-if" => "!product.group_buy"}
|
||||
|
||||
@@ -3,5 +3,6 @@
|
||||
.small-12.large-9.columns
|
||||
%p= current_distributor.long_description.andand.html_safe
|
||||
.small-12.large-3.columns
|
||||
%img.about.right{src: current_distributor.promo_image.url(:large)}
|
||||
/ Hide image until image styles are working correctly:
|
||||
/ %img.about.right{src: current_distributor.promo_image.url(:large)}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
= f.field_container :primary_taxon_id do
|
||||
= f.label :primary_taxon_id
|
||||
= f.label :primary_taxon_id, t(:product_category)
|
||||
%br
|
||||
= f.collection_select(:primary_taxon_id, Spree::Taxon.all, :id, :name, {:include_blank => true}, {:class => "select2 fullwidth"})
|
||||
= f.error_message_on :primary_taxon_id
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
class AddPrimaryTaxonToProducts < ActiveRecord::Migration
|
||||
def change
|
||||
def up
|
||||
add_column :spree_products, :primary_taxon_id, :integer
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
|
||||
add_index :spree_products, :primary_taxon_id
|
||||
add_foreign_key :spree_products, :spree_taxons, column: :primary_taxon_id
|
||||
=======
|
||||
>>>>>>> fd1e7eb... Adding primary taxon field to product
|
||||
=======
|
||||
add_index :spree_products, :primary_taxon_id
|
||||
add_foreign_key :spree_products, :spree_taxons, column: :primary_taxon_id
|
||||
>>>>>>> 110a6f2... Adding primary taxon to admin forms
|
||||
|
||||
Spree::Product.all.each do |p|
|
||||
p.update_column :primary_taxon_id, (p.taxons.first || Spree::Taxon.first)
|
||||
end
|
||||
|
||||
change_column :spree_products, :primary_taxon_id, :integer, null: false
|
||||
end
|
||||
|
||||
def down
|
||||
remove_column :spree_products, :primary_taxon_id
|
||||
end
|
||||
end
|
||||
|
||||
@@ -681,7 +681,7 @@ ActiveRecord::Schema.define(:version => 20140522044009) do
|
||||
t.float "variant_unit_scale"
|
||||
t.string "variant_unit_name"
|
||||
t.text "notes"
|
||||
t.integer "primary_taxon_id"
|
||||
t.integer "primary_taxon_id", :null => false
|
||||
end
|
||||
|
||||
add_index "spree_products", ["available_on"], :name => "index_products_on_available_on"
|
||||
|
||||
55
spec/controllers/spree/admin/products_controller_spec.rb
Normal file
55
spec/controllers/spree/admin/products_controller_spec.rb
Normal file
@@ -0,0 +1,55 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Spree::Admin::ProductsController do
|
||||
context "Creating a new product" do
|
||||
let(:user) do
|
||||
user = create(:user)
|
||||
user.spree_roles << Spree::Role.find_or_create_by_name!('admin')
|
||||
user
|
||||
end
|
||||
|
||||
before do
|
||||
controller.stub spree_current_user: user
|
||||
end
|
||||
|
||||
it "redirects to bulk_edit when the user hits 'create'" do
|
||||
s = create(:supplier_enterprise)
|
||||
t = create(:taxon)
|
||||
spree_post :create, {
|
||||
product: {
|
||||
name: "Product1",
|
||||
supplier_id: s.id,
|
||||
price: 5.0,
|
||||
on_hand: 5,
|
||||
variant_unit: 'weight',
|
||||
variant_unit_scale: 1000,
|
||||
unit_value: 10,
|
||||
unit_description: "",
|
||||
primary_taxon_id: t.id
|
||||
},
|
||||
button: 'create'
|
||||
}
|
||||
response.should redirect_to "/admin/products/bulk_edit"
|
||||
end
|
||||
|
||||
it "redirects to new when the user hits 'add_another'" do
|
||||
s = create(:supplier_enterprise)
|
||||
t = create(:taxon)
|
||||
spree_post :create, {
|
||||
product: {
|
||||
name: "Product1",
|
||||
supplier_id: s.id,
|
||||
price: 5.0,
|
||||
on_hand: 5,
|
||||
variant_unit: 'weight',
|
||||
variant_unit_scale: 1000,
|
||||
unit_value: 10,
|
||||
unit_description: "",
|
||||
primary_taxon_id: t.id
|
||||
},
|
||||
button: 'add_another'
|
||||
}
|
||||
response.should redirect_to "/admin/products/new"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -15,26 +15,39 @@ feature %q{
|
||||
end
|
||||
|
||||
describe "creating a product" do
|
||||
scenario "assigning a supplier, distributors and units to the product" do
|
||||
scenario "assigning a important attributes" 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 taxon.name, from: "product_primary_taxon_id"
|
||||
select 'New supplier', from: 'product_supplier_id'
|
||||
fill_in 'product_name', with: 'A new product !!!'
|
||||
# select "Weight (kg)", from: 'product_variant_unit_with_scale'
|
||||
# fill_in 'product_unit_value_with_description', with: 5
|
||||
select taxon.name, from: "product_primary_taxon_id"
|
||||
fill_in 'product_price', with: '19.99'
|
||||
fill_in 'product_on_hand', with: 5
|
||||
fill_in 'product_description', with: "A description..."
|
||||
|
||||
click_button 'Create'
|
||||
|
||||
flash_message.should == 'Product "A new product !!!" has been successfully created!'
|
||||
product = Spree::Product.find_by_name('A new product !!!')
|
||||
product.supplier.should == @supplier
|
||||
#product.variant_unit.should == 'weight'
|
||||
#product.variant_unit_scale.should == 1000
|
||||
#product.unit_value.should == 5
|
||||
#product.unit_value_description.should == ""
|
||||
#product.unit_name.should == ""
|
||||
product.primary_taxon_id.should == taxon.id
|
||||
product.price.to_s.should == '19.99'
|
||||
product.on_hand.should == 5
|
||||
product.description.should == "A description..."
|
||||
product.group_buy.should be_false
|
||||
|
||||
# Distributors
|
||||
within('#sidebar') { click_link 'Product Distributions' }
|
||||
visit spree.product_distributions_admin_product_path(product)
|
||||
|
||||
check @distributors[0].name
|
||||
select @enterprise_fees[0].name, :from => 'product_product_distributions_attributes_0_enterprise_fee_id'
|
||||
|
||||
@@ -24,7 +24,6 @@ feature "As a consumer I want to shop with a distributor", js: true do
|
||||
page.should have_text distributor.name
|
||||
find("#tab_about a").click
|
||||
first("distributor img")['src'].should == distributor.logo.url(:thumb)
|
||||
first("#about img")['src'].should == distributor.promo_image.url(:large)
|
||||
end
|
||||
|
||||
it "shows the producers for a distributor" do
|
||||
|
||||
@@ -16,6 +16,7 @@ module Spree
|
||||
|
||||
it "requires a primary taxon" do
|
||||
product = create(:simple_product)
|
||||
product.taxons = []
|
||||
product.primary_taxon = nil
|
||||
product.should_not be_valid
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user