Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[NEW SPREE 0.70] new files from ground up rebuild

  • Loading branch information...
commit 4aa37622fe9ceb1b10b5cd630bc512d0447bbf0a 1 parent c2227ac
johndavid400 authored
Showing with 1,950 additions and 0 deletions.
  1. +22 −0 Gemfile
  2. +26 −0 LICENSE
  3. +20 −0 README.md
  4. +31 −0 Rakefile
  5. +9 −0 Versionfile
  6. +1 −0  app/assets/javascripts/admin/spree_suppliers.js
  7. +3 −0  app/assets/javascripts/invoice_items.js.coffee
  8. +1 −0  app/assets/javascripts/store/spree_suppliers.js
  9. +3 −0  app/assets/javascripts/supplier_invoices.js.coffee
  10. +3 −0  app/assets/javascripts/suppliers.js.coffee
  11. +3 −0  app/assets/stylesheets/admin/spree_suppliers.css
  12. +3 −0  app/assets/stylesheets/invoice_items.css.scss
  13. +3 −0  app/assets/stylesheets/store/spree_suppliers.css
  14. +3 −0  app/assets/stylesheets/supplier_invoices.css.scss
  15. +4 −0 app/assets/stylesheets/suppliers.css.scss
  16. +61 −0 app/controllers/admin/supplier_taxons_controller.rb
  17. +127 −0 app/controllers/admin/suppliers_controller.rb
  18. +18 −0 app/controllers/admin/vendor_overview_controller.rb
  19. +2 −0  app/controllers/invoice_items_controller.rb
  20. +2 −0  app/controllers/supplier_invoices_controller.rb
  21. +15 −0 app/controllers/suppliers_controller.rb
  22. +4 −0 app/models/invoice_item.rb
  23. +8 −0 app/models/supplier.rb
  24. +4 −0 app/models/supplier_invoice.rb
  25. +5 −0 app/overrides/admin.rb
  26. +34 −0 app/views/admin/orders/show.html.erb
  27. +19 −0 app/views/admin/orders/user.html.erb
  28. +114 −0 app/views/admin/products/_form.html.erb
  29. +4 −0 app/views/admin/products/_suppliers_form.html.erb
  30. +5 −0 app/views/admin/shared/_order_tabs_decide.html.erb
  31. +39 −0 app/views/admin/shared/_vendor_order_tabs.html.erb
  32. +23 −0 app/views/admin/supplier_taxons/_form.html.erb
  33. +23 −0 app/views/admin/supplier_taxons/_taxon_table.html.erb
  34. +33 −0 app/views/admin/supplier_taxons/available.js.erb
  35. +11 −0 app/views/admin/supplier_taxons/edit.html.erb
  36. +1 −0  app/views/admin/supplier_taxons/remove.html.erb
  37. +2 −0  app/views/admin/supplier_taxons/select.js.erb
  38. +18 −0 app/views/admin/supplier_taxons/selected.html.erb
  39. +75 −0 app/views/admin/suppliers/_edit_form.html.erb
  40. +18 −0 app/views/admin/suppliers/_edit_hours_form.html.erb
  41. +60 −0 app/views/admin/suppliers/_form.html.erb
  42. +11 −0 app/views/admin/suppliers/_hours_form.html.erb
  43. +11 −0 app/views/admin/suppliers/_image_form.html.erb
  44. +24 −0 app/views/admin/suppliers/_supplier.html.erb
  45. +12 −0 app/views/admin/suppliers/_supplier_tabs.html.erb
  46. +25 −0 app/views/admin/suppliers/_suppliers_table.html.erb
  47. +14 −0 app/views/admin/suppliers/_upload_image.html.erb
  48. +34 −0 app/views/admin/suppliers/available.js.erb
  49. +13 −0 app/views/admin/suppliers/edit.html.erb
  50. +97 −0 app/views/admin/suppliers/index.html.erb
  51. +20 −0 app/views/admin/suppliers/line_items.html.erb
  52. +13 −0 app/views/admin/suppliers/new.html.erb
  53. +1 −0  app/views/admin/suppliers/remove.html.erb
  54. +1 −0  app/views/admin/suppliers/select.html.erb
  55. +40 −0 app/views/admin/suppliers/selected.html.erb
  56. +2 −0  app/views/admin/suppliers/show.html.erb
  57. +1 −0  app/views/admin/vendor_overview/index.html.erb
  58. +47 −0 app/views/shared/_supplier_invoices.html.erb
  59. +7 −0 app/views/suppliers/_supplier.html.erb
  60. +13 −0 app/views/suppliers/_supplier_list.erb
  61. +13 −0 app/views/suppliers/index.html.erb
  62. +11 −0 app/views/suppliers/show.html.erb
  63. +11 −0 app/views/suppliers/supplier_list.erb
  64. +37 −0 config/routes.rb
  65. +8 −0 db/migrate/20120131160039_create_suppliers.rb
  66. +16 −0 db/migrate/20120131160855_add_fields_to_suppliers.rb
  67. +12 −0 db/migrate/20120131161247_create_supplier_invoices.rb
  68. +12 −0 db/migrate/20120131161610_create_invoice_items.rb
  69. +143 −0 db/seeds.rb
  70. BIN  db/seeds/images/apple.gif
  71. BIN  db/seeds/images/apple.jpg
  72. BIN  db/seeds/images/banana.jpg
  73. BIN  db/seeds/images/blueberry.jpg
  74. BIN  db/seeds/images/cherries.jpg
  75. BIN  db/seeds/images/chicken.jpg
  76. BIN  db/seeds/images/cow.jpg
  77. BIN  db/seeds/images/flower.jpg
  78. BIN  db/seeds/images/goat.jpg
  79. BIN  db/seeds/images/grapes.jpg
  80. BIN  db/seeds/images/greenapple.jpg
  81. BIN  db/seeds/images/greenbeans.jpg
  82. BIN  db/seeds/images/indie_candy.jpg
  83. BIN  db/seeds/images/orange.jpg
  84. BIN  db/seeds/images/squash.jpg
  85. BIN  db/seeds/images/stock_user.jpg
  86. BIN  db/seeds/images/strawberry.jpg
  87. BIN  db/seeds/images/watermelon.jpg
  88. +29 −0 lib/generators/spree_suppliers/install/install_generator.rb
  89. +192 −0 lib/spree_suppliers.rb
  90. +24 −0 lib/spree_suppliers/engine.rb
  91. +19 −0 lib/spree_suppliers_hooks.rb
  92. +7 −0 script/rails
  93. +31 −0 spec/spec_helper.rb
  94. +23 −0 spree_suppliers.gemspec
  95. 0  test/fixtures/.gitkeep
  96. +13 −0 test/fixtures/invoice_items.yml
  97. +13 −0 test/fixtures/supplier_invoices.yml
  98. +11 −0 test/fixtures/suppliers.yml
  99. 0  test/functional/.gitkeep
  100. +7 −0 test/functional/invoice_items_controller_test.rb
  101. +7 −0 test/functional/supplier_invoices_controller_test.rb
  102. +7 −0 test/functional/suppliers_controller_test.rb
  103. 0  test/integration/.gitkeep
  104. +12 −0 test/performance/browsing_test.rb
  105. +13 −0 test/test_helper.rb
  106. +4 −0 test/unit/helpers/invoice_items_helper_test.rb
  107. +4 −0 test/unit/helpers/supplier_invoices_helper_test.rb
  108. +4 −0 test/unit/helpers/suppliers_helper_test.rb
  109. +7 −0 test/unit/invoice_item_test.rb
  110. +7 −0 test/unit/supplier_invoice_test.rb
  111. +7 −0 test/unit/supplier_test.rb
View
22 Gemfile
@@ -0,0 +1,22 @@
+source 'http://rubygems.org'
+
+gem 'sqlite3'
+
+group :test do
+ gem 'rspec-rails', '= 2.6.1'
+end
+
+group :cucumber do
+ gem 'cucumber-rails', '1.0.0'
+ gem 'database_cleaner', '= 0.6.7'
+ gem 'nokogiri'
+ gem 'capybara', '1.0.1'
+end
+
+if RUBY_VERSION < "1.9"
+ gem "ruby-debug"
+else
+ gem "ruby-debug19"
+end
+
+gemspec
View
26 LICENSE
@@ -0,0 +1,26 @@
+Copyright (c) 2012 [name of plugin creator]
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name Spree nor the names of its contributors may be used to
+ endorse or promote products derived from this software without specific
+ prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
20 README.md
@@ -0,0 +1,20 @@
+SpreeSupplier
+=============
+
+Introduction goes here.
+
+
+Example
+=======
+
+Example goes here.
+
+Testing
+-------
+
+Be sure to add the rspec-rails gem to your Gemfile and then create a dummy test app for the specs to run against.
+
+ $ bundle exec rake test app
+ $ bundle exec rspec spec
+
+Copyright (c) 2012 [name of extension creator], released under the New BSD License
View
31 Rakefile
@@ -0,0 +1,31 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/packagetask'
+require 'rubygems/package_task'
+require 'rspec/core/rake_task'
+require 'cucumber/rake/task'
+require 'spree_core/testing_support/common_rake'
+
+RSpec::Core::RakeTask.new
+Cucumber::Rake::Task.new
+
+task :default => [:spec, :cucumber ]
+
+spec = eval(File.read('spree_suppliers.gemspec'))
+
+Gem::PackageTask.new(spec) do |p|
+ p.gem_spec = spec
+end
+
+desc "Release to gemcutter"
+task :release => :package do
+ require 'rake/gemcutter'
+ Rake::Gemcutter::Tasks.new(spec).define
+ Rake::Task['gem:push'].invoke
+end
+
+desc "Generates a dummy app for testing"
+task :test_app do
+ ENV['LIB_NAME'] = 'spree_suppliers'
+ Rake::Task['common:test_app'].invoke
+end
View
9 Versionfile
@@ -0,0 +1,9 @@
+# This file is used to designate compatibilty with different versions of Spree
+# Please see http://spreecommerce.com/documentation/extensions.html#versionfile for details
+
+# Examples
+#
+# "0.70.x" => { :branch => "master"}
+# "0.60.x" => { :branch => "0-60-stable" }
+# "0.40.x" => { :tag => "v1.0.0", :version => "1.0.0" }
+
View
1  app/assets/javascripts/admin/spree_suppliers.js
@@ -0,0 +1 @@
+//= require admin/spree_core
View
3  app/assets/javascripts/invoice_items.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
1  app/assets/javascripts/store/spree_suppliers.js
@@ -0,0 +1 @@
+//= require store/spree_core
View
3  app/assets/javascripts/supplier_invoices.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
3  app/assets/javascripts/suppliers.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
3  app/assets/stylesheets/admin/spree_suppliers.css
@@ -0,0 +1,3 @@
+/*
+ *= require admin/spree_core
+*/
View
3  app/assets/stylesheets/invoice_items.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the invoice_items controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
3  app/assets/stylesheets/store/spree_suppliers.css
@@ -0,0 +1,3 @@
+/*
+ *= require store/spree_core
+*/
View
3  app/assets/stylesheets/supplier_invoices.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the supplier_invoices controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
4 app/assets/stylesheets/suppliers.css.scss
@@ -0,0 +1,4 @@
+// Place all the styles related to the suppliers controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
+
View
61 app/controllers/admin/supplier_taxons_controller.rb
@@ -0,0 +1,61 @@
+class Admin::SupplierTaxonsController < Admin::BaseController
+ include Railslove::Plugins::FindByParam::SingletonMethods
+ helper "admin/taxons"
+
+ respond_to :html, :json, :js
+
+ def selected
+ @supplier = load_supplier
+ @taxons = @supplier.taxons
+ @options = Taxon.all
+ respond_with(:admin, @taxons)
+ end
+
+ def available
+ @supplier = load_supplier
+ @taxons = params[:q].blank? ? [] : Taxon.where('lower(name) LIKE ?', "%#{params[:q].mb_chars.downcase}%")
+ @taxons.delete_if { |taxon| @supplier.taxons.include?(taxon) }
+ respond_with(:admin, @taxons)
+ end
+
+ def remove
+ @supplier = load_supplier
+ @taxon = Taxon.find(params[:id])
+ @supplier.taxons.delete(@taxon)
+ @supplier.save
+ @taxons = @supplier.taxons
+ respond_with(@taxon) { |format| format.js { render_js_for_destroy } }
+ end
+
+ def select
+ @supplier = load_supplier
+ @taxon = Taxon.find(params[:id])
+ @supplier.taxons << @taxon
+ @supplier.save
+ @taxons = @supplier.taxons
+ respond_with(:admin, @taxons)
+ end
+
+ def batch_select
+ @supplier = load_supplier
+ @taxons = params[:taxon_ids].map{|id| Taxon.find(id)}.compact
+ @supplier.taxons = @taxons
+ @supplier.save
+ redirect_to selected_admin_supplier_taxons_url(@supplier)
+ end
+
+ def update_taxons
+ @supplier = Supplier.find params[:supplier_id]
+ @supplier.taxons = []
+ @supplier.taxons.push(Taxon.all.select{|t| params[t.name.to_s] })
+ @supplier.save
+ redirect_to :back, :notice => "Taxons successfully added"
+ end
+
+ private
+
+ def load_supplier
+ Supplier.find params[:supplier_id]
+ end
+
+end
View
127 app/controllers/admin/suppliers_controller.rb
@@ -0,0 +1,127 @@
+class Admin::SuppliersController < Admin::BaseController
+ resource_controller
+ respond_to :html, :js
+
+ def index
+ if current_user.has_role?("admin")
+ @suppliers = Supplier.all
+ else
+ @supplier = current_user.supplier
+ end
+ end
+
+ def new
+ @supplier = Supplier.new()
+ @supplier.images.build
+ @status = true
+ end
+
+ def create
+ @supplier = Supplier.new(params[:supplier])
+ if @supplier.save
+ redirect_to admin_suppliers_path, :notice => "New supplier created"
+ else
+ render "new"
+ end
+ end
+
+ def show
+ @supplier = Supplier.find(params[:id])
+ end
+
+ def edit
+ @supplier = Supplier.find(params[:id])
+ @supplier.images.build
+ end
+
+ def destroy
+ @supplier = Supplier.find(params[:id])
+ @supplier.destroy
+ flash[:notice] = "Supplier Successfully deleted."
+ respond_with(@product) do |format|
+ format.html { redirect_to collection_url }
+ format.js do
+ render :update do |page|
+ page.redirect_to collection_url
+ end
+ end
+ end
+ end
+
+ def update
+ @supplier = Supplier.find(params[:id])
+ @status = false
+ if @supplier.update_attributes(params[:supplier])
+ redirect_to edit_admin_supplier_path, :notice => "Supplier updated"
+ else
+ render "edit"
+ end
+ end
+
+ def feature
+ @supplier = Supplier.find(params[:supplier_id])
+ if @supplier.featured == true
+ @supplier.featured = false
+ else
+ @supplier.featured = true
+ end
+ @supplier.save
+ flash[:notice] = "change #{@supplier.title}'s feature status to #{@supplier.featured}"
+ redirect_to admin_suppliers_path
+ end
+
+ def line_items
+ @order = Order.find_by_number(params[:order_id])
+ end
+
+ def selected
+ @supplier = @product.supplier
+ end
+
+ def available
+ if params[:q].blank?
+ @available_suppliers = []
+ else
+ @available_suppliers = Supplier.find(:all, :conditions => ['lower(name) LIKE ?', "%#{params[:q].downcase}%"])
+ end
+ @available_suppliers.delete_if { |supplier| @product.supplier == supplier }
+ respond_to do |format|
+ format.html
+ format.js {render :layout => false}
+ end
+
+ end
+
+ def remove
+ @product.supplier = nil
+ @product.save
+ @supplier = @product.supplier
+ render :layout => false
+ end
+
+ def select
+ @supplier = Supplier.find_by_param!(params[:id])
+ @product.supplier = @supplier
+ @product.save
+ @supplier = @product.supplier
+ render :layout => false
+ end
+
+
+ update.response do |wants|
+ wants.html { redirect_to collection_url }
+ end
+
+ update.after do
+ Rails.cache.delete('suppliers')
+ end
+
+ create.response do |wants|
+ wants.html { redirect_to collection_url }
+ end
+
+ create.after do
+ Rails.cache.delete('suppliers')
+ end
+
+end
View
18 app/controllers/admin/vendor_overview_controller.rb
@@ -0,0 +1,18 @@
+class Admin::VendorOverviewController < Spree::BaseController
+ ssl_required
+
+ helper :search
+ helper 'admin/navigation'
+ layout 'admin'
+
+ before_filter :vendor
+
+ def vendor
+ if !current_user.has_role?("vendor")
+ unauthorized
+ end
+ end
+ def index
+
+ end
+end
View
2  app/controllers/invoice_items_controller.rb
@@ -0,0 +1,2 @@
+class InvoiceItemsController < ApplicationController
+end
View
2  app/controllers/supplier_invoices_controller.rb
@@ -0,0 +1,2 @@
+class SupplierInvoicesController < ApplicationController
+end
View
15 app/controllers/suppliers_controller.rb
@@ -0,0 +1,15 @@
+class SuppliersController < Spree::BaseController
+ helper :products
+ respond_to :html
+
+ def index
+ @search = Supplier.search(params[:search])
+ @suppliers = @search.all
+ respond_with(@suppliers)
+ end
+
+ def show
+ @supplier = Supplier.find(params[:id])
+ @products = Product.find(:all, :conditions => { :supplier_id => @supplier.id , :deleted_at => nil })
+ end
+end
View
4 app/models/invoice_item.rb
@@ -0,0 +1,4 @@
+class InvoiceItem < ActiveRecord::Base
+ belongs_to :supplier_invoice
+ belongs_to :line_item
+end
View
8 app/models/supplier.rb
@@ -0,0 +1,8 @@
+class Supplier < ActiveRecord::Base
+ has_many :images, :as => :viewable, :order => :position, :dependent => :destroy
+ accepts_nested_attributes_for :images
+ has_one :user
+ has_many :supplier_invoices
+ has_and_belongs_to_many :taxons
+ has_many :products
+end
View
4 app/models/supplier_invoice.rb
@@ -0,0 +1,4 @@
+class SupplierInvoice < ActiveRecord::Base
+ belongs_to :supplier
+ has_many :invoice_items
+end
View
5 app/overrides/admin.rb
@@ -0,0 +1,5 @@
+Deface::Override.new(:virtual_path => "layouts/admin",
+ :name => "suppliers_tabs",
+ :insert_bottom => "[data-hook='admin_tabs'], #admin_tabs[data-hook]",
+ :text => "<%= tab(:suppliers) %>",
+ :disabled => false)
View
34 app/views/admin/orders/show.html.erb
@@ -0,0 +1,34 @@
+<div class='toolbar order-links'>
+ <%= hook :admin_order_show_buttons do %>
+ <% if !current_user.has_role?("vendor") %>
+ <%= button_link_to t("cancel"), fire_admin_order_url(@order.number, {:e => "cancel"}), :icon => 'delete', :confirm => t('are_you_sure') if @order.can_cancel? %>
+ <%= button_link_to t("edit"), edit_admin_order_url(@order.number), :icon => 'edit' %>
+ <% end %>
+ <% end %>
+</div>
+
+<% render :partial => 'admin/shared/order_tabs_decide', :locals => {:current => "Order Details"} %>
+<%= hook :admin_order_show_addresses do %>
+ <% if @order.bill_address %>
+ <div class='adr'>
+ <h4><%= t("bill_address") %></h4>
+ <%= render :partial => 'admin/shared/address', :locals => {:address => @order.bill_address} %>
+ </div>
+ <% end %>
+ <% if @order.ship_address %>
+ <div class='adr'>
+ <h4><%= t("ship_address") %></h4>
+ <%= render :partial => 'admin/shared/address', :locals => {:address => @order.ship_address} %>
+ </div>
+ <% end %>
+ <hr />
+<% end %>
+<% if !current_user.has_role?("vendor") %>
+ <%= hook :admin_order_show_details do %>
+ <%= render :partial => 'admin/shared/order_details', :locals => {:order => @order} %>
+ <% end %>
+
+<% end %>
+<h3><%= t("Supplier_Invoices") %></h3>
+<%= render :partial => 'shared/supplier_invoices', :locals => {:order => @order} %>
+
View
19 app/views/admin/orders/user.html.erb
@@ -0,0 +1,19 @@
+<%= render :partial => 'admin/shared/order_tabs_decide', :locals => {:current => "Customer Details"} %>
+<%= csrf_meta_tag %>
+
+<% if @order.cart? %>
+ <div id="add-line-item" data-hook>
+ <fieldset>
+ <legend><%= t(:customer_search) %></legend>
+ <%= label_tag :customer_search, t(:enter_at_least_five_letters) %>
+ <%= text_field_tag :customer_search, nil, :class => 'fullwidth title' %>
+ </fieldset>
+ </div>
+<% end %>
+
+<%= render 'shared/error_messages', :target => @order %>
+
+<%= form_for @order, :url => admin_order_url(@order), :html => { :method => :put} do |f| %>
+ <%= f.hidden_field :number %>
+ <%= render :partial => 'user_form', :locals => {:f => f} %>
+<% end %>
View
114 app/views/admin/products/_form.html.erb
@@ -0,0 +1,114 @@
+<div class="clearfix">
+ <div class="left" data-hook="admin_product_form_left">
+ <%= f.field_container :name do %>
+ <%= f.label :name, t(:name) %> <span class="required">*</span><br />
+ <%= f.text_field :name, :class => 'fullwidth title' %>
+ <%= f.error_message_on :name %>
+ <% end %>
+
+ <%= f.field_container :permalink do %>
+ <%= f.label :permalink, t(:permalink) %> <span class="required">*</span><br />
+ <%= f.text_field :permalink, :class => 'fullwidth title' %>
+ <%= f.error_message_on :permalink %>
+ <% end %>
+
+ <%= f.field_container :description do %>
+ <%= f.label :description, t(:description)%><br />
+ <%= f.text_area :description, {:cols => 60, :rows => 4, :class => 'fullwidth'} %>
+ <%= f.error_message_on :description %>
+ <% end %>
+ </div>
+ <div class="right" data-hook="admin_product_form_right">
+ <%= f.field_container :price do %>
+ <%= f.label :price, t(:master_price) %> <span class="required">*</span><br />
+ <%= f.text_field :price, :value => number_with_precision(@product.price, :precision => 2) %>
+ <%= f.error_message_on :price %>
+ <% end %>
+
+ <%if Spree::Config[:show_price_inc_vat] %>
+ <%= label_tag :price_includes_vat , I18n.t(:price_with_vat_included, :price => I18n.t(:price)) %><br />
+ <%= text_field_tag :price_including_vat, product_price(@product, :show_vat_text => false), :size => 30 %>
+ <%= javascript_tag do -%>
+ var effective_tax_rate = <%= @product.effective_tax_rate %>;
+ <% end -%>
+ <% end %>
+
+ <%= f.field_container :cost_price do %>
+ <%= f.label :cost_price, t(:cost_price) %><br />
+ <%= f.text_field :cost_price, :value => number_with_precision(@product.cost_price, :precision => 2) %>
+ <%= f.error_message_on :cost_price %>
+ <% end %>
+
+ <p>
+ <%= f.label :available_on, t(:available_on) %><br />
+ <%= f.error_message_on :available_on %>
+ <%= f.text_field :available_on, :class => 'datepicker' %>
+ </p>
+
+ <p>
+ <%= render :partial => 'admin/products/suppliers_form', :locals => {:f => f} %>
+ </p>
+
+
+ <p>
+ <%= f.label :sku, t(:sku) %><br />
+ <%= f.text_field :sku, :size => 16 %>
+ </p>
+ <% unless @product.has_variants? %>
+ <% if Spree::Config[:track_inventory_levels] %>
+ <p>
+ <%= f.label :on_hand, t(:on_hand) %><br />
+ <%= f.text_field :on_hand, :size => 4 %>
+ </p>
+ <% end %>
+ <ul id="shipping-specs">
+ <li>
+ <%= f.label :weight, t(:weight) %>
+ <%= f.text_field :weight, :size => 4 %>
+ </li>
+ <li>
+ <%= f.label :height, t(:height) %>
+ <%= f.text_field :height, :size => 4 %>
+ </li>
+ <li>
+ <%= f.label :width, t(:width) %>
+ <%= f.text_field :width, :size => 4 %>
+ </li>
+ <li>
+ <%= f.label :depth, t(:depth) %>
+ <%= f.text_field :depth, :size => 4 %>
+ </li>
+ </ul>
+ <% end %>
+ <p>
+ <%= f.label :shipping_category_id, t(:shipping_categories) %><br />
+ <%= f.collection_select(:shipping_category_id, @shipping_categories, :id, :name, {:include_blank => true}, {'style' => 'width:200px'}) %>
+ <%= f.error_message_on :shipping_category %>
+ </p>
+
+ <p>
+ <%= f.label :tax_category_id, t(:tax_category) %><br />
+ <%= f.collection_select(:tax_category_id, @tax_categories, :id, :name, {:include_blank => true}, {'style' => 'width:200px'}) %>
+ <%= f.error_message_on :tax_category %>
+ </p>
+ </div>
+</div>
+
+<h2><%= t(:metadata) %></h2>
+<div data-hook="admin_product_form_meta">
+ <p>
+ <%= f.label :meta_keywords, t(:meta_keywords) %><br />
+ <%= f.text_field :meta_keywords, :class => 'fullwidth' %>
+ </p>
+ <p>
+ <%= f.label :meta_description, t(:meta_description) %><br />
+ <%= f.text_field :meta_description, :class => 'fullwidth' %>
+ </p>
+</div>
+
+
+<div data-hook="admin_product_form_additional_fields">
+ <% Variant.additional_fields.select{|af| af[:only].nil? || af[:only].include?(:product) }.each do |field| %>
+ <%= render :partial => 'admin/shared/additional_field', :locals => {:field => field, :f => f} %>
+ <% end %>
+</div>
View
4 app/views/admin/products/_suppliers_form.html.erb
@@ -0,0 +1,4 @@
+<p>
+ <%= f.label :supplier_id, t("suppliers")%><br />
+ <%= f.collection_select(:supplier_id, @suppliers, :id, :title, {:include_blank => true}) %>
+</p>
View
5 app/views/admin/shared/_order_tabs_decide.html.erb
@@ -0,0 +1,5 @@
+<% if current_user.has_role?("vendor") %>
+ <%= render :partial => 'admin/shared/vendor_order_tabs', :locals => {:current => current}%>
+<% else %>
+ <%= render :partial => 'admin/shared/order_tabs', :locals => {:current => current} %>
+<% end %>
View
39 app/views/admin/shared/_vendor_order_tabs.html.erb
@@ -0,0 +1,39 @@
+<h1><%= t(:order) + " #{@order.number}" %></h1>
+
+<% content_for :sidebar do %>
+ <div id="order_tab_summary">
+ <h3 id="order_number"><%= "#{t(:order)} ##{@order.number} " %></h3>
+ <h5 id="order_status"><%= "#{t(:status)}: #{t("order_state.#{@order.state}")}" %></h5>
+ <h5 id="order_total"><%= "#{t(:total)}: #{number_to_currency(@order.total)}" %></h5>
+ <% if @order.completed? %>
+ <h5 id="shipment_status"><%= "#{t(:shipment)}: #{t("shipment_states.#{@order.shipment_state}")}" %></h5>
+ <h5 id="payment_status"><%= "#{t(:payment)}: #{t("payment_states.#{@order.payment_state}")}" %></h5>
+ <% end %>
+ <br class="clear" />
+ </div>
+ <br class="clear" />
+
+ <ul class="sidebar">
+ <%= hook :admin_order_tabs, {:current => current} do %>
+ <% unless @order.completed? %>
+ <li<%== ' class="active"' if current == "Order Details" %>>
+ <%= link_to t("order_details"), edit_admin_order_url(@order) %>
+ </li>
+ <li<%== ' class="active"' if current == "Customer Details" %>>
+ <%= link_to t("customer_details"), user_admin_order_url(@order) %>
+ </li>
+ <% else %>
+ <li<%== ' class="active"' if current == "Order Details" %>>
+ <%= link_to t("order_details"), admin_order_url(@order) %>
+ </li>
+ <li<%== ' class="active"' if current == "Customer Details" %>>
+ <%= link_to t("customer_details"), user_admin_order_url(@order) %>
+ </li>
+ <% end %>
+
+
+
+ <% end %>
+ </ul>
+
+<% end %>
View
23 app/views/admin/supplier_taxons/_form.html.erb
@@ -0,0 +1,23 @@
+<%= hook :admin_inside_taxon_form, {:f => f} do %>
+ <%= f.field_container :name do %>
+ <%= f.label :name, t("name") %> <span class="required">*</span><br />
+ <%= error_message_on :taxon, :name, :class => 'fullwidth title' %>
+ <%= text_field :taxon, :name %>
+ <% end %>
+
+ <%= f.field_container :permalink_part do %>
+ <%= f.label :permalink_part, t("permalink") %><span class="required">*</span><br />
+ <%= @taxon.permalink.split("/")[0...-1].join("/") + "/" %><%= text_field_tag :permalink_part, @permalink_part %>
+ <% end %>
+
+ <%= f.field_container :icon do %>
+ <%= f.label :icon, t('icon') %><br />
+ <%= f.file_field :icon %>
+ <% end %>
+
+ <%= f.field_container :description do %>
+ <%= f.label :description, t(:description) %><br />
+ <%= f.text_area :description %>
+ <% end %>
+
+<% end %>
View
23 app/views/admin/supplier_taxons/_taxon_table.html.erb
@@ -0,0 +1,23 @@
+<table class="index">
+ <thead>
+ <tr>
+ <th><%= t("name") %></th>
+ <th><%= t("path") %></th>
+ <th></th>
+ </tr>
+ </thead>
+ <tbody>
+ <% taxons.each do |taxon| %>
+ <tr id="<%= dom_id(taxon)%>">
+ <td><%= taxon.name %></td>
+ <td><%= taxon_path taxon %></td>
+ <td lass="actions">
+ <%= link_to_delete taxon, :url => remove_admin_supplier_taxon_url(@supplier, taxon), :name => icon("delete") + ' ' + t("remove") %>
+ </td>
+ </tr>
+ <% end %>
+ <% if taxons.empty? %>
+ <tr><td colspan="3"><%= t('none') %>.</td></tr>
+ <% end %>
+ </tbody>
+</table>
View
33 app/views/admin/supplier_taxons/available.js.erb
@@ -0,0 +1,33 @@
+<script type="text/javascript">
+ function displayRow(){
+ var row = document.getElementById("captionRow");
+ if (row.style.display == '') row.style.display = 'none';
+ else row.style.display = '';
+ }
+</script>
+<h4><%= t('available_taxons') %></h4>
+<table class="index">
+ <thead>
+ <tr>
+ <th><%= t("name") %></th>
+ <th><%= t("path") %></th>
+ <th><%= t("action") %></th>
+ </tr>
+ </thead>
+ <tbody>
+ <% @taxons.each do |taxon| %>
+ <tr id="<%= dom_id(taxon, :sel) %>">
+ <td><%= taxon.name %></td>
+ <td><%= taxon_path taxon %></td>
+ <td class="actions">
+ <%= link_to icon('add') + ' ' + t("select"),
+ select_admin_supplier_taxon_path(@supplier, taxon),
+ :remote => true, :class => 'iconlink' %>
+ </td>
+ </tr>
+ <% end %>
+ <% if @taxons.empty? %>
+ <tr><td colspan="3"><%= t('no_match_found') %>.</td></tr>
+ <% end %>
+ </tbody>
+</table>
View
11 app/views/admin/supplier_taxons/edit.html.erb
@@ -0,0 +1,11 @@
+<%= render :partial => 'admin/shared/configuration_menu' %>
+
+<h1><%= t("taxon_edit")%></h1>
+
+<%= form_for(:taxon, :url => admin_taxonomy_taxon_url(@taxonomy, @taxon), :html => { :method => :put, :multipart => true}) do |f| %>
+ <%= render :partial => 'form', :locals => {:f => f} %>
+
+ <p class="form-buttons">
+ <%= button t("update") %> <%= t("or") %> <%= link_to t("cancel"), edit_admin_taxonomy_url(@taxonomy) %>
+ </p>
+<% end %>
View
1  app/views/admin/supplier_taxons/remove.html.erb
@@ -0,0 +1 @@
+<%= render :partial => "taxon_table", :locals => {:taxons => @taxons} %>
View
2  app/views/admin/supplier_taxons/select.js.erb
@@ -0,0 +1,2 @@
+$("#selected-taxons").html("<%= escape_javascript(render(:partial => "taxon_table", :locals => {:taxons => @taxons})) %>");
+$("#<%= dom_id @taxon, :sel %>").hide();
View
18 app/views/admin/supplier_taxons/selected.html.erb
@@ -0,0 +1,18 @@
+<h1>Editing Vendor</h1>
+
+<%= render :partial => 'admin/suppliers/supplier_tabs', :locals => {:current => "Taxons"} %>
+
+<%= form_tag({:controller => "supplier_taxons", :action => "update_taxons"}, :method => :post) do %>
+ <h3>Category</h3>
+ <ul>
+ <% @options.each do |o| %>
+ <%- if @supplier.taxons.select{|p| p.name == o.name}.present? %>
+ <li><%= check_box_tag o.name, o.id, true %><%= label_tag o.name %></li>
+ <% else %>
+ <li><%= check_box_tag o.name, o.id %><%= label_tag o.name %></li>
+ <% end %>
+ <% end %>
+ </ul>
+ <%= submit_tag "Update" %>
+<% end %>
+
View
75 app/views/admin/suppliers/_edit_form.html.erb
@@ -0,0 +1,75 @@
+<table class="admin-report" width="545">
+ <tr>
+ <td valign="top">Company name:</td>
+ <td><%= f.text_field :title, :value => @supplier.title %></td>
+ </tr>
+ <tr>
+ <td valign="top">Company Description:</td>
+ <td><%= f.text_field :notes, :value => @supplier.notes %></td>
+ </tr>
+</table>
+
+<h3>Company Information</h3>
+<table class="admin-report" width="545">
+ <tr>
+ <td valign="top">Phone:</td>
+ <td><%= f.text_field :phone, :value => @supplier.phone %></td>
+ </tr>
+ <tr>
+ <td valign="top">Address:</td>
+ <td><%= f.text_field :address1, :value => @supplier.address1 %></td>
+ </tr>
+ <tr>
+ <td valign="top">Town:</td>
+ <td><%= f.text_field :town, :value => @supplier.town %></td>
+ </tr>
+ <tr>
+ <td valign="top">State:</td>
+ <td><%= f.collection_select :state_id, State.find(:all, :order => 'name ASC'), :id, :name, :include_blank => true %></td>
+ </tr>
+ <tr>
+ <td valign="top">Market:</td>
+ <td><%= f.collection_select :city_id, City.find(:all, :order => 'name ASC'), :id, :name, :include_blank => true %></td>
+ </tr>
+ <tr>
+ <td valign="top">Zip-code:</td>
+ <td><%= f.text_field :zip_code, :value => @supplier.zip_code %></td>
+ </tr>
+ <tr>
+ <td valign="top">Fax:</td>
+ <td><%= f.text_field :fax, :value => @supplier.fax %></td>
+ </tr>
+ <tr>
+ <td valign="top">Email:</td>
+ <td><%= f.text_field :email, :value => @supplier.email %></td>
+ </tr>
+ <tr>
+ <td valign="top">Facebook:</td>
+ <td><%= f.text_field :facebook, :value => @supplier.facebook %></td>
+ </tr>
+ <tr>
+ <td valign="top">Twitter:</td>
+ <td><%= f.text_field :twitter, :value => @supplier.twitter %></td>
+ </tr>
+ <tr>
+ <td valign="top">Website:</td>
+ <td><%= f.text_field :website, :value => @supplier.website %></td>
+ </tr>
+ <tr>
+ <td valign="top">Products Sold:</td>
+ <td><%= f.text_area :products_sold %></td>
+ </tr>
+</table>
+
+<h3>Owner Information</h3>
+<table class="admin-report" width="545">
+ <tr>
+ <td valign="top">Owner Name:</td>
+ <td><%= f.text_field :name, :value => @supplier.name %></td>
+ </tr>
+ <tr>
+ <td valign="top">Owner Description:</td>
+ <td><%= f.text_field :description2, :value => @supplier.description2 %></td>
+ </tr>
+</table>
+
View
18 app/views/admin/suppliers/_edit_hours_form.html.erb
@@ -0,0 +1,18 @@
+<tr>
+ <td><h4><%= day %></h4></td>
+ <% outcome = @supplier.hours.first.send(day.downcase) %>
+ <% if outcome == "Closed" || outcome == "Information Unavailable" %>
+ <% if outcome == "Information Unavailable" %>
+ <% outcome = "Unavailable" %>
+ <% end %>
+ <td><%= select_tag "#{day}_closed", options_for_select(@closed, outcome) %></td>
+ <% else %>
+ <td><%= select_tag "#{day}_closed", options_for_select(@closed, "Open") %></td>
+ <% end %>
+ <td>From: <%= select_tag "#{day}_begin", options_for_select(@hours, find_hours(outcome)[0]) %></td>
+ <td><%= select_tag "#{day}_begin_mins", options_for_select(@minutes,find_minutes(outcome)[0]) %></td>
+ <td><%= select_tag "#{day}_begin_type", options_for_select(@periods,find_periods(outcome)[0]) %>, to</td>
+ <td><%= select_tag "#{day}_end", options_for_select(@hours,find_hours(outcome)[1]) %><td>
+ <td><%= select_tag "#{day}_end_mins", options_for_select(@minutes, find_minutes(outcome)[1]) %></td>
+ <td><%= select_tag "#{day}_end_type", options_for_select(@periods,find_periods(outcome)[1]) %></td>
+</tr>
View
60 app/views/admin/suppliers/_form.html.erb
@@ -0,0 +1,60 @@
+<table class="admin-report" width="545">
+ <tr>
+ <td valign="top">Company name:</td>
+ <td><%= f.text_field :title %></td>
+ </tr>
+ <tr>
+ <td valign="top">Company Description:</td>
+ <td><%= f.text_field :notes %></td>
+ </tr>
+</table>
+
+<h3>Information</h3>
+<table class="admin-report" width="545">
+ <tr>
+ <td valign="top">Phone:</td>
+ <td><%= f.text_field :phone %></td>
+ </tr>
+ <tr>
+ <td valign="top">Fax:</td>
+ <td><%= f.text_field :fax %></td>
+ </tr>
+ <tr>
+ <td valign="top">Email:</td>
+ <td><%= f.text_field :email %></td>
+ </tr>
+ <tr>
+ <td valign="top">Facebook:</td>
+ <td><%= f.text_field :facebook %></td>
+ </tr>
+ <tr>
+ <td valign="top">Twitter:</td>
+ <td><%= f.text_field :twitter %></td>
+ </tr>
+ <tr>
+ <td valign="top">Website:</td>
+ <td><%= f.text_field :website %></td>
+ </tr>
+</table>
+
+<h3>Proprietor Information</h3>
+<table class="admin-report" width="545">
+ <tr>
+ <td valign="top">Owner Name:</td>
+ <td><%= f.text_field :name %></td>
+ </tr>
+</table>
+
+ <h3>Supplier Images</h3>
+ <%= f.fields_for :images do |image| %>
+ <% if !image.object.attachment_file_name.nil? %>
+ <span class="supplier_image">
+ <%= image_tag(image.object.attachment.url) %>
+ </span>
+ <% else %>
+ <p />
+ <h4><%= "Upload New Image" %></h4>
+ <%= image.file_field :attachment if image.object.attachment_file_name.nil? %>
+ <% end %>
+ <% end %>
+
View
11 app/views/admin/suppliers/_hours_form.html.erb
@@ -0,0 +1,11 @@
+<tr>
+ <td><h4><%= day %></h4></td>
+ <td><%= select_tag "#{day}_closed", "<option>Unavailable</option><option>Open</option><option>Closed</option>".html_safe %></td>
+ <td>From: <%= select_tag "#{day}_begin", "<option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option><option>11</option><option>12</option>".html_safe %></td>
+ <td><%= select_tag "#{day}_begin_mins", "<option>00</option><option>15</option><option>30</option><option>45</option>".html_safe %></td>
+ <td><%= select_tag "#{day}_begin_type", "<option>am</option><option>pm</option>".html_safe %>, to</td>
+ <td><%= select_tag "#{day}_end", "<option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option><option>11</option><option>12</option>".html_safe %></td>
+ <td><%= select_tag "#{day}_end_mins", "<option>00</option><option>15</option><option>30</option><option>45</option>".html_safe %></td>
+ <td><%= select_tag "#{day}_end_type", "<option>pm</option><option>am</option>".html_safe %></td>
+
+</tr>
View
11 app/views/admin/suppliers/_image_form.html.erb
@@ -0,0 +1,11 @@
+<%= f.fields_for :images do |a| %>
+ <%= a.label :image %>
+ <%= a.file_field :attachment %>
+<% end %>
+
+<% if @supplier %>
+ <% @supplier.images.each do |image| %>
+ <%= image_tag(image) %>
+ <% end %>
+<% end %>
+
View
24 app/views/admin/suppliers/_supplier.html.erb
@@ -0,0 +1,24 @@
+<h2>Supplier Info: <%= supplier.title %></h2>
+<ul>
+ <li><b>Company name:</b> <%= supplier.title %></li>
+ <li><b>Vendor page:</b> <%= link_to supplier.title, supplier_path(supplier) %></li>
+ <li><b>Description:</b> <%= supplier.notes %></li>
+ <li><b>Phone:</b> <%= supplier.phone %></li>
+ <li><b>Fax:</b><%= supplier.fax %></li>
+ <li><b>Email:</b><%= supplier.email %></li>
+ <li><b>Facebook:</b><%= supplier.facebook %></li>
+ <li><b>Twitter:</b><%= supplier.twitter %></li>
+ <li><b>Website:</b><%= supplier.website %></li>
+</ul>
+<h2>Proprietor Info</h2>
+<ul>
+ <li><b>Owner Name:</b><%= supplier.name %></li>
+</ul>
+
+<h2>Images</h2>
+<% supplier.images.each do |image| %>
+ <ul>
+ <li><%= image_tag(image.attachment)%></li>
+ </ul>
+<% end %>
+
View
12 app/views/admin/suppliers/_supplier_tabs.html.erb
@@ -0,0 +1,12 @@
+<% content_for :sidebar do %>
+ <ul class="sidebar supplier-menu">
+ <%= hook :admin_supplier_tabs, {:current => current} do %>
+ <li<%== ' class="active"' if current == "Supplier Details" %>>
+ <%= link_to "Supplier Details", edit_admin_supplier_url(@supplier) %>
+ </li>
+ <li<%== ' class="active"' if current == "Taxons" %>>
+ <%= link_to t("taxons"), selected_admin_supplier_taxons_url(@supplier) %>
+ </li>
+ <% end %>
+ </ul>
+<% end %>
View
25 app/views/admin/suppliers/_suppliers_table.html.erb
@@ -0,0 +1,25 @@
+<table class="index">
+ <thead>
+ <tr>
+ <th><%= t("supplier_name") %></th>
+ <th></th>
+ </tr>
+ </thead>
+ <tbody>
+ <% unless supplier.blank? %>
+ <tr id="<%= dom_id(supplier, :sel)%>">
+ <td><%= supplier.name %></td>
+ <td class="actions">
+ <%= image_tag "spinner.gif", :style => "display:none", :id => "#{dom_id(supplier, :rem_spinner)}" %>
+ <%= link_to_remote icon('delete') + ' ' + t('remove'),
+ {:url => remove_admin_product_supplier_url(@product, supplier),
+ :loading => "jQuery('##{dom_id(supplier, :rem_spinner)}').show()",
+ :update => 'selected-supplier',
+ :complete => "jQuery('##{dom_id(supplier, :sel)}').remove(); jQuery('##{dom_id(supplier, :rem_spinner)}').hide();"}, :class => 'iconlink' %>
+ </td>
+ </tr>
+ <% else %>
+ <tr><td colspan="3"><%= t('none') %>.</td></tr>
+ <% end %>
+ </tbody>
+</table>
View
14 app/views/admin/suppliers/_upload_image.html.erb
@@ -0,0 +1,14 @@
+<table class="basic-table">
+<h3>Company images</h3>
+ <tr>
+ <td><%= t("filename") %>:</td>
+ <td><%= f.file_field :attachment %></td>
+ </tr>
+ <tr>
+ <td><%= t("alt_text") %>:</td>
+ <td><%= f.text_field :alt, :value => "There is no image available" %></td>
+ </tr>
+ <tr>
+ <td><%= f.hidden_field :viewable_id, :value => @supplier.id %></td>
+ </tr>
+</table>
View
34 app/views/admin/suppliers/available.js.erb
@@ -0,0 +1,34 @@
+<script type="text/javascript">
+ function displayRow(){
+ var row = document.getElementById("captionRow");
+ if (row.style.display == '') row.style.display = 'none';
+ else row.style.display = '';
+ }
+</script>
+<h4><%= t('available_suppliers') %></h4>
+<table class="index">
+ <thead>
+ <tr>
+ <th><%= t("name") %></th>
+ <th><%= t("action") %></th>
+ </tr>
+ </thead>
+ <tbody>
+ <% @available_suppliers.each do |supplier| %>
+ <tr id="<%= dom_id(supplier) %>">
+ <td><%= supplier.name %></td>
+ <td class="actions">
+ <%= image_tag "spinner.gif", :style => "display:none", :id => "#{dom_id(supplier, :spinner)}" %>
+ <%= link_to_remote icon('add') + ' ' + t('select'),
+ {:url => select_admin_product_supplier_path(@product, supplier),
+ :loading => "jQuery('##{dom_id(supplier, :spinner)}').show()",
+ :update => 'selected-supplier',
+ :complete => "jQuery('##{dom_id(supplier)}').remove(); jQuery('##{dom_id(supplier, :spinner)}').hide();"}, :class => 'iconlink' %>
+ </td>
+ </tr>
+ <% end %>
+ <% if @available_suppliers.empty? %>
+ <tr><td colspan="3"><%= t('no_match_found') %>.</td></tr>
+ <% end %>
+ </tbody>
+</table>
View
13 app/views/admin/suppliers/edit.html.erb
@@ -0,0 +1,13 @@
+<%= render :partial => 'admin/suppliers/supplier_tabs', :locals => {:current => "Supplier Details"} %>
+
+<h1>Edit Supplier</h1>
+
+<%= form_for @supplier, :url => object_url, :html => { :method => :put, :multipart => true } do |f| %>
+ <%= render :partial => "form", :locals => { :f => f } %>
+
+ <p class="form-buttons">
+ <%= button t("update") %>
+ <%= t('or') %> <%= link_to t("cancel"), "#", :id => "cancel_link" %>
+ </p>
+<% end %>
+
View
97 app/views/admin/suppliers/index.html.erb
@@ -0,0 +1,97 @@
+<%= render :partial => 'admin/shared/configuration_menu' %>
+<h1>
+ <%= t("suppliers") %>
+</h1>
+<% if current_user.has_role?("admin") %>
+ <div class='toolbar'>
+ <ul class='actions'>
+ <li id="new_product_link">
+ <%= button_link_to "New Supplier", new_admin_supplier_path %>
+ </li>
+ </ul>
+ <br class='clear' />
+ </div>
+ <table class="index" width="545">
+ <thead>
+ <tr>
+ <th>
+ <%= t("supplier_name") %>
+ </th>
+ <th>
+ <%= t("notes") %>
+ </th>
+ <th>
+ Actions
+ </th>
+ <th>
+ Featured
+ </th>
+ </tr>
+ </thead>
+ <tbody>
+ <% @suppliers.each do |supplier| %>
+ <tr class="<%= cycle('even', 'odd') %>">
+ <td>
+ <%= link_to supplier.title, edit_admin_supplier_path(supplier) %>
+ </td>
+ <td>
+ <%= truncate(supplier.notes, :length => 50) %>
+ </td>
+ <td class='actions'>
+ <%= link_to_edit supplier, :class => 'edit' %>
+ &nbsp;
+ <%= link_to_delete supplier %>
+ </td>
+ <td>
+ <% if supplier.featured %>
+ <%= link_to "Yes", admin_supplier_feature_path(supplier) %>
+ <% else %>
+ <%= link_to "No", admin_supplier_feature_path(supplier) %>
+ <% end %>
+ </td>
+ </tr><% end %>
+ </tbody>
+ </table>
+<% else %>
+ <table class="index" width="545">
+ <thead>
+ <tr>
+ <th>
+ <%= t("supplier_name") %>
+ </th>
+ <th>
+ <%= t("notes") %>
+ </th>
+ <th>
+ Actions
+ </th>
+ <th>
+ Featured
+ </th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>
+ <%= link_to @supplier.title, edit_admin_supplier_path(@supplier) %>
+ </td>
+ <td>
+ <%= truncate(@supplier.notes, :length => 50) %>
+ </td>
+ <td class='actions'>
+ <%= link_to_edit @supplier, :class => 'edit' %>
+ </td>
+ <td>
+ <% if @supplier.featured %>
+ Yes
+ <% else %>
+ No
+ <% end %>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+<% end %>
+<% if current_user.has_role?("admin") %>
+ <%= link_to t("new_supplier"), new_object_url %>
+<% end %>
View
20 app/views/admin/suppliers/line_items.html.erb
@@ -0,0 +1,20 @@
+<table class="index">
+ <tbody id='line-items'>
+ <tr>
+ <th><%= t('item_description') %></th>
+ <th class="supplier"><%= t('supplier_name') %></th>
+ <th class="price"><%= t('price') %></th>
+ <th class="qty"><%= t('qty') %></th>
+ <th class="total_display"><span><%= t('total') %></span></th>
+ </tr>
+ <% @order.line_items.each do |item| %>
+ <tr >
+ <td width="300"><%=item.variant.product.name-%> <%= "(" + variant_options(item.variant) + ")" unless item.variant .option_values.empty? %></td>
+ <td valign="top"><%=item.variant.product.supplier.name if item.variant.product.supplier -%></td>
+ <td valign="top"><%= number_to_currency item.price -%></td>
+ <td valign="top"><%=item.quantity-%></td>
+ <td valign="top" class="total_display"><span><%= number_to_currency (item.price * item.quantity)-%></span></td>
+ </tr>
+ <% end %>
+ </tbody>
+</table>
View
13 app/views/admin/suppliers/new.html.erb
@@ -0,0 +1,13 @@
+<%= render :partial => 'admin/shared/configuration_menu' %>
+
+<h1><%= t("new_supplier") %></h1>
+
+<%= form_for @supplier, :url => collection_url, :html => { :multipart => true } do |f| %>
+ <%= render :partial => "form", :locals => { :f => f } %>
+
+ <p class="form-buttons">
+ <%= button t("new") %>
+ <%= t('or') %> <%= link_to t("cancel"), "#", :id => "cancel_link" %>
+ </p>
+<% end %>
+
View
1  app/views/admin/suppliers/remove.html.erb
@@ -0,0 +1 @@
+<%= render :partial => "suppliers_table", :locals => {:supplier => @supplier} %>
View
1  app/views/admin/suppliers/select.html.erb
@@ -0,0 +1 @@
+<%= render :partial => "suppliers_table", :locals => {:supplier => @supplier} %>
View
40 app/views/admin/suppliers/selected.html.erb
@@ -0,0 +1,40 @@
+<%= render :partial => 'admin/suppliers/supplier_tabs', :locals => {:current => "Taxons"} %>
+
+<div id="selected-taxons">
+ <%= render :partial => "taxon_table", :locals => {:taxons => @taxons} %>
+</div>
+
+<%= form_tag('#') do %>
+ <label><%= t('search') %>:</label>
+ <input id="searchtext" size="25">
+<% end %>
+
+<%= javascript_tag do %>
+ function search_for_taxons(){
+ jQuery.ajax({
+ data: {q: jQuery("#searchtext").val() },
+ dataType: 'script',
+ success: function(request){
+ jQuery('#search_hits').html(request);
+ },
+ type: 'post',
+ url: '<%= available_admin_supplier_taxons_url(@supplier) %>'
+ });
+ }
+
+ jQuery("#searchtext").keypress(function (e) {
+ if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
+ search_for_taxons();
+
+ return false;
+ } else {
+ return true;
+ }
+ });
+
+ jQuery("#searchtext").delayedObserver(function() {
+ search_for_taxons();
+ }, 0.75);
+<% end %>
+<br/>
+<div id="search_hits"></div>
View
2  app/views/admin/suppliers/show.html.erb
@@ -0,0 +1,2 @@
+<%= render :partial => "supplier", :locals => {:supplier => @supplier} %>
+<%= link_to "Edit Profile", edit_admin_supplier_path(@supplier) %>
View
1  app/views/admin/vendor_overview/index.html.erb
@@ -0,0 +1 @@
+puts"HELLO"
View
47 app/views/shared/_supplier_invoices.html.erb
@@ -0,0 +1,47 @@
+
+<% @invoices.each do |invoice| %>
+
+ <div class="supplier_invoice">
+ <h3><%= invoice.supplier.title %></h3>
+ <table class="index">
+ <tr>
+ <th>Product Name</th>
+ <th>Product price</th>
+ <th>Quantity</th>
+ <th>Totals</th>
+ </tr>
+
+ <% invoice.invoice_items.each do |item| %>
+ <tr bgcolor="#F9FFB9">
+ <td width="600px"><%= item.line_item.product.name %> <%= "(" + variant_options(item.line_item.variant) + ")" unless item.line_item.variant.option_values.empty? %></td>
+ <td width="150px"><%= number_to_currency(item.line_item.variant.price) %></td>
+ <td width="75px"><%= item.quantity %></td>
+ <td><%= number_to_currency(item.line_item.variant.price * item.quantity) %></td>
+ </tr>
+ <% end %>
+ <tr>
+ <td>Order-total</td>
+ <td></td>
+ <td></td>
+ <td><%= number_to_currency(invoice.invoice_total) %></td>
+ </tr>
+ <tr>
+ <td>-(fee)</td>
+ <td></td>
+ <td></td>
+ <td><%= number_to_currency(invoice.invoice_total * @fee) %></td>
+ </tr>
+ <tr>
+ <td>Sub-total</td>
+ <td></td>
+ <td></td>
+ <td><%= number_to_currency(invoice.invoice_total * (1 - @fee)) %></td>
+ </tr>
+
+ </table>
+ </div>
+<% end %>
+
+
+
+
View
7 app/views/suppliers/_supplier.html.erb
@@ -0,0 +1,7 @@
+<div class="yui3-u-1-3">
+ <div class="vendor">
+ <% @products.each do |product|
+ <%= link_to product.name, product_path(product) %>
+ <% end %>
+ </div>
+</div>
View
13 app/views/suppliers/_supplier_list.erb
@@ -0,0 +1,13 @@
+<li class="suppliers">
+<div class="vendor-image">
+ <%= link_to supplier.images.first, supplier_path(supplier) %>
+</div>
+<div class="article-content">
+ <% if supplier.title %>
+ <h4><%= link_to supplier.title, supplier_path(supplier) %> </h4>
+ <% else %>
+ <h4><%= link_to supplier.name, supplier_path(supplier) %> </h4>
+ <% end %>
+ </p>
+</div>
+</li>
View
13 app/views/suppliers/index.html.erb
@@ -0,0 +1,13 @@
+<div class="search-sidebar">
+ <%= form_for @search do |f| %>
+ <p>
+ <%= f.label :search_vendors %>
+ <%= f.text_field :name_or_title_contains %>
+ </p>
+ <p class = "button"><%= f.submit "Search" %></p>
+ <% end %>
+</div>
+<div class="search-list">
+ <%= render :partial => "suppliers/supplier_list", :collection => @suppliers, :as => :supplier %>
+</div>
+<div class="clear"></div>
View
11 app/views/suppliers/show.html.erb
@@ -0,0 +1,11 @@
+<div id="spree_suppliers_show">
+ <h2><%= @supplier.title %></h2>
+ <%- if @supplier.name %>
+ <ul>
+ <li><%= @supplier.name %></li>
+ <li><%= @supplier.description %></li>
+ <li><%= @supplier.notes %></li>
+ </ul>
+ <% end %>
+</div>
+
View
11 app/views/suppliers/supplier_list.erb
@@ -0,0 +1,11 @@
+<li>
+<div class="vendor-image">
+ <%= link_to supplier.images.first supplier_path(supplier) %>
+</div>
+<div class="article-content">
+ <h3><%= link_to supplier.title, supplier_path(supplier) %> </h3>
+ <p class="supplier_about">
+ <%= supplier.notes%> <br />
+ <span class="phone"><%= supplier.phone %></span></p>
+</div>
+</li>
View
37 config/routes.rb
@@ -0,0 +1,37 @@
+Rails.application.routes.draw do
+ # Add your extension routes here
+ resources :suppliers
+ resources :supplier_invoices
+ resources :invoice_items
+
+ namespace :admin do
+
+ resources :suppliers do
+ get 'feature'
+ resources :taxons, :controller => "supplier_taxons" do
+ member do
+ get :select
+ delete :remove
+ end
+ collection do
+ post :available
+ post :batch_select
+ get :selected
+ post :update_taxons
+ end
+ end
+ end
+
+ resources :products do
+ resources :suppliers, :member => {:select => :post, :remove => :post}, :collection => {:available => :post, :selected => :get}
+ member do
+ get :publish
+ get :unpublish
+ end
+ end
+ resources :orders do
+ resources :suppliers, :collection => {:line_items => :get}
+ end
+
+ end
+end
View
8 db/migrate/20120131160039_create_suppliers.rb
@@ -0,0 +1,8 @@
+class CreateSuppliers < ActiveRecord::Migration
+ def change
+ create_table :suppliers do |t|
+
+ t.timestamps
+ end
+ end
+end
View
16 db/migrate/20120131160855_add_fields_to_suppliers.rb
@@ -0,0 +1,16 @@
+class AddFieldsToSuppliers < ActiveRecord::Migration
+ def change
+ add_column :suppliers, :name, :string
+ add_column :suppliers, :title, :string
+ add_column :suppliers, :phone, :string
+ add_column :suppliers, :fax, :string
+ add_column :suppliers, :email, :string
+ add_column :suppliers, :website, :string
+ add_column :suppliers, :notes, :text
+ add_column :suppliers, :featured, :boolean
+ add_column :suppliers, :twitter, :string
+ add_column :suppliers, :facebook, :string
+ add_column :suppliers, :description, :text
+ add_column :suppliers, :user_id, :integer
+ end
+end
View
12 db/migrate/20120131161247_create_supplier_invoices.rb
@@ -0,0 +1,12 @@
+class CreateSupplierInvoices < ActiveRecord::Migration
+ def change
+ create_table :supplier_invoices do |t|
+ t.integer :order_id
+ t.integer :item_count
+ t.decimal :invoice_total
+ t.integer :supplier_id
+
+ t.timestamps
+ end
+ end
+end
View
12 db/migrate/20120131161610_create_invoice_items.rb
@@ -0,0 +1,12 @@
+class CreateInvoiceItems < ActiveRecord::Migration
+ def change
+ create_table :invoice_items do |t|
+ t.integer :product_id
+ t.integer :quantity
+ t.integer :supplier_invoice_id
+ t.integer :line_item_id
+
+ t.timestamps
+ end
+ end
+end
View
143 db/seeds.rb
@@ -0,0 +1,143 @@
+# Loads seed data out of default dir
+SpreeCore::Engine.load_seed if defined?(SpreeCore)
+
+puts "Create payment method"
+ii = PaymentMethod::Check.create :name => "test", :active => true, :environment => "development"
+
+puts "Create shipping method"
+
+s = ShippingMethod.new :name => "Shipping", :zone => Zone.find_by_name("North America")
+s.calculator = Calculator::FlatRate.new :calculable => s.id, :calculable_type => "ShippingMethod"
+s.save
+
+puts "Create Users"
+
+@admin = User.create :email => "spree@example.com", :password => "password", :password_confirmation => "password", :first_name => "Spree", :last_name => "Cat", :description => "Sup."
+@admin.roles = [Role.first]
+@admin.save
+@user = User.create :email => "test@example.com", :password => "password", :password_confirmation => "password"
+@user2 = User.create :email => "test2@example.com", :password => "password", :password_confirmation => "password"
+
+puts"Create Taxons"
+
+t = Taxonomy.create :name => "Producers"
+s = Taxonomy.create :name => "Products"
+
+supplier = t.taxons.create :name => "Suppliers", :parent_id => t.id
+toys = t.taxons.create :name => "Toys", :parent_id => t.id
+candy = t.taxons.create :name => "Candy", :parent_id => s.id
+t.taxons.create :name => "Clothing", :parent_id => s.id
+t.taxons.create :name => "Recipes", :parent_id => t.id
+
+s.taxons.create :name => "Potent Potables", :parent_id => t.id
+s.taxons.create :name => "Childrens", :parent_id => s.id
+s.taxons.create :name => "Baked Goods", :parent_id => s.id
+
+
+puts"Create Suppliers"
+
+supplier1 = Supplier.create(:name => "Farmer Bob", :featured => true, :notes => "Farmer Bob is a specialist in growing watermelon, squash, and tomatoes", :title => "Farmer Bob's Market")
+supplier1.taxons = [supplier]
+supplier1.images.create(:attachment => File.open(File.join(Rails.root, "db", "seeds", "images", "chicken.jpg")))
+supplier1.save
+
+supplier2 = Supplier.create(:name => "Maury", :title => "Moonshine Maury", :featured => true)
+supplier2.images.create(:attachment => File.open(File.join(Rails.root, "db", "seeds", "images", "goat.jpg")))
+supplier2.taxons = [supplier]
+supplier2.save
+
+supplier3 = Supplier.create(:name => "Fresh", :title => "Freshfully Farms", :featured => true)
+supplier3.images.create(:attachment => File.open(File.join(Rails.root, "db", "seeds", "images", "watermelon.jpg")))
+supplier3.taxons = [supplier]
+supplier3.save
+
+supplier4 = Supplier.create(:name => "Betty", :title => "Betty's Bees", :featured => true)
+supplier4.images.create(:attachment => File.open(File.join(Rails.root, "db", "seeds", "images", "flower.jpg")))
+supplier4.taxons = [supplier]
+supplier4.save
+
+supplier5 = Supplier.create(:name => "Larry", :title => "Larry's Lemonade", :description => "I am a supplier")
+supplier5.images.create(:attachment => File.open(File.join(Rails.root, "db", "seeds", "images", "cow.jpg")))
+supplier5.taxons = [supplier]
+supplier5.save
+
+supplier6 = Supplier.create(:name => "Gary", :title => "Gardener Gary")
+supplier6.images.create(:attachment => File.open(File.join(Rails.root, "db", "seeds", "images", "banana.jpg")))
+supplier6.taxons = [supplier]
+supplier6.save
+
+puts "Creating Sample Products"
+
+a = Product.create :name => "Grapes", :price => "4.99", :permalink => "grapes", :supplier_id => supplier1.id, :available_on => 3.days.ago
+a.images.create(:attachment => File.open(File.join(Rails.root, "db", "seeds", "images", "grapes.jpg")))
+a.taxons = [candy]
+a.save
+
+c = Product.create :name => "Banana", :price => "6.99", :permalink => "banana", :supplier_id => supplier3.id, :available_on => 3.days.ago
+c.images.create(:attachment => File.open(File.join(Rails.root, "db", "seeds", "images", "banana.jpg")))
+c.taxons = [candy]
+c.save
+
+d = Product.create :name => "Corn", :price => "4.99", :permalink => "corn", :supplier_id => supplier4.id, :available_on => 3.days.ago
+d.images.create(:attachment => File.open(File.join(Rails.root, "db", "seeds", "images", "cow.jpg")))
+d.taxons = [candy]
+d.save
+
+e = Product.create :name => "Blueberries", :price => "4.99", :permalink => "blueberries", :supplier_id => supplier4.id, :available_on => 3.days.ago
+e.images.create(:attachment => File.open(File.join(Rails.root, "db", "seeds", "images", "blueberry.jpg")))
+e.taxons = [candy]
+e.save
+
+f = Product.create :name => "Strawberries", :price => "3.99", :permalink => "strawberries", :supplier_id => supplier5.id, :available_on => 3.days.ago
+f.images.create(:attachment => File.open(File.join(Rails.root, "db", "seeds", "images", "strawberry.jpg")))
+f.taxons = [candy]
+f.save
+
+g = Product.create :name => "Oranges", :price => "2.99", :permalink => "oranges", :supplier_id => supplier6.id, :available_on => 3.days.ago
+g.images.create(:attachment => File.open(File.join(Rails.root, "db", "seeds", "images", "orange.jpg")))
+g.taxons = [candy]
+g.save
+
+h =Product.create :name => "Cranberry", :price => "0.99", :permalink => "cranberry", :supplier_id => supplier1.id, :available_on => 3.days.ago
+h.images.create(:attachment => File.open(File.join(Rails.root, "db", "seeds", "images", "cherries.jpg")))
+h.taxons = [candy]
+h.save
+
+i = Product.create :name => "Squash", :price => "2.99", :permalink => "squash", :supplier_id => supplier2.id, :available_on => 3.days.ago
+i.images.create(:attachment => File.open(File.join(Rails.root, "db", "seeds", "images", "squash.jpg")))
+i.taxons = [toys]
+i.save
+
+j = Product.create :name => "Green Beans", :price => "1.99", :permalink => "greenbeans", :supplier_id => supplier3.id, :available_on => 3.days.ago
+j.images.create(:attachment => File.open(File.join(Rails.root, "db", "seeds", "images", "greenbeans.jpg")))
+j.taxons = [toys]
+j.save
+
+g = Product.create :name => "Floranges", :price => "2.99", :permalink => "floranges", :supplier_id => supplier6.id, :available_on => 3.days.ago
+g.images.create(:attachment => File.open(File.join(Rails.root, "db", "seeds", "images", "orange.jpg")))
+g.taxons = [candy]
+g.save
+
+h =Product.create :name => "Handberry", :price => "0.99", :permalink => "handberry", :supplier_id => supplier1.id, :available_on => 3.days.ago
+h.images.create(:attachment => File.open(File.join(Rails.root, "db", "seeds", "images", "cherries.jpg")))
+h.taxons = [candy]
+h.save
+
+i = Product.create :name => "Tosh.0", :price => "2.99", :permalink => "tosh", :supplier_id => supplier2.id, :available_on => 3.days.ago
+i.images.create(:attachment => File.open(File.join(Rails.root, "db", "seeds", "images", "squash.jpg")))
+i.taxons = [toys]
+i.save
+
+j = Product.create :name => "Kidney Beans", :price => "1.99", :permalink => "beans", :supplier_id => supplier3.id, :available_on => 3.days.ago
+j.images.create(:attachment => File.open(File.join(Rails.root, "db", "seeds", "images", "greenbeans.jpg")))
+j.taxons = [toys]
+j.save
+
+j = Product.create :name => "Liver Beans", :price => "1.99", :permalink => "liver beans", :supplier_id => supplier3.id, :available_on => 3.days.ago
+j.images.create(:attachment => File.open(File.join(Rails.root, "db", "seeds", "images", "greenbeans.jpg")))
+j.taxons = [toys]
+j.save
+
+
+
+puts "Finished Seed Data"
View
BIN  db/seeds/images/apple.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  db/seeds/images/apple.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  db/seeds/images/banana.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  db/seeds/images/blueberry.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  db/seeds/images/cherries.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  db/seeds/images/chicken.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  db/seeds/images/cow.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  db/seeds/images/flower.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  db/seeds/images/goat.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  db/seeds/images/grapes.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  db/seeds/images/greenapple.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  db/seeds/images/greenbeans.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  db/seeds/images/indie_candy.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  db/seeds/images/orange.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  db/seeds/images/squash.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  db/seeds/images/stock_user.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  db/seeds/images/strawberry.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  db/seeds/images/watermelon.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
29 lib/generators/spree_suppliers/install/install_generator.rb
@@ -0,0 +1,29 @@
+module SpreeSupplier
+ module Generators
+ class InstallGenerator < Rails::Generators::Base
+
+ def add_javascripts
+ append_file "app/assets/javascripts/store/all.js", "//= require store/spree_suppliers\n"
+ append_file "app/assets/javascripts/admin/all.js", "//= require admin/spree_suppliers\n"
+ end
+
+ def add_stylesheets
+ inject_into_file "app/assets/stylesheets/store/all.css", " *= require store/spree_suppliers\n", :before => /\*\//, :verbose => true
+ inject_into_file "app/assets/stylesheets/admin/all.css", " *= require admin/spree_suppliers\n", :before => /\*\//, :verbose => true
+ end
+
+ def add_migrations
+ run 'bundle exec rake railties:install:migrations FROM=spree_suppliers'
+ end
+
+ def run_migrations
+ res = ask "Would you like to run the migrations now? [Y/n]"
+ if res == "" || res.downcase == "y"
+ run 'bundle exec rake db:migrate'
+ else
+ puts "Skiping rake db:migrate, don't forget to run it!"
+ end
+ end
+ end
+ end
+end
View
192 lib/spree_suppliers.rb
@@ -0,0 +1,192 @@
+require 'spree_core'
+require 'spree_suppliers/engine'
+
+module SpreeSuppliers
+ class Engine < Rails::Engine
+ config.autoload_paths += %W(#{config.root}/lib)
+ def self.activate
+
+ LineItem.class_eval do
+ has_many :invoice_items
+ end
+
+ Image.class_eval do
+ belongs_to :supplier
+ end
+
+ Admin::OrdersController.class_eval do
+ def show
+ load_order
+ # optional fee that admin can charge to sell suppliers products for them
+ @fee = 0.10
+ if current_user.has_role?("vendor")
+ @invoices = @order.supplier_invoices
+ @invoices.select! {|s| s.supplier_id == current_user.supplier.id}
+ else
+ @invoices = @order.supplier_invoices
+ end
+ respond_with(@order)
+ end
+
+ def index
+ params[:search] ||= {}
+ params[:search][:completed_at_is_not_null] ||= '1' if Spree::Config[:show_only_complete_orders_by_default]
+ @show_only_completed = params[:search][:completed_at_is_not_null].present?
+ params[:search][:meta_sort] ||= @show_only_completed ? 'completed_at.desc' : 'created_at.desc'
+
+ @search = Order.metasearch(params[:search])
+
+ if !params[:search][:created_at_greater_than].blank?
+ params[:search][:created_at_greater_than] = Time.zone.parse(params[:search][:created_at_greater_than]).beginning_of_day rescue ""
+ end
+
+ if !params[:search][:created_at_less_than].blank?
+ params[:search][:created_at_less_than] = Time.zone.parse(params[:search][:created_at_less_than]).end_of_day rescue ""
+ end
+
+ if @show_only_completed
+ params[:search][:completed_at_greater_than] = params[:search].delete(:created_at_greater_than)
+ params[:search][:completed_at_less_than] = params[:search].delete(:created_at_less_than)
+ end
+
+ @orders = Order.metasearch(params[:search]).includes([:user, :shipments, :payments]).page(params[:page]).per(Spree::Config[:orders_per_page])
+
+ if current_user.has_role?("vendor")
+ @orders.select! {|o| o.supplier_invoices.select {|s| s.supplier_id == current_user.supplier.id}.size > 0}
+ end
+ respond_with(@orders)
+ end
+ end
+
+ Order.class_eval do
+ has_many :supplier_invoices
+ def generate_invoices(order)
+ @order = order
+ @order_products = @order.line_items
+ @suppliers = @order_products.collect{|item| item.product.supplier_id}.uniq
+ @invoices = @suppliers.count
+
+ for i in 0..@invoices - 1
+ @supplier_products = @order_products.select{|x| x.product.supplier_id == @suppliers[i]}
+ @product_count = @supplier_products.count
+ invoice = SupplierInvoice.create(:order_id => @order.id, :supplier_id => @suppliers[i], :item_count => @product_count)
+
+ @supplier_products.each do |item|
+ invoice.invoice_items.create(:product_id => item.product.id, :quantity => item.quantity, :line_item_id => item.id)
+ end
+
+ item_total = "0.00".to_d
+ invoice.invoice_items.each do |i|
+ item_total = (i.line_item.variant.price * i.quantity) + item_total
+ end
+ invoice.update_attributes(:invoice_total => item_total)
+ @invoice = invoice
+ #SupplierMailer.invoice_email(@invoice).deliver
+ end
+ end
+
+ def finalize!
+ update_attribute(:completed_at, Time.now)
+ InventoryUnit.assign_opening_inventory(self)
+ # lock any optional adjustments (coupon promotions, etc.)
+ adjustments.optional.each { |adjustment| adjustment.update_attribute('locked', true) }
+ # generate the invoices for each supplier
+ generate_invoices(self)
+ #OrderMailer.confirm_email(self).deliver
+
+ self.state_events.create({
+ :previous_state => 'cart',
+ :next_state => 'complete',
+ :name => 'order' ,
+ :user_id => (User.respond_to?(:current) && User.current.try(:id)) || self.user_id
+ })
+ end
+ end
+
+
+ Admin::ProductsController.class_eval do
+ before_filter :load
+ before_filter :load_index, :only => [:index]
+ before_filter :edit_before, :only => [:edit]
+ create.before :create_before
+ create.fails :reset
+ update.before :update_taxons
+
+ def load
+ @suppliers = Supplier.find(:all, :order => "name")
+ @options = Taxon.all
+ end
+
+ def load_index
+ if current_user.roles.member?(Role.find_by_name("vendor"))
+ @collection.select! {|c| c.supplier_id == current_user.supplier.id}
+ end
+ end
+
+ #indicate that we want to create a new product
+ def new
+ @object = Product.new()
+ @status = true
+ @suppliers = Supplier.all
+ end
+
+ def edit_before
+ @suppliers = Supplier.all
+ @status = false
+ end
+
+ def taxon_push object
+ object.taxons = []
+ Taxon.all.map {|m| object.taxons.push(Taxon.find_by_id(params[m.name])) if params.member?(m.name)}
+ return object
+ end
+
+ def reset
+ @status = true
+ end
+
+ def update_taxons
+ @object = taxon_push(@object)
+ end
+
+ def create_before
+ if current_user.has_role?("vendor")