spree_suppliers 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. data/README.markdown +84 -0
  2. data/Rakefile +137 -0
  3. data/app/controllers/admin/pickup_locations_controller.rb +52 -0
  4. data/app/controllers/admin/pickups_controller.rb +84 -0
  5. data/app/controllers/admin/shipping_options_controller.rb +32 -0
  6. data/app/controllers/admin/supplier_taxons_controller.rb +65 -0
  7. data/app/controllers/admin/suppliers_controller.rb +203 -0
  8. data/app/controllers/admin/vendor_overview_controller.rb +18 -0
  9. data/app/controllers/dash/base_controller.rb +10 -0
  10. data/app/controllers/dash/overview_controller.rb +6 -0
  11. data/app/controllers/dash/pickup_locations_controller.rb +27 -0
  12. data/app/controllers/dash/pickups_controller.rb +40 -0
  13. data/app/controllers/dash/products_controller.rb +15 -0
  14. data/app/controllers/messages_controller.rb +17 -0
  15. data/app/controllers/suppliers_controller.rb +19 -0
  16. data/app/controllers/user_sessions_decorator.rb +39 -0
  17. data/app/helpers/admin/suppliers_helper.rb +21 -0
  18. data/app/helpers/cities_helper.rb +2 -0
  19. data/app/helpers/dragonfly_helper.rb +16 -0
  20. data/app/helpers/messages_helper.rb +2 -0
  21. data/app/helpers/suppliers_helper.rb +16 -0
  22. data/app/mailers/supplier_mailer.rb +11 -0
  23. data/app/models/ability_decorator.rb +19 -0
  24. data/app/models/delivery.rb +6 -0
  25. data/app/models/hour.rb +4 -0
  26. data/app/models/item.rb +5 -0
  27. data/app/models/message.rb +3 -0
  28. data/app/models/pickup.rb +10 -0
  29. data/app/models/pickup_date.rb +3 -0
  30. data/app/models/pickup_location.rb +7 -0
  31. data/app/models/supplier.rb +33 -0
  32. data/app/models/supplier_invoice.rb +5 -0
  33. data/app/views/admin/orders/index.html.erb +107 -0
  34. data/app/views/admin/orders/show.html.erb +35 -0
  35. data/app/views/admin/orders/user.html.erb +19 -0
  36. data/app/views/admin/pickup_locations/_pickup_location.html.erb +10 -0
  37. data/app/views/admin/pickup_locations/edit.html.erb +44 -0
  38. data/app/views/admin/pickup_locations/new.html.erb +48 -0
  39. data/app/views/admin/pickup_locations/show.html.erb +1 -0
  40. data/app/views/admin/pickups/_pickup.erb +0 -0
  41. data/app/views/admin/pickups/index.html.erb +44 -0
  42. data/app/views/admin/pickups/new.html.erb +33 -0
  43. data/app/views/admin/pickups/show.html.erb +42 -0
  44. data/app/views/admin/products/_suppliers_form.html.erb +5 -0
  45. data/app/views/admin/shared/_order_tabs_decide.html.erb +5 -0
  46. data/app/views/admin/shared/_vendor_order_tabs.html.erb +39 -0
  47. data/app/views/admin/shipping_options/edit.html.erb +38 -0
  48. data/app/views/admin/supplier_taxons/_form.html.erb +23 -0
  49. data/app/views/admin/supplier_taxons/_taxon_table.html.erb +23 -0
  50. data/app/views/admin/supplier_taxons/available.js.erb +33 -0
  51. data/app/views/admin/supplier_taxons/edit.html.erb +11 -0
  52. data/app/views/admin/supplier_taxons/remove.html.erb +1 -0
  53. data/app/views/admin/supplier_taxons/select.js.erb +2 -0
  54. data/app/views/admin/supplier_taxons/selected.html.erb +51 -0
  55. data/app/views/admin/suppliers/_edit_form.html.erb +75 -0
  56. data/app/views/admin/suppliers/_edit_hours_form.html.erb +18 -0
  57. data/app/views/admin/suppliers/_form.html.erb +72 -0
  58. data/app/views/admin/suppliers/_hours_form.html.erb +11 -0
  59. data/app/views/admin/suppliers/_image_form.html.erb +40 -0
  60. data/app/views/admin/suppliers/_supplier.html.erb +37 -0
  61. data/app/views/admin/suppliers/_supplier_tabs.html.erb +18 -0
  62. data/app/views/admin/suppliers/_suppliers_table.html.erb +25 -0
  63. data/app/views/admin/suppliers/_upload_image.html.erb +14 -0
  64. data/app/views/admin/suppliers/available.js.erb +34 -0
  65. data/app/views/admin/suppliers/edit.html.erb +20 -0
  66. data/app/views/admin/suppliers/index.html.erb +102 -0
  67. data/app/views/admin/suppliers/line_items.html.erb +20 -0
  68. data/app/views/admin/suppliers/new.html.erb +22 -0
  69. data/app/views/admin/suppliers/remove.html.erb +1 -0
  70. data/app/views/admin/suppliers/select.html.erb +1 -0
  71. data/app/views/admin/suppliers/selected.html.erb +40 -0
  72. data/app/views/admin/suppliers/show.html.erb +2 -0
  73. data/app/views/admin/users/_form.html.erb +40 -0
  74. data/app/views/admin/vendor_overview/index.html.erb +1 -0
  75. data/app/views/checkout/_delivery.html.erb +5 -0
  76. data/app/views/dash/overview/index.html.erb +58 -0
  77. data/app/views/dash/pickup_locations/_pickup_location.html.erb +3 -0
  78. data/app/views/dash/pickup_locations/new.html.erb +47 -0
  79. data/app/views/dash/pickups/_pickup.erb +3 -0
  80. data/app/views/dash/pickups/new.html.erb +24 -0
  81. data/app/views/dash/products/new.html.erb +38 -0
  82. data/app/views/layouts/admin.html.erb +81 -0
  83. data/app/views/messages/_message_form.html.erb +17 -0
  84. data/app/views/messages/create.html.erb +2 -0
  85. data/app/views/messages/destroy.html.erb +2 -0
  86. data/app/views/messages/new.html.erb +2 -0
  87. data/app/views/shared/_deliveries.html.erb +113 -0
  88. data/app/views/shared/_hours.html.erb +21 -0
  89. data/app/views/shared/_products_vendor.html.erb +49 -0
  90. data/app/views/shared/_supplier_invoices.html.erb +67 -0
  91. data/app/views/supplier_mailer/invoice_email.html.erb +72 -0
  92. data/app/views/suppliers/_supplier.html.erb +7 -0
  93. data/app/views/suppliers/_supplier_list.erb +20 -0
  94. data/app/views/suppliers/index.html.erb +17 -0
  95. data/app/views/suppliers/show.html.erb +106 -0
  96. data/app/views/suppliers/supplier_list.erb +14 -0
  97. data/config/initializers/dragonfly.rb +8 -0
  98. data/config/initializers/supplier_invoice_mailer.rb +10 -0
  99. data/config/locales/en-US.yml +13 -0
  100. data/config/routes.rb +48 -0
  101. data/db/migrate/20091209201716_supplier_setup.rb +36 -0
  102. data/db/migrate/20110922213437_create_messages.rb +18 -0
  103. data/db/migrate/20110928203155_create_hours.rb +21 -0
  104. data/db/migrate/20111006185052_create_pickups.rb +17 -0
  105. data/db/migrate/20111010191125_add_location_to_addresses.rb +9 -0
  106. data/db/migrate/20111010214313_create_pickup_dates.rb +14 -0
  107. data/db/migrate/20111011180211_add_supplier_id_to_user.rb +9 -0
  108. data/db/migrate/20111012211422_create_pickup_locations.rb +21 -0
  109. data/db/migrate/20111013155257_create_supplier_invoices.rb +16 -0
  110. data/db/migrate/20111013161225_create_items.rb +18 -0
  111. data/db/migrate/20111018133543_add_attributes_to_products.rb +17 -0
  112. data/db/migrate/20111028190454_add_attributes_to_assets.rb +11 -0
  113. data/db/migrate/20111029230805_create_suppliers_taxons.rb +16 -0
  114. data/db/migrate/20111101165933_create_deliveries.rb +17 -0
  115. data/db/migrate/20111108213108_create_shipping_methods_suppliers.rb +16 -0
  116. data/db/seeds.rb +14 -0
  117. data/lib/spree_suppliers.rb +411 -0
  118. data/lib/spree_suppliers_hooks.rb +40 -0
  119. data/lib/tasks/spree_suppliers.rake +27 -0
  120. data/public/javascripts/jquery-ui.js +312 -0
  121. data/public/javascripts/jquery-ui.multidatespicker.js +398 -0
  122. data/public/javascripts/jquery.ui.datepicker.js +1791 -0
  123. data/public/stylesheets/suppliers.css +676 -0
  124. data/spec/controllers/cities_controller_spec.rb +157 -0
  125. data/spec/controllers/shipping_options_controller_spec.rb +12 -0
  126. data/spec/helpers/cities_helper_spec.rb +15 -0
  127. data/spec/models/city_spec.rb +5 -0
  128. data/spec/models/comment_spec.rb +64 -0
  129. data/spec/models/item_spec.rb +5 -0
  130. data/spec/models/message_spec.rb +5 -0
  131. data/spec/models/pickup_date_spec.rb +5 -0
  132. data/spec/models/pickup_location_spec.rb +5 -0
  133. data/spec/models/pickup_spec.rb +5 -0
  134. data/spec/models/rating_spec.rb +24 -0
  135. data/spec/models/supplier_invoice_spec.rb +5 -0
  136. data/spec/models/supplier_spec.rb +11 -0
  137. data/spec/requests/cities_spec.rb +11 -0
  138. data/spec/routing/cities_routing_spec.rb +35 -0
  139. data/spec/spec.opts +6 -0
  140. data/spec/spec_helper.rb +37 -0
  141. data/spec/views/cities/edit.html.erb_spec.rb +22 -0
  142. data/spec/views/cities/index.html.erb_spec.rb +28 -0
  143. data/spec/views/cities/new.html.erb_spec.rb +22 -0
  144. data/spec/views/cities/show.html.erb_spec.rb +21 -0
  145. data/spec/views/shipping_options/edit.html.erb_spec.rb +5 -0
  146. data/spree_suppliers-0.60.3.gem +0 -0
  147. data/spree_suppliers.gemspec +24 -0
  148. metadata +243 -0
data/README.markdown ADDED
@@ -0,0 +1,84 @@
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.0.9'
21
+ - gem 'sqlite3'
22
+ - gem 'spree', '0.60.3'
23
+ - gem 'spree_suppliers', '0.60.3'
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
+ 2. create a shipping method (make sure to select the correct zone for your area)
63
+ 3. create a payment method (use "check" to test with)
64
+ 4. edit vendor - add shipping option
65
+ 5. add pickup and pickup location for vendor
66
+ 6. add product for vendor - then edit to assign new product to the vendor
67
+
68
+ 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.
69
+
70
+ ______________________________
71
+
72
+ ## Supplier Invoice Mailer
73
+
74
+ 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.
75
+
76
+ #### To change smtp settings for supplier invoice:
77
+
78
+ - config/initializers/supplier_invoice_mailer.rb
79
+
80
+ #### to enable supplier invoice mailer, uncomment line:238:
81
+
82
+ - lib/spree_suppliers.rb
83
+
84
+
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