solidus_marketplace 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +11 -0
  5. data/Gemfile +8 -0
  6. data/LICENSE +26 -0
  7. data/README.md +123 -0
  8. data/Rakefile +15 -0
  9. data/Versionfile +6 -0
  10. data/app/assets/javascripts/spree/backend/solidus_marketplace.js +5 -0
  11. data/app/assets/javascripts/spree/backend/solidus_marketplace_routes.js +1 -0
  12. data/app/assets/javascripts/spree/backend/suppliers_autocomplete.js +55 -0
  13. data/app/assets/javascripts/spree/frontend/solidus_marketplace.js +1 -0
  14. data/app/assets/stylesheets/spree/backend/solidus_marketplace.scss +22 -0
  15. data/app/assets/stylesheets/spree/frontend/solidus_marketplace.css +3 -0
  16. data/app/controllers/ckeditor/attachment_files_controller_decorator.rb +20 -0
  17. data/app/controllers/ckeditor/pictures_controller_decorator.rb +17 -0
  18. data/app/controllers/spree/admin/marketplace_settings_controller.rb +19 -0
  19. data/app/controllers/spree/admin/products_controller_decorator.rb +79 -0
  20. data/app/controllers/spree/admin/reports_controller_decorator.rb +68 -0
  21. data/app/controllers/spree/admin/shipments_controller.rb +47 -0
  22. data/app/controllers/spree/admin/stock_items_controller_decorator.rb +10 -0
  23. data/app/controllers/spree/admin/stock_locations_controller_decorator.rb +23 -0
  24. data/app/controllers/spree/admin/suppliers_controller.rb +54 -0
  25. data/app/controllers/spree/admin/users_controller_decorator.rb +34 -0
  26. data/app/controllers/spree/api/suppliers_controller.rb +16 -0
  27. data/app/controllers/spree/api/v1/stock_locations_controller_decorator.rb +18 -0
  28. data/app/controllers/spree/base_controller_decorator.rb +13 -0
  29. data/app/helpers/spree/api/api_helpers_decorator.rb +22 -0
  30. data/app/mailers/spree/marketplace_order_mailer.rb +13 -0
  31. data/app/mailers/spree/supplier_mailer.rb +12 -0
  32. data/app/models/ckeditor/asset_decorator.rb +5 -0
  33. data/app/models/spree.rb +5 -0
  34. data/app/models/spree/marketplace_configuration.rb +14 -0
  35. data/app/models/spree/order_decorator.rb +44 -0
  36. data/app/models/spree/payment_decorator.rb +7 -0
  37. data/app/models/spree/product_decorator.rb +52 -0
  38. data/app/models/spree/shipment_decorator.rb +40 -0
  39. data/app/models/spree/stock/splitter/marketplace.rb +47 -0
  40. data/app/models/spree/stock_location_decorator.rb +23 -0
  41. data/app/models/spree/supplier.rb +120 -0
  42. data/app/models/spree/supplier_ability.rb +35 -0
  43. data/app/models/spree/supplier_variant.rb +6 -0
  44. data/app/models/spree/user_decorator.rb +23 -0
  45. data/app/models/spree/variant_decorator.rb +24 -0
  46. data/app/overrides/spree/admin/menus.rb +15 -0
  47. data/app/overrides/spree/admin/products/_form/converted_admin_product_form_right.html.erb.deface +5 -0
  48. data/app/overrides/spree/admin/products/edit/override_rows.html.erb.deface +22 -0
  49. data/app/overrides/spree/admin/stock_locations/_form/add_supplier.html.erb.deface +12 -0
  50. data/app/views/spree/admin/marketplace_settings/edit.html.erb +21 -0
  51. data/app/views/spree/admin/orders/index.html.erb +187 -0
  52. data/app/views/spree/admin/products/_form.html.erb +198 -0
  53. data/app/views/spree/admin/reports/earnings.html.erb +34 -0
  54. data/app/views/spree/admin/shared/_marketplace_settings.html.erb +1 -0
  55. data/app/views/spree/admin/shared/_marketplace_tabs.html.erb +4 -0
  56. data/app/views/spree/admin/shipments/edit.html.erb +24 -0
  57. data/app/views/spree/admin/shipments/index.html.erb +93 -0
  58. data/app/views/spree/admin/suppliers/_form.html.erb +75 -0
  59. data/app/views/spree/admin/suppliers/edit.html.erb +22 -0
  60. data/app/views/spree/admin/suppliers/index.html.erb +68 -0
  61. data/app/views/spree/admin/suppliers/new.html.erb +17 -0
  62. data/app/views/spree/api/shared/_pagination.json.jbuilder +5 -0
  63. data/app/views/spree/api/suppliers/_supplier.json.jbuilder +1 -0
  64. data/app/views/spree/api/suppliers/index.json.jbuilder +4 -0
  65. data/app/views/spree/marketplace_order_mailer/supplier_order.html.erb +119 -0
  66. data/app/views/spree/shared/unauthorized.erb +1 -0
  67. data/app/views/spree/supplier_mailer/welcome.html.erb +53 -0
  68. data/config/locales/en.yml +107 -0
  69. data/config/locales/es.yml +133 -0
  70. data/config/routes.rb +24 -0
  71. data/db/default/spree/marketplace_roles.rb +14 -0
  72. data/db/migrate/20121006073854_create_suppliers.rb +20 -0
  73. data/db/migrate/20130216070944_product_belongs_to_supplier.rb +6 -0
  74. data/db/migrate/20130405005502_stock_locations_belongs_to_supplier.rb +6 -0
  75. data/db/migrate/20130405011127_user_belongs_to_supplier.rb +6 -0
  76. data/db/migrate/20130428063053_add_balanced_token_to_suppliers.rb +7 -0
  77. data/db/migrate/20130510181443_add_supplier_id_to_ckeditor_assets.rb +8 -0
  78. data/db/migrate/20130606220913_add_permalink_to_suppliers.rb +6 -0
  79. data/db/migrate/20140323170638_add_supplier_commission_to_shipments.rb +5 -0
  80. data/db/migrate/20140416184616_migrate_payment_and_commission.rb +7 -0
  81. data/db/migrate/20140529041325_create_spree_supplier_variants.rb +15 -0
  82. data/db/migrate/20171027180043_add_paypal_email_to_suppliers.rb +5 -0
  83. data/db/seeds.rb +8 -0
  84. data/lib/generators/solidus_marketplace/install/install_generator.rb +36 -0
  85. data/lib/solidus_marketplace.rb +6 -0
  86. data/lib/solidus_marketplace/engine.rb +53 -0
  87. data/lib/solidus_marketplace/factories.rb +107 -0
  88. data/lib/solidus_marketplace/version.rb +3 -0
  89. data/lib/spree/permitted_attributes_decorator.rb +18 -0
  90. data/lib/tasks/spree_sample.rake +72 -0
  91. data/log/awesome.log +1 -0
  92. data/script/rails +7 -0
  93. data/solidus_marketplace.gemspec +46 -0
  94. data/spec/features/admin/orders_spec.rb +11 -0
  95. data/spec/features/admin/products_spec.rb +25 -0
  96. data/spec/features/admin/return_authorizations_spec.rb +7 -0
  97. data/spec/features/admin/settings_spec.rb +33 -0
  98. data/spec/features/admin/shipments_spec.rb +80 -0
  99. data/spec/features/admin/stock_management_spec.rb +156 -0
  100. data/spec/features/admin/stock_spec.rb +98 -0
  101. data/spec/features/admin/suppliers_spec.rb +130 -0
  102. data/spec/models/spree/order_decorator_spec.rb +80 -0
  103. data/spec/models/spree/payment_decorator_spec.rb +7 -0
  104. data/spec/models/spree/product_decorator_spec.rb +56 -0
  105. data/spec/models/spree/shipment_decorator_spec.rb +48 -0
  106. data/spec/models/spree/stock/splitter/marketplace_spec.rb +62 -0
  107. data/spec/models/spree/stock_location_decorator_spec.rb +33 -0
  108. data/spec/models/spree/supplier_ability_spec.rb +182 -0
  109. data/spec/models/spree/supplier_spec.rb +123 -0
  110. data/spec/models/spree/supplier_variant_spec.rb +5 -0
  111. data/spec/models/spree/user_decorator_spec.rb +57 -0
  112. data/spec/models/spree/variant_decorator_spec.rb +7 -0
  113. data/spec/spec_helper.rb +91 -0
  114. data/spec/support/ability_helpers.rb +11 -0
  115. data/spec/support/integration_helpers.rb +15 -0
  116. metadata +473 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 518ae3e24ec32c0b5b821e644c68da757eb8cf30
4
+ data.tar.gz: 1ddcc47402d8dc0ded60e5056f1c3603fc1906e9
5
+ SHA512:
6
+ metadata.gz: fbae1888258fc884af783e660aaef37c39729764845a301da2c5390e8f8a3bef83569bd14007c4ffcc148518178d11dce32a18b11119b35335ed6fed27794b07
7
+ data.tar.gz: 44973e168ebbfc6851cfaa7539885208985d29f2f0ee3b5d152cbb9ca1df263b43bc9730c8d90f3ea22253287e78c57565ddaf0fc20f33aa27b5a586a0ff7f16
@@ -0,0 +1,18 @@
1
+ \#*
2
+ *~
3
+ .#*
4
+ .bundle
5
+ .DS_Store
6
+ .idea
7
+ .project
8
+ .ruby-gemset
9
+ .ruby-version
10
+ .sass-cache
11
+ coverage
12
+ Gemfile.lock
13
+ tmp
14
+ nbproject
15
+ pkg
16
+ *.swp
17
+ spec/dummy
18
+ spec/vcr_cassettes
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --format progress
@@ -0,0 +1,11 @@
1
+ before_script:
2
+ - "sh -e /etc/init.d/xvfb start"
3
+ - "bundle exec rake test_app"
4
+ script:
5
+ - "export DISPLAY=:99.0"
6
+ - "bundle exec rspec spec"
7
+ rvm:
8
+ - 2.0.0
9
+ - 2.1.2
10
+ - 2.1.5
11
+ language: ruby
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+
4
+ branch = ENV.fetch('SOLIDUS_BRANCH', 'master')
5
+ gem "solidus", github: "solidusio/solidus", branch: branch
6
+ gem "solidus_auth_devise", github: "solidusio/solidus_auth_devise", branch: branch
7
+
8
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2012-2013 Jeff Dutil
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,123 @@
1
+ # Solidus Marketplace
2
+
3
+ # NOTE: This gem is currently a work-in-progress.
4
+ Contributors are welcome to help us get this gem to a viable MVP.
5
+ We suggest installing [ZenHub](http://zenhub.com) in order to view/manage open issues.
6
+ This will give you a new tab in Github called "Boards", which provides a Kanban-style view of the project's issues.
7
+
8
+ # Overview
9
+
10
+ This is marketplace implementation for solidus.
11
+
12
+ Basic functionality:
13
+ * Links products to one or more suppliers
14
+ * Once an order is placed:
15
+ * A shipment is created for the product's supplier
16
+ * The shipment is then sent to the store owner for fulfillment and to the supplier for visibility (via Email by default).
17
+ * The store owner fulfills orders. The supplier can view their shipments (read-only for now).
18
+
19
+ Installation
20
+ ------------
21
+ Here's how to install solidus_marketplace into your existing spree site AFTER you've installed Spree:
22
+
23
+ Add the following to your Gemfile:
24
+
25
+ gem 'solidus_marketplace'
26
+
27
+ Make your bundle happy:
28
+
29
+ bundle install
30
+
31
+ Now run the generator:
32
+
33
+ rails g solidus_marketplace:install
34
+
35
+ (Optional) Run the generator for solidus_gateway to enable the use of Stripe or other payment providers
36
+ included with that extension:
37
+
38
+ rails g solidus_gateway:install
39
+
40
+ Then migrate your database if you did not run during installation generator:
41
+
42
+ bundle exec rake db:migrate
43
+
44
+ And reboot your server:
45
+
46
+ rails s
47
+
48
+ You should be up and running now!
49
+
50
+ Sample Data
51
+ -----------
52
+
53
+ If you'd like to generate sample data, use the included rake tasks:
54
+
55
+ ```shell
56
+ rake db:seed # Loads seed data into the store
57
+ rake spree_sample:load # Loads sample data into the store
58
+ rake spree_sample:suppliers # Create sample suppliers and randomly link to products
59
+ rake spree_sample:marketplace_orders # Create sample marketplace orders
60
+ ```
61
+
62
+ This will include a new role (supplier_admin) and 2 new users in addition to the default 'admin@example.com' user provided by solidus.
63
+
64
+ Those users have the following email/password/roles
65
+
66
+ * marketmaker@example.com / test123 / admin
67
+ * supplier_admin@example.com / test123 / supplier_admin
68
+
69
+ Demo
70
+ ----
71
+
72
+ You can easily use the spec/dummy app as a demo of solidus_marketplace. Just `cd` to where you develop and run:
73
+
74
+ ```shell
75
+ git clone git://github.com/boomerdigital/solidus_marketplace.git
76
+ cd solidus_marketplace
77
+ bundle install
78
+ bundle exec rake test_app
79
+ cd spec/dummy
80
+ rake db:migrate db:seed spree_sample:load spree_sample:suppliers spree_sample:marketplace_orders
81
+ rails s
82
+ ```
83
+
84
+ Testing
85
+ -------
86
+
87
+ Be sure to bundle your dependencies and then create a dummy test app for the specs to run against.
88
+
89
+ ```shell
90
+ brew install geckodriver
91
+
92
+ bundle
93
+ bundle exec rake test_app
94
+ bundle exec rspec spec
95
+ ```
96
+
97
+ Todo
98
+ ----
99
+
100
+ * See open issues here: [open issues](https://github.com/boomerdigital/solidus_marketplace/issues)
101
+
102
+ Contributing
103
+ ------------
104
+
105
+ In the spirit of [free software](http://www.fsf.org/licensing/essays/free-sw.html), **everyone** is encouraged to help improve this project.
106
+
107
+ Here are some ways *you* can contribute:
108
+
109
+ * by using prerelease versions
110
+ * by reporting [bugs](https://github.com/boomerdigital/solidus_marketplace/issues)
111
+ * by suggesting new features
112
+ * by [translating to a new language](https://github.com/boomerdigital/solidus_marketplace/tree/master/config/locales)
113
+ * by writing or editing documentation
114
+ * by writing specifications
115
+ * by writing code (*no patch is too small*: fix typos, add comments, clean up inconsistent whitespace)
116
+ * by refactoring code
117
+ * by resolving [issues](https://github.com/boomerdigital/solidus_marketplace/issues)
118
+ * by reviewing patches
119
+
120
+ Donating
121
+ --------
122
+
123
+ Copyright (c) 2016-2017 Boomer Digital, released under the [New BSD License](https://github.com/boomerdigital/solidus_marketplace/tree/master/LICENSE).
@@ -0,0 +1,15 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ require 'spree/testing_support/common_rake'
6
+
7
+ RSpec::Core::RakeTask.new
8
+
9
+ task :default => [:spec]
10
+
11
+ desc 'Generates a dummy app for testing'
12
+ task :test_app do
13
+ ENV['LIB_NAME'] = 'solidus_marketplace'
14
+ Rake::Task['common:test_app'].invoke 'Spree::User'
15
+ end
@@ -0,0 +1,6 @@
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
+ # '1.3.x' => { :ref => 'e5624f7' } # Not going to be maintained but most of the works there if your looking for a starting point to branch off of.
4
+
5
+ '2.4.x' => { :branch => 'master' }
6
+ '2.3.x' => { :branch => '2-3-stable' }
@@ -0,0 +1,5 @@
1
+ //= require spree/backend
2
+ // Shipments AJAX API
3
+
4
+ //= require spree/backend/solidus_marketplace_routes
5
+ //= require spree/backend/suppliers_autocomplete
@@ -0,0 +1 @@
1
+ Spree.routes.suppliers_search = Spree.pathFor('api/suppliers')
@@ -0,0 +1,55 @@
1
+ $.fn.supplierAutocomplete = function () {
2
+ 'use strict';
3
+
4
+ this.select2({
5
+ placeholder: Spree.translations.supplier_placeholder,
6
+ multiple: true,
7
+ initSelection: function (element, callback) {
8
+ var ids = element.val(),
9
+ count = ids.split(",").length;
10
+
11
+ Spree.ajax({
12
+ type: "GET",
13
+ url: Spree.routes.suppliers_search,
14
+ data: {
15
+ ids: ids,
16
+ per_page: count
17
+ },
18
+ success: function (data) {
19
+ callback(data['suppliers']);
20
+ }
21
+ });
22
+ },
23
+ ajax: {
24
+ url: Spree.routes.suppliers_search,
25
+ datatype: 'json',
26
+ data: function (term, page) {
27
+ return {
28
+ per_page: 50,
29
+ page: page,
30
+ q: {
31
+ name_cont: term
32
+ },
33
+ token: Spree.api_key
34
+ };
35
+ },
36
+ results: function (data, page) {
37
+ var more = page < data.pages;
38
+ return {
39
+ results: data['suppliers'],
40
+ more: more
41
+ };
42
+ }
43
+ },
44
+ formatResult: function (supplier, container, query, escapeMarkup) {
45
+ return escapeMarkup(supplier.name);
46
+ },
47
+ formatSelection: function (supplier, container, escapeMarkup) {
48
+ return escapeMarkup(supplier.name);
49
+ }
50
+ });
51
+ };
52
+
53
+ $(document).ready(function () {
54
+ $('#product_supplier_ids').supplierAutocomplete();
55
+ });
@@ -0,0 +1 @@
1
+ //= require spree/frontend
@@ -0,0 +1,22 @@
1
+ /*
2
+ *= require spree/backend
3
+ */
4
+
5
+ .center {
6
+ text-align: center;
7
+ }
8
+
9
+ .state.delivered:before,
10
+ .state.confirmed:before {
11
+ background-color: #ff9300;
12
+ }
13
+
14
+ .supplier-banks ol li {
15
+ margin-left: 20px;
16
+ margin-bottom: 5px;
17
+ text-align: left;
18
+ }
19
+
20
+ a .without-textdecor{
21
+ text-decoration: none;
22
+ }
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require spree/frontend
3
+ */
@@ -0,0 +1,20 @@
1
+ if defined?(Ckeditor::AttachmentFilesController)
2
+ Ckeditor::AttachmentFilesController.class_eval do
3
+
4
+ load_and_authorize_resource :class => 'Ckeditor::AttachmentFile'
5
+ after_filter :set_supplier, only: [:create]
6
+
7
+ def index
8
+ end
9
+
10
+ private
11
+
12
+ def set_supplier
13
+ if try_spree_current_user.supplier? and @attachment
14
+ @attachment.supplier = try_spree_current_user.supplier
15
+ @attachment.save
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ if defined?(Ckeditor::PicturesController)
2
+ Ckeditor::PicturesController.class_eval do
3
+ load_and_authorize_resource :class => 'Ckeditor::Picture'
4
+ after_filter :set_supplier, only: [:create]
5
+
6
+ def index
7
+ end
8
+
9
+ private
10
+ def set_supplier
11
+ if spree_current_user.supplier? and @picture
12
+ @picture.supplier = spree_current_user.supplier
13
+ @picture.save
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ class Spree::Admin::MarketplaceSettingsController < Spree::Admin::BaseController
2
+
3
+ def edit
4
+ @config = Spree::MarketplaceConfiguration.new
5
+ end
6
+
7
+ def update
8
+ config = Spree::MarketplaceConfiguration.new
9
+
10
+ params.each do |name, value|
11
+ next unless config.has_preference? name
12
+ config[name] = value
13
+ end
14
+
15
+ flash[:success] = Spree.t('admin.marketplace_settings.update.success')
16
+ redirect_to spree.edit_admin_marketplace_settings_path
17
+ end
18
+
19
+ end
@@ -0,0 +1,79 @@
1
+ Spree::Admin::ProductsController.class_eval do
2
+
3
+ before_action :get_suppliers, only: [:edit] #, :update]
4
+ before_action :supplier_collection, only: [:index]
5
+ after_action :update_product_suppliers, only: [:update]
6
+ create.after :add_product_to_supplier
7
+
8
+ private
9
+
10
+ def permitted_resource_params
11
+ params[object_name].present? ? params.require(object_name).permit! : ActionController::Parameters.new.permit!
12
+ params[object_name].except(:supplier_ids)
13
+ end
14
+
15
+ def update_product_suppliers
16
+ if adding_suppliers?
17
+ supplier_ids = new_supplier_ids - current_supplier_ids
18
+ @product.add_suppliers!(supplier_ids)
19
+ elsif removing_suppliers?
20
+ supplier_ids = current_supplier_ids - new_supplier_ids
21
+ @product.remove_suppliers!(supplier_ids)
22
+ elsif same_number_of_suppliers? && different_suppliers?
23
+ @product.remove_suppliers!(current_suppliers)
24
+ @product.add_suppliers!(new_suppliers)
25
+ elsif same_suppliers?
26
+ #noop
27
+ end
28
+ end
29
+
30
+ def adding_suppliers?
31
+ new_supplier_ids.count > current_supplier_ids.count
32
+ end
33
+
34
+ def removing_suppliers?
35
+ new_supplier_ids.count < current_supplier_ids.count
36
+ end
37
+
38
+ def same_suppliers?
39
+ new_supplier_ids == current_supplier_ids
40
+ end
41
+
42
+ def same_number_of_suppliers?
43
+ new_supplier_ids.count == current_supplier_ids.count
44
+ end
45
+
46
+ def different_suppliers?
47
+ new_supplier_ids.sort != current_supplier_ids.sort
48
+ end
49
+
50
+ def new_supplier_ids
51
+ return [] unless params["product"].present? && params["product"]["supplier_ids"].present?
52
+ params["product"]["supplier_ids"].split(",").map(&:to_i)
53
+ end
54
+
55
+ def current_supplier_ids
56
+ @product.supplier_ids
57
+ end
58
+
59
+ def get_suppliers
60
+ @suppliers = Spree::Supplier.order(:name)
61
+ end
62
+
63
+ # Scopes the collection to what the user should have access to, based on the user's role
64
+ def supplier_collection
65
+ return unless try_spree_current_user
66
+
67
+ if try_spree_current_user.supplier?
68
+ @collection = @collection.joins(:suppliers).where('spree_suppliers.id = ?', try_spree_current_user.supplier_id)
69
+ end
70
+ end
71
+
72
+ # Newly added products by a Supplier are associated with it.
73
+ def add_product_to_supplier
74
+ if try_spree_current_user && try_spree_current_user.supplier?
75
+ @product.add_supplier!(try_spree_current_user.supplier_id)
76
+ end
77
+ end
78
+
79
+ end