spree_suppliers 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. data/Gemfile +22 -0
  2. data/LICENSE +26 -0
  3. data/README.md +80 -0
  4. data/Rakefile +31 -0
  5. data/Versionfile +9 -0
  6. data/app/assets/javascripts/admin/spree_suppliers.js +1 -0
  7. data/app/assets/javascripts/invoice_items.js.coffee +3 -0
  8. data/app/assets/javascripts/store/spree_suppliers.js +1 -0
  9. data/app/assets/javascripts/supplier_invoices.js.coffee +3 -0
  10. data/app/assets/javascripts/suppliers.js.coffee +3 -0
  11. data/app/assets/stylesheets/admin/spree_suppliers.css +3 -0
  12. data/app/assets/stylesheets/invoice_items.css.scss +3 -0
  13. data/app/assets/stylesheets/store/spree_suppliers.css +3 -0
  14. data/app/assets/stylesheets/supplier_invoices.css.scss +3 -0
  15. data/app/assets/stylesheets/suppliers.css.scss +4 -0
  16. data/app/controllers/admin/supplier_taxons_controller.rb +61 -0
  17. data/app/controllers/admin/suppliers_controller.rb +127 -0
  18. data/app/controllers/admin/vendor_overview_controller.rb +18 -0
  19. data/app/controllers/invoice_items_controller.rb +2 -0
  20. data/app/controllers/supplier_invoices_controller.rb +2 -0
  21. data/app/controllers/suppliers_controller.rb +15 -0
  22. data/app/models/invoice_item.rb +4 -0
  23. data/app/models/supplier.rb +8 -0
  24. data/app/models/supplier_invoice.rb +4 -0
  25. data/app/overrides/admin.rb +5 -0
  26. data/app/views/admin/orders/show.html.erb +34 -0
  27. data/app/views/admin/orders/user.html.erb +19 -0
  28. data/app/views/admin/products/_form.html.erb +114 -0
  29. data/app/views/admin/products/_suppliers_form.html.erb +4 -0
  30. data/app/views/admin/shared/_order_tabs_decide.html.erb +5 -0
  31. data/app/views/admin/shared/_vendor_order_tabs.html.erb +39 -0
  32. data/app/views/admin/supplier_taxons/_form.html.erb +23 -0
  33. data/app/views/admin/supplier_taxons/_taxon_table.html.erb +23 -0
  34. data/app/views/admin/supplier_taxons/available.js.erb +33 -0
  35. data/app/views/admin/supplier_taxons/edit.html.erb +11 -0
  36. data/app/views/admin/supplier_taxons/remove.html.erb +1 -0
  37. data/app/views/admin/supplier_taxons/select.js.erb +2 -0
  38. data/app/views/admin/supplier_taxons/selected.html.erb +18 -0
  39. data/app/views/admin/suppliers/_edit_form.html.erb +75 -0
  40. data/app/views/admin/suppliers/_edit_hours_form.html.erb +18 -0
  41. data/app/views/admin/suppliers/_form.html.erb +60 -0
  42. data/app/views/admin/suppliers/_hours_form.html.erb +11 -0
  43. data/app/views/admin/suppliers/_image_form.html.erb +11 -0
  44. data/app/views/admin/suppliers/_supplier.html.erb +24 -0
  45. data/app/views/admin/suppliers/_supplier_tabs.html.erb +12 -0
  46. data/app/views/admin/suppliers/_suppliers_table.html.erb +25 -0
  47. data/app/views/admin/suppliers/_upload_image.html.erb +14 -0
  48. data/app/views/admin/suppliers/available.js.erb +34 -0
  49. data/app/views/admin/suppliers/edit.html.erb +13 -0
  50. data/app/views/admin/suppliers/index.html.erb +97 -0
  51. data/app/views/admin/suppliers/line_items.html.erb +20 -0
  52. data/app/views/admin/suppliers/new.html.erb +13 -0
  53. data/app/views/admin/suppliers/remove.html.erb +1 -0
  54. data/app/views/admin/suppliers/select.html.erb +1 -0
  55. data/app/views/admin/suppliers/selected.html.erb +40 -0
  56. data/app/views/admin/suppliers/show.html.erb +2 -0
  57. data/app/views/admin/vendor_overview/index.html.erb +1 -0
  58. data/app/views/shared/_supplier_invoices.html.erb +47 -0
  59. data/app/views/suppliers/_supplier.html.erb +7 -0
  60. data/app/views/suppliers/_supplier_list.erb +13 -0
  61. data/app/views/suppliers/index.html.erb +13 -0
  62. data/app/views/suppliers/show.html.erb +11 -0
  63. data/app/views/suppliers/supplier_list.erb +11 -0
  64. data/config/routes.rb +37 -0
  65. data/db/migrate/20120131160039_create_suppliers.rb +8 -0
  66. data/db/migrate/20120131160855_add_fields_to_suppliers.rb +16 -0
  67. data/db/migrate/20120131161247_create_supplier_invoices.rb +12 -0
  68. data/db/migrate/20120131161610_create_invoice_items.rb +12 -0
  69. data/db/migrate/20120201160616_create_suppliers_taxons.rb +16 -0
  70. data/db/migrate/20120201170705_add_supplier_id_to_products.rb +5 -0
  71. data/db/seeds.rb +143 -0
  72. data/db/seeds/images/apple.gif +0 -0
  73. data/db/seeds/images/apple.jpg +0 -0
  74. data/db/seeds/images/banana.jpg +0 -0
  75. data/db/seeds/images/blueberry.jpg +0 -0
  76. data/db/seeds/images/cherries.jpg +0 -0
  77. data/db/seeds/images/chicken.jpg +0 -0
  78. data/db/seeds/images/cow.jpg +0 -0
  79. data/db/seeds/images/flower.jpg +0 -0
  80. data/db/seeds/images/goat.jpg +0 -0
  81. data/db/seeds/images/grapes.jpg +0 -0
  82. data/db/seeds/images/greenapple.jpg +0 -0
  83. data/db/seeds/images/greenbeans.jpg +0 -0
  84. data/db/seeds/images/indie_candy.jpg +0 -0
  85. data/db/seeds/images/orange.jpg +0 -0
  86. data/db/seeds/images/squash.jpg +0 -0
  87. data/db/seeds/images/stock_user.jpg +0 -0
  88. data/db/seeds/images/strawberry.jpg +0 -0
  89. data/db/seeds/images/watermelon.jpg +0 -0
  90. data/lib/generators/spree_suppliers/install/install_generator.rb +31 -0
  91. data/lib/spree_suppliers.rb +192 -0
  92. data/lib/spree_suppliers/engine.rb +24 -0
  93. data/lib/spree_suppliers_hooks.rb +19 -0
  94. data/script/rails +7 -0
  95. data/spec/spec_helper.rb +31 -0
  96. data/spree_suppliers.gemspec +24 -0
  97. data/test/fixtures/.gitkeep +0 -0
  98. data/test/fixtures/invoice_items.yml +13 -0
  99. data/test/fixtures/supplier_invoices.yml +13 -0
  100. data/test/fixtures/suppliers.yml +11 -0
  101. data/test/functional/.gitkeep +0 -0
  102. data/test/functional/invoice_items_controller_test.rb +7 -0
  103. data/test/functional/supplier_invoices_controller_test.rb +7 -0
  104. data/test/functional/suppliers_controller_test.rb +7 -0
  105. data/test/integration/.gitkeep +0 -0
  106. data/test/performance/browsing_test.rb +12 -0
  107. data/test/test_helper.rb +13 -0
  108. data/test/unit/helpers/invoice_items_helper_test.rb +4 -0
  109. data/test/unit/helpers/supplier_invoices_helper_test.rb +4 -0
  110. data/test/unit/helpers/suppliers_helper_test.rb +4 -0
  111. data/test/unit/invoice_item_test.rb +7 -0
  112. data/test/unit/supplier_invoice_test.rb +7 -0
  113. data/test/unit/supplier_test.rb +7 -0
  114. metadata +156 -37
data/Gemfile ADDED
@@ -0,0 +1,22 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'sqlite3'
4
+
5
+ group :test do
6
+ gem 'rspec-rails', '= 2.6.1'
7
+ end
8
+
9
+ group :cucumber do
10
+ gem 'cucumber-rails', '1.0.0'
11
+ gem 'database_cleaner', '= 0.6.7'
12
+ gem 'nokogiri'
13
+ gem 'capybara', '1.0.1'
14
+ end
15
+
16
+ if RUBY_VERSION < "1.9"
17
+ gem "ruby-debug"
18
+ else
19
+ gem "ruby-debug19"
20
+ end
21
+
22
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2012 [name of plugin creator]
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ * Neither the name Spree nor the names of its contributors may be used to
13
+ endorse or promote products derived from this software without specific
14
+ prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,80 @@
1
+ # Spree Suppliers Extension
2
+
3
+ This is an extension to run on top of spree 0.60.3 rails ecommerce engine.
4
+
5
+ This extension provides functionality to use multiple suppliers/vendors, each selling their own products, but using a unified listing view so the customer is not affected by this and only makes one transaction. On the backend, smaller sub-orders called supplier invoices are created by grouping the products in an order by each product's supplier_id. A subtotal is generated for each supplier invoice, so the spree administrator can send out invoices to each supplier.
6
+
7
+ ______________________________
8
+
9
+ ## Installation:
10
+
11
+ ### you must first have a running rails app:
12
+
13
+ - rails new spree_suppliers_test
14
+ - cd spree_suppliers_test
15
+
16
+ ### Now set up your Gemfile and install:
17
+
18
+ #### Add to Gemfile:
19
+
20
+ - gem 'rails', '3.1.3'
21
+ - gem 'sqlite3'
22
+ - gem 'spree', '0.70.3'
23
+ - gem 'spree_suppliers'
24
+
25
+ #### then run:
26
+
27
+ - bundle install
28
+ - rake spree:install
29
+ - rake spree_suppliers:install
30
+ - rake db:migrate
31
+ - rake db:seed
32
+ - rake db:admin:create
33
+
34
+ ### That's it for installation!
35
+
36
+ - rails s
37
+ - visit localhost:3000
38
+
39
+ ______________________________
40
+
41
+ ### Alternatively,
42
+ To get the latest updates, you can install the spree_suppliers extension from github instead of rubygems:
43
+
44
+
45
+ #### Add to Gemfile:
46
+
47
+ - gem 'spree_suppliers', :git => 'git://github.com/johndavid400/spree_suppliers.git'
48
+
49
+ #### run the following:
50
+
51
+ - bundle install
52
+ - rake spree_suppliers:install
53
+ - rake db:migrate
54
+
55
+ ______________________________
56
+
57
+ ## Checkout Process
58
+
59
+ Before being able to check out with the new changes, go to /admin and do the following things:
60
+
61
+ 1. create a vendor (with valid address)
62
+ 3. create a payment method (use "check" to test with)
63
+ 6. add product for vendor to use - then edit to assign new product to the vendor
64
+
65
+ Go through checkout process normally, then check orders page on the admin panel to view the details of an order and all supplier invoices that are created.
66
+
67
+ ______________________________
68
+
69
+ ## Supplier Invoice Mailer
70
+
71
+ There is a mailer in place that will send each individual supplier an email anytime a purchase is made from them. It will not show them the entire order, only the products purchased from them. The mailer is disabled (commented out) as there is no email smtp information yet. Once you fill this in, you can re-enable the mailer to send out emails.
72
+
73
+ #### To change smtp settings for supplier invoice:
74
+
75
+ - config/initializers/supplier_invoice_mailer.rb
76
+
77
+ #### to enable supplier invoice mailer, uncomment line:84 and line:95:
78
+
79
+ - lib/spree_suppliers.rb
80
+
@@ -0,0 +1,31 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/packagetask'
4
+ require 'rubygems/package_task'
5
+ require 'rspec/core/rake_task'
6
+ require 'cucumber/rake/task'
7
+ require 'spree_core/testing_support/common_rake'
8
+
9
+ RSpec::Core::RakeTask.new
10
+ Cucumber::Rake::Task.new
11
+
12
+ task :default => [:spec, :cucumber ]
13
+
14
+ spec = eval(File.read('spree_suppliers.gemspec'))
15
+
16
+ Gem::PackageTask.new(spec) do |p|
17
+ p.gem_spec = spec
18
+ end
19
+
20
+ desc "Release to gemcutter"
21
+ task :release => :package do
22
+ require 'rake/gemcutter'
23
+ Rake::Gemcutter::Tasks.new(spec).define
24
+ Rake::Task['gem:push'].invoke
25
+ end
26
+
27
+ desc "Generates a dummy app for testing"
28
+ task :test_app do
29
+ ENV['LIB_NAME'] = 'spree_suppliers'
30
+ Rake::Task['common:test_app'].invoke
31
+ end
@@ -0,0 +1,9 @@
1
+ # This file is used to designate compatibilty with different versions of Spree
2
+ # Please see http://spreecommerce.com/documentation/extensions.html#versionfile for details
3
+
4
+ # Examples
5
+ #
6
+ "0.70.3" => { :branch => "0.70"}
7
+ # "0.60.x" => { :branch => "0-60-stable" }
8
+ # "0.40.x" => { :tag => "v1.0.0", :version => "1.0.0" }
9
+
@@ -0,0 +1 @@
1
+ //= require admin/spree_core
@@ -0,0 +1,3 @@
1
+ # Place all the behaviors and hooks related to the matching controller here.
2
+ # All this logic will automatically be available in application.js.
3
+ # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
@@ -0,0 +1 @@
1
+ //= require store/spree_core
@@ -0,0 +1,3 @@
1
+ # Place all the behaviors and hooks related to the matching controller here.
2
+ # All this logic will automatically be available in application.js.
3
+ # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
@@ -0,0 +1,3 @@
1
+ # Place all the behaviors and hooks related to the matching controller here.
2
+ # All this logic will automatically be available in application.js.
3
+ # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require admin/spree_core
3
+ */
@@ -0,0 +1,3 @@
1
+ // Place all the styles related to the invoice_items controller here.
2
+ // They will automatically be included in application.css.
3
+ // You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require store/spree_core
3
+ */
@@ -0,0 +1,3 @@
1
+ // Place all the styles related to the supplier_invoices controller here.
2
+ // They will automatically be included in application.css.
3
+ // You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,4 @@
1
+ // Place all the styles related to the suppliers controller here.
2
+ // They will automatically be included in application.css.
3
+ // You can use Sass (SCSS) here: http://sass-lang.com/
4
+
@@ -0,0 +1,61 @@
1
+ class Admin::SupplierTaxonsController < Admin::BaseController
2
+ include Railslove::Plugins::FindByParam::SingletonMethods
3
+ helper "admin/taxons"
4
+
5
+ respond_to :html, :json, :js
6
+
7
+ def selected
8
+ @supplier = load_supplier
9
+ @taxons = @supplier.taxons
10
+ @options = Taxon.all
11
+ respond_with(:admin, @taxons)
12
+ end
13
+
14
+ def available
15
+ @supplier = load_supplier
16
+ @taxons = params[:q].blank? ? [] : Taxon.where('lower(name) LIKE ?', "%#{params[:q].mb_chars.downcase}%")
17
+ @taxons.delete_if { |taxon| @supplier.taxons.include?(taxon) }
18
+ respond_with(:admin, @taxons)
19
+ end
20
+
21
+ def remove
22
+ @supplier = load_supplier
23
+ @taxon = Taxon.find(params[:id])
24
+ @supplier.taxons.delete(@taxon)
25
+ @supplier.save
26
+ @taxons = @supplier.taxons
27
+ respond_with(@taxon) { |format| format.js { render_js_for_destroy } }
28
+ end
29
+
30
+ def select
31
+ @supplier = load_supplier
32
+ @taxon = Taxon.find(params[:id])
33
+ @supplier.taxons << @taxon
34
+ @supplier.save
35
+ @taxons = @supplier.taxons
36
+ respond_with(:admin, @taxons)
37
+ end
38
+
39
+ def batch_select
40
+ @supplier = load_supplier
41
+ @taxons = params[:taxon_ids].map{|id| Taxon.find(id)}.compact
42
+ @supplier.taxons = @taxons
43
+ @supplier.save
44
+ redirect_to selected_admin_supplier_taxons_url(@supplier)
45
+ end
46
+
47
+ def update_taxons
48
+ @supplier = Supplier.find params[:supplier_id]
49
+ @supplier.taxons = []
50
+ @supplier.taxons.push(Taxon.all.select{|t| params[t.name.to_s] })
51
+ @supplier.save
52
+ redirect_to :back, :notice => "Taxons successfully added"
53
+ end
54
+
55
+ private
56
+
57
+ def load_supplier
58
+ Supplier.find params[:supplier_id]
59
+ end
60
+
61
+ end
@@ -0,0 +1,127 @@
1
+ class Admin::SuppliersController < Admin::BaseController
2
+ resource_controller
3
+ respond_to :html, :js
4
+
5
+ def index
6
+ if current_user.has_role?("admin")
7
+ @suppliers = Supplier.all
8
+ else
9
+ @supplier = current_user.supplier
10
+ end
11
+ end
12
+
13
+ def new
14
+ @supplier = Supplier.new()
15
+ @supplier.images.build
16
+ @status = true
17
+ end
18
+
19
+ def create
20
+ @supplier = Supplier.new(params[:supplier])
21
+ if @supplier.save
22
+ redirect_to admin_suppliers_path, :notice => "New supplier created"
23
+ else
24
+ render "new"
25
+ end
26
+ end
27
+
28
+ def show
29
+ @supplier = Supplier.find(params[:id])
30
+ end
31
+
32
+ def edit
33
+ @supplier = Supplier.find(params[:id])
34
+ @supplier.images.build
35
+ end
36
+
37
+ def destroy
38
+ @supplier = Supplier.find(params[:id])
39
+ @supplier.destroy
40
+ flash[:notice] = "Supplier Successfully deleted."
41
+ respond_with(@product) do |format|
42
+ format.html { redirect_to collection_url }
43
+ format.js do
44
+ render :update do |page|
45
+ page.redirect_to collection_url
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ def update
52
+ @supplier = Supplier.find(params[:id])
53
+ @status = false
54
+ if @supplier.update_attributes(params[:supplier])
55
+ redirect_to edit_admin_supplier_path, :notice => "Supplier updated"
56
+ else
57
+ render "edit"
58
+ end
59
+ end
60
+
61
+ def feature
62
+ @supplier = Supplier.find(params[:supplier_id])
63
+ if @supplier.featured == true
64
+ @supplier.featured = false
65
+ else
66
+ @supplier.featured = true
67
+ end
68
+ @supplier.save
69
+ flash[:notice] = "change #{@supplier.title}'s feature status to #{@supplier.featured}"
70
+ redirect_to admin_suppliers_path
71
+ end
72
+
73
+ def line_items
74
+ @order = Order.find_by_number(params[:order_id])
75
+ end
76
+
77
+ def selected
78
+ @supplier = @product.supplier
79
+ end
80
+
81
+ def available
82
+ if params[:q].blank?
83
+ @available_suppliers = []
84
+ else
85
+ @available_suppliers = Supplier.find(:all, :conditions => ['lower(name) LIKE ?', "%#{params[:q].downcase}%"])
86
+ end
87
+ @available_suppliers.delete_if { |supplier| @product.supplier == supplier }
88
+ respond_to do |format|
89
+ format.html
90
+ format.js {render :layout => false}
91
+ end
92
+
93
+ end
94
+
95
+ def remove
96
+ @product.supplier = nil
97
+ @product.save
98
+ @supplier = @product.supplier
99
+ render :layout => false
100
+ end
101
+
102
+ def select
103
+ @supplier = Supplier.find_by_param!(params[:id])
104
+ @product.supplier = @supplier
105
+ @product.save
106
+ @supplier = @product.supplier
107
+ render :layout => false
108
+ end
109
+
110
+
111
+ update.response do |wants|
112
+ wants.html { redirect_to collection_url }
113
+ end
114
+
115
+ update.after do
116
+ Rails.cache.delete('suppliers')
117
+ end
118
+
119
+ create.response do |wants|
120
+ wants.html { redirect_to collection_url }
121
+ end
122
+
123
+ create.after do
124
+ Rails.cache.delete('suppliers')
125
+ end
126
+
127
+ end
@@ -0,0 +1,18 @@
1
+ class Admin::VendorOverviewController < Spree::BaseController
2
+ ssl_required
3
+
4
+ helper :search
5
+ helper 'admin/navigation'
6
+ layout 'admin'
7
+
8
+ before_filter :vendor
9
+
10
+ def vendor
11
+ if !current_user.has_role?("vendor")
12
+ unauthorized
13
+ end
14
+ end
15
+ def index
16
+
17
+ end
18
+ end
@@ -0,0 +1,2 @@
1
+ class InvoiceItemsController < ApplicationController
2
+ end
@@ -0,0 +1,2 @@
1
+ class SupplierInvoicesController < ApplicationController
2
+ end
@@ -0,0 +1,15 @@
1
+ class SuppliersController < Spree::BaseController
2
+ helper :products
3
+ respond_to :html
4
+
5
+ def index
6
+ @search = Supplier.search(params[:search])
7
+ @suppliers = @search.all
8
+ respond_with(@suppliers)
9
+ end
10
+
11
+ def show
12
+ @supplier = Supplier.find(params[:id])
13
+ @products = Product.find(:all, :conditions => { :supplier_id => @supplier.id , :deleted_at => nil })
14
+ end
15
+ end