spree_suppliers 0.1.0 → 0.60.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README +46 -0
- data/Rakefile +137 -0
- data/app/controllers/admin/pickup_locations_controller.rb +52 -0
- data/app/controllers/admin/pickups_controller.rb +84 -0
- data/app/controllers/admin/shipping_options_controller.rb +32 -0
- data/app/controllers/admin/supplier_taxons_controller.rb +65 -0
- data/app/controllers/admin/suppliers_controller.rb +203 -0
- data/app/controllers/admin/vendor_overview_controller.rb +18 -0
- data/app/controllers/dash/base_controller.rb +10 -0
- data/app/controllers/dash/overview_controller.rb +6 -0
- data/app/controllers/dash/pickup_locations_controller.rb +27 -0
- data/app/controllers/dash/pickups_controller.rb +40 -0
- data/app/controllers/dash/products_controller.rb +15 -0
- data/app/controllers/messages_controller.rb +17 -0
- data/app/controllers/suppliers_controller.rb +19 -0
- data/app/controllers/user_sessions_decorator.rb +39 -0
- data/app/helpers/admin/suppliers_helper.rb +21 -0
- data/app/helpers/cities_helper.rb +2 -0
- data/app/helpers/dragonfly_helper.rb +16 -0
- data/app/helpers/messages_helper.rb +2 -0
- data/app/helpers/suppliers_helper.rb +16 -0
- data/app/mailers/supplier_mailer.rb +11 -0
- data/app/models/ability_decorator.rb +19 -0
- data/app/models/delivery.rb +6 -0
- data/app/models/hour.rb +4 -0
- data/app/models/item.rb +5 -0
- data/app/models/message.rb +3 -0
- data/app/models/pickup.rb +10 -0
- data/app/models/pickup_date.rb +3 -0
- data/app/models/pickup_location.rb +7 -0
- data/app/models/supplier.rb +33 -0
- data/app/models/supplier_invoice.rb +5 -0
- data/app/views/admin/orders/index.html.erb +107 -0
- data/app/views/admin/orders/show.html.erb +35 -0
- data/app/views/admin/orders/user.html.erb +19 -0
- data/app/views/admin/pickup_locations/_pickup_location.html.erb +10 -0
- data/app/views/admin/pickup_locations/edit.html.erb +44 -0
- data/app/views/admin/pickup_locations/new.html.erb +48 -0
- data/app/views/admin/pickup_locations/show.html.erb +1 -0
- data/app/views/admin/pickups/_pickup.erb +0 -0
- data/app/views/admin/pickups/index.html.erb +44 -0
- data/app/views/admin/pickups/new.html.erb +33 -0
- data/app/views/admin/pickups/show.html.erb +42 -0
- data/app/views/admin/products/_suppliers_form.html.erb +5 -0
- data/app/views/admin/shared/_order_tabs_decide.html.erb +5 -0
- data/app/views/admin/shared/_vendor_order_tabs.html.erb +39 -0
- data/app/views/admin/shipping_options/edit.html.erb +38 -0
- data/app/views/admin/supplier_taxons/_form.html.erb +23 -0
- data/app/views/admin/supplier_taxons/_taxon_table.html.erb +23 -0
- data/app/views/admin/supplier_taxons/available.js.erb +33 -0
- data/app/views/admin/supplier_taxons/edit.html.erb +11 -0
- data/app/views/admin/supplier_taxons/remove.html.erb +1 -0
- data/app/views/admin/supplier_taxons/select.js.erb +2 -0
- data/app/views/admin/supplier_taxons/selected.html.erb +51 -0
- data/app/views/admin/suppliers/_edit_form.html.erb +75 -0
- data/app/views/admin/suppliers/_edit_hours_form.html.erb +18 -0
- data/app/views/admin/suppliers/_form.html.erb +72 -0
- data/app/views/admin/suppliers/_hours_form.html.erb +11 -0
- data/app/views/admin/suppliers/_image_form.html.erb +40 -0
- data/app/views/admin/suppliers/_supplier.html.erb +37 -0
- data/app/views/admin/suppliers/_supplier_tabs.html.erb +18 -0
- data/app/views/admin/suppliers/_suppliers_table.html.erb +25 -0
- data/app/views/admin/suppliers/_upload_image.html.erb +14 -0
- data/app/views/admin/suppliers/available.js.erb +34 -0
- data/app/views/admin/suppliers/edit.html.erb +20 -0
- data/app/views/admin/suppliers/index.html.erb +102 -0
- data/app/views/admin/suppliers/line_items.html.erb +20 -0
- data/app/views/admin/suppliers/new.html.erb +22 -0
- data/app/views/admin/suppliers/remove.html.erb +1 -0
- data/app/views/admin/suppliers/select.html.erb +1 -0
- data/app/views/admin/suppliers/selected.html.erb +40 -0
- data/app/views/admin/suppliers/show.html.erb +2 -0
- data/app/views/admin/users/_form.html.erb +40 -0
- data/app/views/admin/vendor_overview/index.html.erb +1 -0
- data/app/views/checkout/_delivery.html.erb +5 -0
- data/app/views/dash/overview/index.html.erb +58 -0
- data/app/views/dash/pickup_locations/_pickup_location.html.erb +3 -0
- data/app/views/dash/pickup_locations/new.html.erb +47 -0
- data/app/views/dash/pickups/_pickup.erb +3 -0
- data/app/views/dash/pickups/new.html.erb +24 -0
- data/app/views/dash/products/new.html.erb +38 -0
- data/app/views/layouts/admin.html.erb +81 -0
- data/app/views/messages/_message_form.html.erb +17 -0
- data/app/views/messages/create.html.erb +2 -0
- data/app/views/messages/destroy.html.erb +2 -0
- data/app/views/messages/new.html.erb +2 -0
- data/app/views/shared/_deliveries.html.erb +113 -0
- data/app/views/shared/_hours.html.erb +21 -0
- data/app/views/shared/_products_vendor.html.erb +49 -0
- data/app/views/shared/_supplier_invoices.html.erb +67 -0
- data/app/views/supplier_mailer/invoice_email.html.erb +72 -0
- data/app/views/suppliers/_supplier.html.erb +7 -0
- data/app/views/suppliers/_supplier_list.erb +20 -0
- data/app/views/suppliers/index.html.erb +17 -0
- data/app/views/suppliers/show.html.erb +106 -0
- data/app/views/suppliers/supplier_list.erb +14 -0
- data/config/initializers/dragonfly.rb +8 -0
- data/config/initializers/supplier_invoice_mailer.rb +10 -0
- data/config/locales/en-US.yml +13 -0
- data/config/routes.rb +48 -0
- data/db/migrate/20091209201716_supplier_setup.rb +36 -0
- data/db/migrate/20110922213437_create_messages.rb +18 -0
- data/db/migrate/20110928203155_create_hours.rb +21 -0
- data/db/migrate/20111006185052_create_pickups.rb +17 -0
- data/db/migrate/20111010191125_add_location_to_addresses.rb +9 -0
- data/db/migrate/20111010214313_create_pickup_dates.rb +14 -0
- data/db/migrate/20111011180211_add_supplier_id_to_user.rb +9 -0
- data/db/migrate/20111012211422_create_pickup_locations.rb +21 -0
- data/db/migrate/20111013155257_create_supplier_invoices.rb +16 -0
- data/db/migrate/20111013161225_create_items.rb +18 -0
- data/db/migrate/20111018133543_add_attributes_to_products.rb +17 -0
- data/db/migrate/20111028190454_add_attributes_to_assets.rb +11 -0
- data/db/migrate/20111029230805_create_suppliers_taxons.rb +16 -0
- data/db/migrate/20111101165933_create_deliveries.rb +17 -0
- data/db/migrate/20111108213108_create_shipping_methods_suppliers.rb +16 -0
- data/db/seeds.rb +14 -0
- data/lib/spree_suppliers.rb +411 -0
- data/lib/spree_suppliers_hooks.rb +40 -0
- data/lib/tasks/spree_suppliers.rake +27 -0
- data/public/javascripts/jquery-ui.js +312 -0
- data/public/javascripts/jquery-ui.multidatespicker.js +398 -0
- data/public/javascripts/jquery.ui.datepicker.js +1791 -0
- data/public/stylesheets/suppliers.css +676 -0
- data/spec/controllers/cities_controller_spec.rb +157 -0
- data/spec/controllers/shipping_options_controller_spec.rb +12 -0
- data/spec/helpers/cities_helper_spec.rb +15 -0
- data/spec/models/city_spec.rb +5 -0
- data/spec/models/comment_spec.rb +64 -0
- data/spec/models/item_spec.rb +5 -0
- data/spec/models/message_spec.rb +5 -0
- data/spec/models/pickup_date_spec.rb +5 -0
- data/spec/models/pickup_location_spec.rb +5 -0
- data/spec/models/pickup_spec.rb +5 -0
- data/spec/models/rating_spec.rb +24 -0
- data/spec/models/supplier_invoice_spec.rb +5 -0
- data/spec/models/supplier_spec.rb +11 -0
- data/spec/requests/cities_spec.rb +11 -0
- data/spec/routing/cities_routing_spec.rb +35 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +37 -0
- data/spec/views/cities/edit.html.erb_spec.rb +22 -0
- data/spec/views/cities/index.html.erb_spec.rb +28 -0
- data/spec/views/cities/new.html.erb_spec.rb +22 -0
- data/spec/views/cities/show.html.erb_spec.rb +21 -0
- data/spec/views/shipping_options/edit.html.erb_spec.rb +5 -0
- data/spree_suppliers.gemspec +24 -0
- metadata +181 -14
data/README
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
This is an extension to run on top of spree 0.60.3 rails ecommerce engine.
|
2
|
+
|
3
|
+
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.
|
4
|
+
|
5
|
+
To install:
|
6
|
+
|
7
|
+
you must first have a running rails app:
|
8
|
+
rails new spree_suppliers_test
|
9
|
+
cd spree_suppliers_test
|
10
|
+
|
11
|
+
You must also have a running Spree store:
|
12
|
+
Add to Gemfile:
|
13
|
+
gem 'rails', '3.0.9'
|
14
|
+
gem 'spree', '0.60.3'
|
15
|
+
|
16
|
+
then run:
|
17
|
+
bundle install
|
18
|
+
rake spree:install
|
19
|
+
rake db:migrate
|
20
|
+
rake db:seed
|
21
|
+
rake db:admin:create
|
22
|
+
|
23
|
+
To install the spree_suppliers extension:
|
24
|
+
Add to Gemfile:
|
25
|
+
gem 'spree_suppliers', :git => 'git://github.com/johndavid400/spree_suppliers.git'
|
26
|
+
|
27
|
+
run the following:
|
28
|
+
bundle install
|
29
|
+
rake spree_suppliers:install
|
30
|
+
rake db:migrate
|
31
|
+
|
32
|
+
_---------------------------
|
33
|
+
|
34
|
+
Before being able to check out, go to /admin and do the following things:
|
35
|
+
1. create a vendor (with valid address)
|
36
|
+
2. create a shipping method
|
37
|
+
3. create a payment method (use check as test)
|
38
|
+
4. edit vendor - add shipping option
|
39
|
+
5. add pickup and pickup location for vendor
|
40
|
+
6. add product for vendor - then edit to assign new product to the vendor
|
41
|
+
|
42
|
+
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.
|
43
|
+
|
44
|
+
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.
|
45
|
+
|
46
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
# I think this is the one that should be moved to the extension Rakefile template
|
2
|
+
|
3
|
+
# In rails 1.2, plugins aren't available in the path until they're loaded.
|
4
|
+
# Check to see if the rspec plugin is installed first and require
|
5
|
+
# it if it is. If not, use the gem version.
|
6
|
+
|
7
|
+
# Determine where the RSpec plugin is by loading the boot
|
8
|
+
unless defined? SPREE_ROOT
|
9
|
+
ENV["RAILS_ENV"] = "test"
|
10
|
+
case
|
11
|
+
when ENV["SPREE_ENV_FILE"]
|
12
|
+
require File.dirname(ENV["SPREE_ENV_FILE"]) + "/boot"
|
13
|
+
when File.dirname(__FILE__) =~ %r{vendor/SPREE/vendor/extensions}
|
14
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot"
|
15
|
+
else
|
16
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rake'
|
21
|
+
require 'rake/rdoctask'
|
22
|
+
require 'rake/testtask'
|
23
|
+
|
24
|
+
rspec_base = File.expand_path(SPREE_ROOT + '/vendor/plugins/rspec/lib')
|
25
|
+
$LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
|
26
|
+
require 'spec/rake/spectask'
|
27
|
+
# require 'spec/translator'
|
28
|
+
|
29
|
+
# Cleanup the SPREE_ROOT constant so specs will load the environment
|
30
|
+
Object.send(:remove_const, :SPREE_ROOT)
|
31
|
+
|
32
|
+
extension_root = File.expand_path(File.dirname(__FILE__))
|
33
|
+
|
34
|
+
task :default => :spec
|
35
|
+
task :stats => "spec:statsetup"
|
36
|
+
|
37
|
+
desc "Run all specs in spec directory"
|
38
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
39
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
40
|
+
t.spec_files = FileList["#{extension_root}/spec/**/*_spec.rb"]
|
41
|
+
end
|
42
|
+
|
43
|
+
namespace :spec do
|
44
|
+
desc "Run all specs in spec directory with RCov"
|
45
|
+
Spec::Rake::SpecTask.new(:rcov) do |t|
|
46
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
47
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
48
|
+
t.rcov = true
|
49
|
+
t.rcov_opts = ['--exclude', 'spec', '--rails']
|
50
|
+
end
|
51
|
+
|
52
|
+
desc "Print Specdoc for all specs"
|
53
|
+
Spec::Rake::SpecTask.new(:doc) do |t|
|
54
|
+
t.spec_opts = ["--format", "specdoc", "--dry-run"]
|
55
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
56
|
+
end
|
57
|
+
|
58
|
+
[:models, :controllers, :views, :helpers].each do |sub|
|
59
|
+
desc "Run the specs under spec/#{sub}"
|
60
|
+
Spec::Rake::SpecTask.new(sub) do |t|
|
61
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
62
|
+
t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Hopefully no one has written their extensions in pre-0.9 style
|
67
|
+
# desc "Translate specs from pre-0.9 to 0.9 style"
|
68
|
+
# task :translate do
|
69
|
+
# translator = ::Spec::Translator.new
|
70
|
+
# dir = RAILS_ROOT + '/spec'
|
71
|
+
# translator.translate(dir, dir)
|
72
|
+
# end
|
73
|
+
|
74
|
+
# Setup specs for stats
|
75
|
+
task :statsetup do
|
76
|
+
require 'code_statistics'
|
77
|
+
::STATS_DIRECTORIES << %w(Model\ specs spec/models)
|
78
|
+
::STATS_DIRECTORIES << %w(View\ specs spec/views)
|
79
|
+
::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
|
80
|
+
::STATS_DIRECTORIES << %w(Helper\ specs spec/views)
|
81
|
+
::CodeStatistics::TEST_TYPES << "Model specs"
|
82
|
+
::CodeStatistics::TEST_TYPES << "View specs"
|
83
|
+
::CodeStatistics::TEST_TYPES << "Controller specs"
|
84
|
+
::CodeStatistics::TEST_TYPES << "Helper specs"
|
85
|
+
::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
|
86
|
+
end
|
87
|
+
|
88
|
+
namespace :db do
|
89
|
+
namespace :fixtures do
|
90
|
+
desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
|
91
|
+
task :load => :environment do
|
92
|
+
require 'active_record/fixtures'
|
93
|
+
ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
|
94
|
+
(ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
|
95
|
+
Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
desc 'Generate documentation for the supplier extension.'
|
103
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
104
|
+
rdoc.rdoc_dir = 'rdoc'
|
105
|
+
rdoc.title = 'SupplierExtension'
|
106
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
107
|
+
rdoc.rdoc_files.include('README')
|
108
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
109
|
+
end
|
110
|
+
|
111
|
+
# For extensions that are in transition
|
112
|
+
desc 'Test the supplier extension.'
|
113
|
+
Rake::TestTask.new(:test) do |t|
|
114
|
+
t.libs << 'lib'
|
115
|
+
t.pattern = 'test/**/*_test.rb'
|
116
|
+
t.verbose = true
|
117
|
+
end
|
118
|
+
|
119
|
+
namespace :test do
|
120
|
+
desc 'Functional test the supplier extension.'
|
121
|
+
Rake::TestTask.new(:functionals) do |t|
|
122
|
+
t.libs << 'lib'
|
123
|
+
t.pattern = 'test/functional/*_test.rb'
|
124
|
+
t.verbose = true
|
125
|
+
end
|
126
|
+
|
127
|
+
desc 'Unit test the supplier extension.'
|
128
|
+
Rake::TestTask.new(:units) do |t|
|
129
|
+
t.libs << 'lib'
|
130
|
+
t.pattern = 'test/unit/*_test.rb'
|
131
|
+
t.verbose = true
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
# Load any custom rakefiles for extension
|
137
|
+
Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
|
@@ -0,0 +1,52 @@
|
|
1
|
+
class Admin::PickupLocationsController < Admin::BaseController
|
2
|
+
|
3
|
+
def new
|
4
|
+
@pickup_location = PickupLocation.new()
|
5
|
+
end
|
6
|
+
|
7
|
+
def show
|
8
|
+
@location = PickupLocation.find(params[:id])
|
9
|
+
end
|
10
|
+
|
11
|
+
def create
|
12
|
+
@pickup_location = PickupLocation.create(params[:pickup_location])
|
13
|
+
# @pickup_location = current_user.supplier.pickup_locations.build(params[:pickup_location])
|
14
|
+
if @pickup_location.save
|
15
|
+
@pickup_location.hours.create(business_hours)
|
16
|
+
redirect_to admin_pickups_path, :notice => "New location added"
|
17
|
+
else
|
18
|
+
render "new", :notice => "Failed to create location"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def edit
|
24
|
+
@pickup_location = PickupLocation.find(params[:id])
|
25
|
+
@locations = [PickupLocation.first]
|
26
|
+
end
|
27
|
+
|
28
|
+
def update
|
29
|
+
@pickup_location = PickupLocation.find(params[:id])
|
30
|
+
if @pickup_location.update_attributes(params[:pickup_location])
|
31
|
+
if @pickup_location.hours.first.update_attributes(business_hours)
|
32
|
+
redirect_to edit_admin_pickup_location_path, :notice => "Pickup Location and Hours updated"
|
33
|
+
else
|
34
|
+
redirect_to edit_admin_pickup_location_path, :notice => "Pickup Location updated"
|
35
|
+
end
|
36
|
+
else
|
37
|
+
render "edit"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def business_hours
|
42
|
+
days = {}
|
43
|
+
["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"].each do |day|
|
44
|
+
days.merge!({day.downcase.to_sym => params["#{day}_begin"] + ":" + params["#{day}_begin_mins"] + " " + params["#{day}_begin_type"].upcase + " to " + params["#{day}_end"] + ":" + params["#{day}_end_mins"] + " " + params["#{day}_end_type"].upcase} )
|
45
|
+
if params["#{day}_closed"] == "Closed"
|
46
|
+
days.merge!({day.downcase.to_sym => "Closed"})
|
47
|
+
end
|
48
|
+
end
|
49
|
+
days
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
class Admin::PickupsController < Admin::BaseController
|
2
|
+
|
3
|
+
def index
|
4
|
+
if current_user.has_role?("vendor")
|
5
|
+
@suppliers = [current_user.supplier]
|
6
|
+
else
|
7
|
+
@suppliers = Supplier.all.select{|r| !r.pickups.empty?}
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def show
|
12
|
+
@supplier = Supplier.find(params[:id])
|
13
|
+
end
|
14
|
+
|
15
|
+
def new
|
16
|
+
if current_user.has_role?("vendor")
|
17
|
+
@pickups = current_user.supplier.pickups
|
18
|
+
@locations = (current_user.supplier.pickup_locations + PickupLocation.locate).uniq
|
19
|
+
else
|
20
|
+
@pickups = Pickup.all
|
21
|
+
@locations = PickupLocation.all
|
22
|
+
end
|
23
|
+
@pickup_location = PickupLocation.new()
|
24
|
+
@pickup = Pickup.new
|
25
|
+
@suppliers = Supplier.all
|
26
|
+
end
|
27
|
+
|
28
|
+
def create
|
29
|
+
pickup_location_id = params[:pickup_location_id]
|
30
|
+
supplier_id = params[:supplier_id]
|
31
|
+
@pickup = Pickup.create(:supplier_id => supplier_id, :pickup_location_id => pickup_location_id, :name => PickupLocation.find_by_id(pickup_location_id).location_name)
|
32
|
+
pickup_dates = create_dates(params[:dates])
|
33
|
+
if pickup_dates != false
|
34
|
+
@pickup.pickup_dates = pickup_dates
|
35
|
+
else
|
36
|
+
flash[:error] = "Errors in creating dates"
|
37
|
+
redirect_to admin_pickups_path and return
|
38
|
+
end
|
39
|
+
if @pickup.save
|
40
|
+
redirect_to admin_pickups_path, :message => "Successful creation"
|
41
|
+
else
|
42
|
+
redirect_to admin_pickups_path, :error => "Errors in creating dates"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def edit
|
47
|
+
@pickups = Pickup.all
|
48
|
+
@locations = [PickupLocation.first]
|
49
|
+
end
|
50
|
+
|
51
|
+
def update
|
52
|
+
@pickup = Pickup.find(params[:id])
|
53
|
+
if @pickup.update_attributes(params[:pickup])
|
54
|
+
redirect_to edit_admin_pickup_path, :notice => "Pickup updated"
|
55
|
+
else
|
56
|
+
render "edit"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def destroy
|
61
|
+
@pickup = Pickup.find(params[:id])
|
62
|
+
@pickup.destroy
|
63
|
+
flash[:notice] = "Pickup Successfully deleted."
|
64
|
+
redirect_to admin_pickups_url
|
65
|
+
end
|
66
|
+
|
67
|
+
def create_dates dates
|
68
|
+
dates = dates[0].split(',')
|
69
|
+
new_dates = []
|
70
|
+
dates.each do |d|
|
71
|
+
begin
|
72
|
+
new_dates.push(Date.strptime(d, "%m/%d/%Y"))
|
73
|
+
rescue
|
74
|
+
return false
|
75
|
+
end
|
76
|
+
end
|
77
|
+
pickups = []
|
78
|
+
new_dates.each do |day|
|
79
|
+
pickups.push(PickupDate.new({:day => day}))
|
80
|
+
end
|
81
|
+
pickups
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class Admin::ShippingOptionsController < Admin::BaseController
|
2
|
+
|
3
|
+
def edit
|
4
|
+
@shipping_methods = ShippingMethod.all
|
5
|
+
@supplier = Supplier.find(params[:id])
|
6
|
+
end
|
7
|
+
|
8
|
+
def create
|
9
|
+
@supplier = Supplier.find(params[:supplier_id])
|
10
|
+
if !params[:shipping_options].nil?
|
11
|
+
method = ShippingMethod.find_by_id(params[:shipping_options])
|
12
|
+
@update = true
|
13
|
+
@supplier.shipping_methods.each do |t|
|
14
|
+
if t.id == method.id
|
15
|
+
@update = false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
if @update == true
|
19
|
+
@supplier.shipping_methods << method
|
20
|
+
flash[:notice] = "New shipping method added successfully."
|
21
|
+
else
|
22
|
+
flash[:error] = "You already offer this shipping method, nothing added."
|
23
|
+
end
|
24
|
+
elsif !params[:remove].nil?
|
25
|
+
method = ShippingMethod.find_by_id(params[:remove][:id])
|
26
|
+
@supplier.shipping_methods.delete(method)
|
27
|
+
flash[:notice] = "Shipping method removed successfully"
|
28
|
+
end
|
29
|
+
redirect_to :back
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,65 @@
|
|
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
|
+
|
19
|
+
respond_with(:admin, @taxons)
|
20
|
+
end
|
21
|
+
|
22
|
+
def remove
|
23
|
+
@supplier = load_supplier
|
24
|
+
@taxon = Taxon.find(params[:id])
|
25
|
+
@supplier.taxons.delete(@taxon)
|
26
|
+
@supplier.save
|
27
|
+
@taxons = @supplier.taxons
|
28
|
+
|
29
|
+
respond_with(@taxon) { |format| format.js { render_js_for_destroy } }
|
30
|
+
end
|
31
|
+
|
32
|
+
def select
|
33
|
+
@supplier = load_supplier
|
34
|
+
@taxon = Taxon.find(params[:id])
|
35
|
+
@supplier.taxons << @taxon
|
36
|
+
@supplier.save
|
37
|
+
@taxons = @supplier.taxons
|
38
|
+
|
39
|
+
respond_with(:admin, @taxons)
|
40
|
+
end
|
41
|
+
|
42
|
+
def batch_select
|
43
|
+
@supplier = load_supplier
|
44
|
+
@taxons = params[:taxon_ids].map{|id| Taxon.find(id)}.compact
|
45
|
+
@supplier.taxons = @taxons
|
46
|
+
@supplier.save
|
47
|
+
redirect_to selected_admin_supplier_taxons_url(@supplier)
|
48
|
+
end
|
49
|
+
|
50
|
+
def update_taxons
|
51
|
+
@supplier = Supplier.find params[:supplier_id]
|
52
|
+
@supplier.taxons = []
|
53
|
+
Taxon.all.map {|m| @supplier.taxons.push(Taxon.find_by_id(params[m.name])) if params.member?(m.name) }
|
54
|
+
@supplier.taxons.push(Taxon.find_by_name("vendors"))
|
55
|
+
@supplier.save
|
56
|
+
redirect_to(:back)
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def load_supplier
|
62
|
+
Supplier.find params[:supplier_id]
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,203 @@
|
|
1
|
+
class Admin::SuppliersController < Admin::BaseController
|
2
|
+
resource_controller
|
3
|
+
helper :dragonfly
|
4
|
+
before_filter :load_edit, :only => [:edit]
|
5
|
+
before_filter :load_data, :only => [:selected, :available, :remove, :new, :edit, :select]
|
6
|
+
respond_to :html, :js
|
7
|
+
|
8
|
+
def index
|
9
|
+
if current_user.has_role?("admin")
|
10
|
+
@suppliers = Supplier.all
|
11
|
+
else
|
12
|
+
@supplier = current_user.supplier
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def new
|
17
|
+
@supplier = Supplier.new()
|
18
|
+
@status = true
|
19
|
+
end
|
20
|
+
|
21
|
+
def business_hours
|
22
|
+
days = {}
|
23
|
+
["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"].each do |day|
|
24
|
+
if params["#{day}_closed"] == "Closed"
|
25
|
+
days.merge!({day.downcase.to_sym => "Closed"})
|
26
|
+
elsif params["#{day}_closed"] == "Unavailable"
|
27
|
+
days.merge!({day.downcase.to_sym => "Information Unavailable"})
|
28
|
+
else
|
29
|
+
days.merge!({day.downcase.to_sym => params["#{day}_begin"] + ":" + params["#{day}_begin_mins"] + " " + params["#{day}_begin_type"].upcase + " to " + params["#{day}_end"] + ":" + params["#{day}_end_mins"] + " " + params["#{day}_end_type"].upcase} )
|
30
|
+
end
|
31
|
+
end
|
32
|
+
days
|
33
|
+
end
|
34
|
+
|
35
|
+
def create
|
36
|
+
@supplier = Supplier.new(params[:supplier])
|
37
|
+
if @supplier.save
|
38
|
+
@supplier.hours.create(business_hours)
|
39
|
+
redirect_to admin_suppliers_path, :notice => "New supplier created"
|
40
|
+
else
|
41
|
+
render "new"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def show
|
46
|
+
@supplier = Supplier.find(params[:id])
|
47
|
+
end
|
48
|
+
|
49
|
+
def destroy
|
50
|
+
@supplier = Supplier.find(params[:id])
|
51
|
+
@supplier.destroy
|
52
|
+
flash[:notice] = "Supplier Successfully deleted."
|
53
|
+
respond_with(@product) do |format|
|
54
|
+
format.html { redirect_to collection_url }
|
55
|
+
format.js do
|
56
|
+
render :update do |page|
|
57
|
+
page.redirect_to collection_url
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def update
|
64
|
+
@supplier = Supplier.find(params[:id])
|
65
|
+
@status = false
|
66
|
+
if @supplier.update_attributes(params[:supplier])
|
67
|
+
@supplier.hours.first.update_attributes(business_hours)
|
68
|
+
redirect_to edit_admin_supplier_path, :notice => "Supplier updated"
|
69
|
+
else
|
70
|
+
render "edit"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
def upload_image
|
77
|
+
@supplier = Supplier.find(params[:image][:viewable_id])
|
78
|
+
@supplier.images.create(params[:image])
|
79
|
+
if @supplier.save
|
80
|
+
redirect_to edit_admin_supplier_path(@supplier), :notice => "New supplier image uploaded successfully"
|
81
|
+
else
|
82
|
+
render "new"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def feature
|
87
|
+
@supplier = Supplier.find(params[:supplier_id])
|
88
|
+
if @supplier.featured == true
|
89
|
+
@supplier.featured = false
|
90
|
+
else
|
91
|
+
@supplier.featured = true
|
92
|
+
end
|
93
|
+
@supplier.save
|
94
|
+
flash[:notice] = "Change #{@supplier.title}'s feature status to #{@supplier.featured}"
|
95
|
+
redirect_to admin_suppliers_path
|
96
|
+
end
|
97
|
+
|
98
|
+
def make_logo
|
99
|
+
@image = Image.find(params[:id])
|
100
|
+
@supplier = Supplier.find(@image.viewable_id)
|
101
|
+
@supplier.images.each do |image|
|
102
|
+
image.logo = false
|
103
|
+
image.save
|
104
|
+
end
|
105
|
+
@image.logo = true
|
106
|
+
@image.save
|
107
|
+
redirect_to :back, :notice => "Change which image is considered a logo."
|
108
|
+
end
|
109
|
+
|
110
|
+
def feature_image
|
111
|
+
@image = Image.find(params[:id])
|
112
|
+
@supplier = Supplier.find(@image.viewable_id)
|
113
|
+
@supplier.images.each do |image|
|
114
|
+
image.featured = false
|
115
|
+
image.save
|
116
|
+
end
|
117
|
+
@image.featured = true
|
118
|
+
@image.save
|
119
|
+
redirect_to :back, :notice => "Change which image is featured."
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
def destroy_image
|
124
|
+
@image = Image.find(params[:id])
|
125
|
+
|
126
|
+
if @image.destroy
|
127
|
+
redirect_to :back, :notice => "Image destroyed."
|
128
|
+
else
|
129
|
+
render "new"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def line_items
|
134
|
+
@order = Order.find_by_number(params[:order_id])
|
135
|
+
end
|
136
|
+
|
137
|
+
def selected
|
138
|
+
@supplier = @product.supplier
|
139
|
+
end
|
140
|
+
|
141
|
+
def available
|
142
|
+
if params[:q].blank?
|
143
|
+
@available_suppliers = []
|
144
|
+
else
|
145
|
+
@available_suppliers = Supplier.find(:all, :conditions => ['lower(name) LIKE ?', "%#{params[:q].downcase}%"])
|
146
|
+
end
|
147
|
+
@available_suppliers.delete_if { |supplier| @product.supplier == supplier }
|
148
|
+
respond_to do |format|
|
149
|
+
format.html
|
150
|
+
format.js {render :layout => false}
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
def remove
|
156
|
+
@product.supplier = nil
|
157
|
+
@product.save
|
158
|
+
@supplier = @product.supplier
|
159
|
+
render :layout => false
|
160
|
+
end
|
161
|
+
|
162
|
+
def select
|
163
|
+
@supplier = Supplier.find_by_param!(params[:id])
|
164
|
+
@product.supplier = @supplier
|
165
|
+
@product.save
|
166
|
+
@supplier = @product.supplier
|
167
|
+
render :layout => false
|
168
|
+
end
|
169
|
+
|
170
|
+
|
171
|
+
update.response do |wants|
|
172
|
+
wants.html { redirect_to collection_url }
|
173
|
+
end
|
174
|
+
|
175
|
+
update.after do
|
176
|
+
Rails.cache.delete('suppliers')
|
177
|
+
end
|
178
|
+
|
179
|
+
create.response do |wants|
|
180
|
+
wants.html { redirect_to collection_url }
|
181
|
+
end
|
182
|
+
|
183
|
+
create.after do
|
184
|
+
Rails.cache.delete('suppliers')
|
185
|
+
end
|
186
|
+
|
187
|
+
private
|
188
|
+
|
189
|
+
def load_data
|
190
|
+
if !Country.first.nil?
|
191
|
+
default_country = Country.find_by_name("United States")
|
192
|
+
@states = default_country.states.sort
|
193
|
+
end
|
194
|
+
@product = Product.find_by_permalink(params[:product_id])
|
195
|
+
end
|
196
|
+
|
197
|
+
def load_edit
|
198
|
+
@closed = ["Unavailable", "Closed", "Open"]
|
199
|
+
@hours = (1..12).to_a
|
200
|
+
@minutes = ["00", "15", "30", "45"]
|
201
|
+
@periods = ["AM","PM"]
|
202
|
+
end
|
203
|
+
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,10 @@
|
|
1
|
+
class Dash::BaseController < Spree::BaseController
|
2
|
+
|
3
|
+
before_filter :authenticate_user!, :vendor_role
|
4
|
+
def vendor_role
|
5
|
+
if !current_user.roles.member?(Role.find_by_name("vendor"))
|
6
|
+
flash[:error] = "You are not a vendor"
|
7
|
+
redirect_to root_path
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class Dash::PickupLocationsController < Dash::BaseController
|
2
|
+
def new
|
3
|
+
@pickup_locations = (current_user.supplier.pickup_locations + PickupLocation.locate).uniq
|
4
|
+
@pickup_location = PickupLocation.new()
|
5
|
+
end
|
6
|
+
|
7
|
+
def business_hours
|
8
|
+
days = {}
|
9
|
+
["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"].each do |day|
|
10
|
+
days.merge!({day.downcase.to_sym => params["#{day}_begin"] + ":" + params["#{day}_begin_mins"] + " " + params["#{day}_begin_type"].upcase + " to " + params["#{day}_end"] + ":" + params["#{day}_end_mins"] + " " + params["#{day}_end_type"].upcase} )
|
11
|
+
if params["#{day}_closed"] == "Closed"
|
12
|
+
days.merge!({day.downcase.to_sym => "Closed"})
|
13
|
+
end
|
14
|
+
end
|
15
|
+
days
|
16
|
+
end
|
17
|
+
|
18
|
+
def create
|
19
|
+
@pickup_location = current_user.supplier.pickup_locations.build(params[:pickup_location])
|
20
|
+
if @pickup_location.save
|
21
|
+
@pickup_location.hours.create(business_hours)
|
22
|
+
redirect_to new_dash_pickup_location_path, :notice => "New location added"
|
23
|
+
else
|
24
|
+
render "new", :notice => "Failed to create location"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|