spree_multi_vendor 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +44 -0
  5. data/Appraisals +11 -0
  6. data/Gemfile +7 -0
  7. data/LICENSE +26 -0
  8. data/README.md +166 -0
  9. data/Rakefile +21 -0
  10. data/app/controllers/spree/admin/vendor_settings_controller.rb +34 -0
  11. data/app/controllers/spree/admin/vendors_controller.rb +60 -0
  12. data/app/controllers/spree/api/v2/storefront/vendors_controller.rb +28 -0
  13. data/app/controllers/spree_multi_vendor/spree/admin/base_controller_decorator.rb +10 -0
  14. data/app/controllers/spree_multi_vendor/spree/admin/option_types_controller_decorator.rb +7 -0
  15. data/app/controllers/spree_multi_vendor/spree/admin/products_controller_decorator.rb +24 -0
  16. data/app/controllers/spree_multi_vendor/spree/admin/properties_controller_decorator.rb +7 -0
  17. data/app/controllers/spree_multi_vendor/spree/admin/resource_controller_decorator.rb +8 -0
  18. data/app/controllers/spree_multi_vendor/spree/admin/shipping_methods_controller_decorator.rb +7 -0
  19. data/app/controllers/spree_multi_vendor/spree/admin/stock_locations_controller_decorator.rb +7 -0
  20. data/app/controllers/spree_multi_vendor/spree/admin/users_controller_decorator.rb +13 -0
  21. data/app/controllers/spree_multi_vendor/spree/admin/variants_controller_decorator.rb +7 -0
  22. data/app/controllers/spree_multi_vendor/spree/api/v1/variants_controller_decorator.rb +22 -0
  23. data/app/finders/spree_multi_vendor/products_finder_decorator.rb +31 -0
  24. data/app/helpers/spree/admin/vendor_helper.rb +15 -0
  25. data/app/mailers/spree/vendor_mailer.rb +15 -0
  26. data/app/models/concerns/spree/vendor_concern.rb +11 -0
  27. data/app/models/spree/order_commission.rb +11 -0
  28. data/app/models/spree/vendor.rb +77 -0
  29. data/app/models/spree/vendor_ability.rb +140 -0
  30. data/app/models/spree/vendor_image.rb +18 -0
  31. data/app/models/spree/vendor_order_totals.rb +28 -0
  32. data/app/models/spree/vendor_user.rb +16 -0
  33. data/app/models/spree_multi_vendor/configuration.rb +10 -0
  34. data/app/models/spree_multi_vendor/spree/ability_decorator.rb +9 -0
  35. data/app/models/spree_multi_vendor/spree/base_decorator.rb +13 -0
  36. data/app/models/spree_multi_vendor/spree/line_item_decorator.rb +48 -0
  37. data/app/models/spree_multi_vendor/spree/order_decorator.rb +105 -0
  38. data/app/models/spree_multi_vendor/spree/shipment_decorator.rb +8 -0
  39. data/app/models/spree_multi_vendor/spree/stock/package_decorator.rb +14 -0
  40. data/app/models/spree_multi_vendor/spree/user_decorator.rb +8 -0
  41. data/app/models/spree_multi_vendor/spree/variant_decorator.rb +41 -0
  42. data/app/overrides/spree/admin/orders/_form.rb +13 -0
  43. data/app/overrides/spree/admin/orders/_line_items.rb +6 -0
  44. data/app/overrides/spree/admin/orders/_line_items_edit_form.rb +6 -0
  45. data/app/overrides/spree/admin/orders/index.rb +6 -0
  46. data/app/overrides/spree/admin/products/form.rb +29 -0
  47. data/app/overrides/spree/admin/products/new.rb +16 -0
  48. data/app/overrides/spree/admin/shared/_main_menu.rb +23 -0
  49. data/app/overrides/spree/admin/shared/_order_summary.rb +35 -0
  50. data/app/overrides/spree/admin/users/_form.rb +13 -0
  51. data/app/serializers/spree/v2/storefront/vendor_image_serializer.rb +11 -0
  52. data/app/serializers/spree/v2/storefront/vendor_order_totals_serializer.rb +18 -0
  53. data/app/serializers/spree/v2/storefront/vendor_serializer.rb +14 -0
  54. data/app/serializers/spree_multi_vendor/cart_serializer_decorator.rb +19 -0
  55. data/app/serializers/spree_multi_vendor/serializer_decorator.rb +23 -0
  56. data/app/services/spree/orders/generate_commissions.rb +34 -0
  57. data/app/views/spree/admin/translations/vendor.html.erb +21 -0
  58. data/app/views/spree/admin/vendor_settings/edit.html.erb +47 -0
  59. data/app/views/spree/admin/vendors/_form.html.erb +36 -0
  60. data/app/views/spree/admin/vendors/edit.html.erb +11 -0
  61. data/app/views/spree/admin/vendors/index.html.erb +83 -0
  62. data/app/views/spree/admin/vendors/new.html.erb +11 -0
  63. data/app/views/spree/vendor_mailer/vendor_notification_email.html.erb +81 -0
  64. data/app/views/spree/vendor_mailer/vendor_notification_email.text.erb +36 -0
  65. data/bin/rails +7 -0
  66. data/config/initializers/spree_permitted_attributes.rb +10 -0
  67. data/config/locales/en.yml +34 -0
  68. data/config/locales/es.yml +33 -0
  69. data/config/locales/fr.yml +33 -0
  70. data/config/routes.rb +19 -0
  71. data/db/default/vendors.rb +13 -0
  72. data/db/migrate/20170406102250_create_spree_vendors.rb +9 -0
  73. data/db/migrate/20170406102944_add_vendor_id_to_spree_models.rb +10 -0
  74. data/db/migrate/20170410111150_add_state_to_vendors.rb +6 -0
  75. data/db/migrate/20170412124925_add_deleted_at_to_spree_vendors.rb +6 -0
  76. data/db/migrate/20170413094447_create_spree_vendor_users.rb +11 -0
  77. data/db/migrate/20190212161426_add_slug_to_spree_vendors.rb +6 -0
  78. data/db/migrate/20190214120226_add_about_us_to_spree_vendors.rb +5 -0
  79. data/db/migrate/20190214142526_add_contact_us_to_spree_vendors.rb +5 -0
  80. data/db/migrate/20190305120337_add_commission_to_spree_vendors.rb +5 -0
  81. data/db/migrate/20190308091546_add_priority_to_vendor.rb +8 -0
  82. data/db/migrate/20190312130754_create_spree_order_commissions.rb +14 -0
  83. data/db/migrate/20190322133128_add_notification_email_to_vendors.rb +5 -0
  84. data/db/migrate/20200416030721_add_translations_to_vendor.rb +19 -0
  85. data/gemfiles/spree_4_2.gemfile +9 -0
  86. data/gemfiles/spree_master.gemfile +9 -0
  87. data/lib/generators/spree_multi_vendor/install/install_generator.rb +21 -0
  88. data/lib/generators/spree_multi_vendor/mailers_preview/mailers_preview_generator.rb +22 -0
  89. data/lib/generators/spree_multi_vendor/mailers_preview/templates/mailers/previews/vendor_notification_preview.rb +5 -0
  90. data/lib/spree_multi_vendor.rb +14 -0
  91. data/lib/spree_multi_vendor/engine.rb +24 -0
  92. data/lib/spree_multi_vendor/factories.rb +7 -0
  93. data/lib/spree_multi_vendor/version.rb +11 -0
  94. data/lib/tasks/vendors.rake +8 -0
  95. data/spec/factories/spree/vendor_factory.rb +22 -0
  96. data/spec/factories/spree/vendor_image_factory.rb +5 -0
  97. data/spec/factories/spree/vendor_user_factory.rb +6 -0
  98. data/spec/features/spree/admin/orders_spec.rb +36 -0
  99. data/spec/features/spree/admin/product_spec.rb +177 -0
  100. data/spec/features/spree/admin/shipping_method_spec.rb +72 -0
  101. data/spec/features/spree/admin/stock_location_spec.rb +90 -0
  102. data/spec/features/spree/admin/vendor_settings_spec.rb +76 -0
  103. data/spec/features/spree/admin/vendor_spec.rb +125 -0
  104. data/spec/fixtures/thinking-cat.jpg +0 -0
  105. data/spec/mailers/vendor_mailer_spec.rb +45 -0
  106. data/spec/models/spree/line_item_spec.rb +32 -0
  107. data/spec/models/spree/order_commission_spec.rb +8 -0
  108. data/spec/models/spree/order_spec.rb +179 -0
  109. data/spec/models/spree/product_spec.rb +19 -0
  110. data/spec/models/spree/variant_spec.rb +104 -0
  111. data/spec/models/spree/vendor_order_totals_spec.rb +33 -0
  112. data/spec/models/spree/vendor_spec.rb +57 -0
  113. data/spec/models/spree/vendor_user_spec.rb +12 -0
  114. data/spec/requests/spree/api/v2/storefront/cart_spec.rb +67 -0
  115. data/spec/requests/spree/api/v2/storefront/products_spec.rb +93 -0
  116. data/spec/requests/spree/api/v2/storefront/vendors_spec.rb +52 -0
  117. data/spec/serializers/spree/v2/storefront/stock_location_serializer_spec.rb +32 -0
  118. data/spec/serializers/spree/v2/storefront/vendor_image_serializer_spec.rb +18 -0
  119. data/spec/serializers/spree/v2/storefront/vendor_order_totals_serializer_spec.rb +54 -0
  120. data/spec/serializers/spree/v2/storefront/vendor_serializer_spec.rb +34 -0
  121. data/spec/spec_helper.rb +11 -0
  122. data/spec/support/shoulda_matchers.rb +6 -0
  123. data/spree_multi_vendor.gemspec +41 -0
  124. metadata +313 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2249038a9dae7dde5d3c7b0eb3833921f4bdd0144ab76fa5c7277e53ee4aadce
4
+ data.tar.gz: 555815de55c3298001c60c753b69974e1d524db73257a130a661279b4ec3e594
5
+ SHA512:
6
+ metadata.gz: 6db7385cd15712b90faf63172eb6f2a05bebd0941f12ddd0faa55c53ce44ddca10c1527fb46ecbcd1524d9662e44359bdafb8eb26044012445d9b157552090ba
7
+ data.tar.gz: 48a0f9438bf8f7df0fc303760be106f23632b40e903f9cea0afc786ab523c181f52677817b0c633b800457a409569a331b9fc8aebfc997f71e53a955d990ff15
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ \#*
2
+ *~
3
+ .#*
4
+ .DS_Store
5
+ .idea
6
+ .localeapp/locales
7
+ .project
8
+ coverage
9
+ Gemfile.lock
10
+ tmp
11
+ nbproject
12
+ pkg
13
+ *.sw?
14
+ spec/dummy
15
+ .rvmrc
16
+ .sass-cache
17
+ public/spree
18
+ .ruby-version
19
+ .ruby-gemset
20
+ gemfiles/*.gemfile.lock
21
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ -r spec_helper
3
+ -f documentation
data/.travis.yml ADDED
@@ -0,0 +1,44 @@
1
+ os: linux
2
+ dist: bionic
3
+
4
+ addons:
5
+ apt:
6
+ sources:
7
+ - google-chrome
8
+ packages:
9
+ - google-chrome-stable
10
+
11
+ services:
12
+ - mysql
13
+ - postgresql
14
+
15
+ language: ruby
16
+
17
+ rvm:
18
+ - 2.7
19
+ - 3.0
20
+
21
+ env:
22
+ - DB=mysql
23
+ - DB=postgres
24
+
25
+ gemfile:
26
+ - gemfiles/spree_4_2.gemfile
27
+ - gemfiles/spree_master.gemfile
28
+
29
+ jobs:
30
+ allow_failures:
31
+ - gemfile: gemfiles/spree_master.gemfile
32
+
33
+ before_install:
34
+ - mysql -u root -e "GRANT ALL ON *.* TO 'travis'@'%';"
35
+
36
+ before_script:
37
+ - CHROME_MAIN_VERSION=`google-chrome-stable --version | sed -E 's/(^Google Chrome |\.[0-9]+ )//g'`
38
+ - CHROMEDRIVER_VERSION=`curl -s "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$CHROME_MAIN_VERSION"`
39
+ - curl "https://chromedriver.storage.googleapis.com/${CHROMEDRIVER_VERSION}/chromedriver_linux64.zip" -O
40
+ - unzip chromedriver_linux64.zip -d ~/bin
41
+
42
+ script:
43
+ - bundle exec rake test_app
44
+ - bundle exec rake spec
data/Appraisals ADDED
@@ -0,0 +1,11 @@
1
+ appraise 'spree-4-2' do
2
+ gem 'spree', '~> 4.2.0.rc4'
3
+ gem 'spree_auth_devise', '~> 4.3'
4
+ gem 'rails-controller-testing'
5
+ end
6
+
7
+ appraise 'spree-master' do
8
+ gem 'spree', github: 'spree/spree', branch: 'master'
9
+ gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: 'master'
10
+ gem 'rails-controller-testing'
11
+ end
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'spree', github: 'spree/spree', branch: 'master'
4
+ gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: 'master'
5
+ gem 'rails-controller-testing'
6
+
7
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2017 Spark Solutions Sp. z o.o.
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.
data/README.md ADDED
@@ -0,0 +1,166 @@
1
+ # Spree Multi Vendor
2
+
3
+ [![Build Status](https://travis-ci.org/spree-contrib/spree_multi_vendor.svg?branch=master)](https://travis-ci.org/spree-contrib/spree_multi_vendor)
4
+
5
+ This is a [spree multi vendor marketplace](https://spreecommerce.org/use-cases/multi-vendor-marketplace/) extension. It's a great starting point if you're building a marketplace on top of [Spree](https://spreecommerce.org). Our goal was flexibility to allow you to tweak it to your needs.
6
+
7
+ Check out this extension [multi vendor marketplace demo](https://spreecommerce.org/launch-a-multi-vendor-marketplace-within-a-few-weeks-with-spree-commerce/) and launch your marketplace within weeks, not months.
8
+
9
+ Developed and maintained by:
10
+
11
+ [![Spark Solutions](http://sparksolutions.co/wp-content/uploads/2015/01/logo-ss-tr-221x100.png)][spark]
12
+
13
+ ## Features
14
+
15
+ By default you can create and manage Vendors who can manage on their own:
16
+
17
+ - [X] Orders
18
+ - [X] Products
19
+ - [X] Stock Locations
20
+ - [X] Shipping Methods
21
+ - [X] Vendor profile
22
+
23
+ Also:
24
+ - [X] Super Admins can assign Users to Vendors
25
+ - [X] You can modify which permissions and models/resources Vendors can manage quite easily
26
+
27
+ Contributions welcome! :)
28
+
29
+ ## Installation
30
+
31
+ 1. Add this extension to your Gemfile with this line:
32
+ ```ruby
33
+ gem 'spree_multi_vendor'
34
+ ```
35
+
36
+ 2. Install the gem using Bundler:
37
+ ```ruby
38
+ bundle install
39
+ ```
40
+
41
+ 3. Copy & run migrations
42
+ ```ruby
43
+ bundle exec rails g spree_multi_vendor:install
44
+ ```
45
+
46
+ 4. Restart your server
47
+
48
+ If your server was running, restart it so that it can find the assets properly.
49
+
50
+ 5. Optionally you can also create sample Vendor by running:
51
+
52
+ ```bash
53
+ bundle exec rake spree_multi_vendor:sample:create
54
+ ```
55
+
56
+ ## Upgrading
57
+
58
+ 1. Fetch new database migrations:
59
+
60
+ ```bash
61
+ bundle exec rake railties:install:migrations FROM=spree_multi_vendor
62
+ ```
63
+
64
+ 2. Run migrations
65
+
66
+ ```bash
67
+ bundle exec rails db:migrate
68
+ ```
69
+
70
+ ## Configuration
71
+
72
+ To change which models should be vendorized, in your Spree initializer (`config/initializers/spree.rb`) add:
73
+
74
+ ```ruby
75
+ SpreeMultiVendor::Config[:vendorized_models] = %w[product variant stock_location shipping_method other_model]
76
+ ```
77
+
78
+ This will lookup for `Spree::OtherModel` class. To add `vendor_id` column to that model run:
79
+
80
+ ```bash
81
+ bundle exec rails g migration AddVendorToSpreeOtherModels vendor:references
82
+ ```
83
+
84
+ ## API endpoints
85
+
86
+ Spree Multi Vendor adds new [API v2](https://api.spreecommerce.org/docs/api-v2/api/docs/v2/storefront/index.yaml) endpoints:
87
+
88
+ 1. `GET` Display Vendor information endpoint
89
+
90
+ ```
91
+ /api/v2/storefront/vendors/<vendor_slug>
92
+ ```
93
+
94
+ eg. `/api/v2/storefront/vendors/test-vendor`
95
+
96
+ you can also include Vendor image and/or Products in that call:
97
+
98
+ `/api/v2/storefront/vendors/test-vendor?include=image,products`
99
+
100
+ And modfies existing:
101
+
102
+ 1. `GET` Filtering Products by Vendor ID(s):
103
+
104
+ ```
105
+ /api/v2/storefront/products?filter[vendor_ids]=1,2,3
106
+ ```
107
+
108
+ 2. `GET` Include Vendor information in Cart endpoint:
109
+
110
+ ```
111
+ /api/v2/storefront/cart?include=vendors,vendor_totals
112
+ ```
113
+
114
+ ## Email previews
115
+
116
+ Spree offers emails preview generator for development purposes.
117
+ To generate them, use command:
118
+
119
+ `bundle exec rails g spree_multi_vendor:mailers_preview`
120
+
121
+ After that, start rails server locally and go to:
122
+ `localhost:3000/rails/mailers`
123
+
124
+ (it requires seeded development database in order to work properly)
125
+
126
+ ## Testing
127
+
128
+ First bundle your dependencies, then run `rake`. `rake` will default to building the dummy app if it does not exist, then it will run specs. The dummy app can be regenerated by using `rake test_app`.
129
+
130
+ ```shell
131
+ bundle
132
+ bundle exec rake
133
+ ```
134
+
135
+ When testing your applications integration with this extension you may use it's factories.
136
+ Simply add this require statement to your spec_helper:
137
+
138
+ ```ruby
139
+ require 'spree_multi_vendor/factories'
140
+ ```
141
+
142
+ ## Contributing
143
+
144
+ If you'd like to contribute, please take a look at the
145
+ [instructions](CONTRIBUTING.md) for installing dependencies and crafting a good
146
+ pull request.
147
+
148
+ ## License
149
+
150
+ Spree Multi Vendor is copyright © 2017-2021
151
+ [Spark Solutions Sp. z o.o.][spark]. It is free software,
152
+ and may be redistributed under the terms specified in the
153
+ [LICENCE](LICENSE) file.
154
+
155
+ [LICENSE]: https://github.com/spark-solutions/spree_braintree_vzero/blob/master/LICENSE
156
+
157
+ ## About Spark Solutions
158
+
159
+ [![Spark Solutions](http://sparksolutions.co/wp-content/uploads/2015/01/logo-ss-tr-221x100.png)][spark]
160
+
161
+ Spree Vendors is maintained by [Spark Solutions Sp. z o.o.](http://sparksolutions.co?utm_source=github)
162
+
163
+ We are passionate about open source software.
164
+ We are [available for hire][spark].
165
+
166
+ [spark]:http://sparksolutions.co?utm_source=github
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ require 'spree/testing_support/extension_rake'
6
+
7
+ RSpec::Core::RakeTask.new
8
+
9
+ task :default do
10
+ if Dir["spec/dummy"].empty?
11
+ Rake::Task[:test_app].invoke
12
+ Dir.chdir("../../")
13
+ end
14
+ Rake::Task[:spec].invoke
15
+ end
16
+
17
+ desc 'Generates a dummy app for testing'
18
+ task :test_app do
19
+ ENV['LIB_NAME'] = 'spree_multi_vendor'
20
+ Rake::Task['extension:test_app'].invoke
21
+ end
@@ -0,0 +1,34 @@
1
+ module Spree
2
+ module Admin
3
+ class VendorSettingsController < Spree::Admin::BaseController
4
+ before_action :authorize
5
+ before_action :load_vendor
6
+
7
+ def update
8
+ if vendor_params[:image] && Spree.version.to_f >= 3.6
9
+ @vendor.create_image(attachment: vendor_params[:image])
10
+ end
11
+ if @vendor.update(vendor_params.except(:image))
12
+ redirect_to admin_vendor_settings_path
13
+ else
14
+ render :edit
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def authorize
21
+ authorize! :manage, :vendor_settings
22
+ end
23
+
24
+ def load_vendor
25
+ @vendor = current_spree_vendor
26
+ raise ActiveRecord::RecordNotFound unless @vendor
27
+ end
28
+
29
+ def vendor_params
30
+ params.require(:vendor).permit(Spree::PermittedAttributes.vendor_attributes)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,60 @@
1
+ module Spree
2
+ module Admin
3
+ class VendorsController < ResourceController
4
+
5
+ def create
6
+ if permitted_resource_params[:image] && Spree.version.to_f >= 3.6
7
+ @vendor.build_image(attachment: permitted_resource_params.delete(:image))
8
+ end
9
+ super
10
+ end
11
+
12
+ def update
13
+ if permitted_resource_params[:image] && Spree.version.to_f >= 3.6
14
+ @vendor.create_image(attachment: permitted_resource_params.delete(:image))
15
+ end
16
+ format_translations if defined? SpreeGlobalize
17
+ super
18
+ end
19
+
20
+ def update_positions
21
+ params[:positions].each do |id, position|
22
+ vendor = Spree::Vendor.find(id)
23
+ vendor.set_list_position(position)
24
+ end
25
+
26
+ respond_to do |format|
27
+ format.js { render plain: 'Ok' }
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def find_resource
34
+ Vendor.with_deleted.friendly.find(params[:id])
35
+ end
36
+
37
+ def collection
38
+ params[:q] = {} if params[:q].blank?
39
+ vendors = super.order(priority: :asc)
40
+ @search = vendors.ransack(params[:q])
41
+
42
+ @collection = @search.result.
43
+ page(params[:page]).
44
+ per(params[:per_page])
45
+ end
46
+
47
+ def format_translations
48
+ return if params[:vendor][:translations_attributes].blank?
49
+ params[:vendor][:translations_attributes].each do |_, data|
50
+ translation = @vendor.translations.find_or_create_by(locale: data[:locale])
51
+ translation.name = data[:name]
52
+ translation.about_us = data[:about_us]
53
+ translation.contact_us = data[:contact_us]
54
+ translation.slug = data[:slug]
55
+ translation.save!
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,28 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Storefront
5
+ class VendorsController < ::Spree::Api::V2::ResourceController
6
+
7
+ private
8
+
9
+ def model_class
10
+ ::Spree::Vendor
11
+ end
12
+
13
+ def scope
14
+ ::Spree::Vendor.active
15
+ end
16
+
17
+ def resource
18
+ scope.find_by(slug: params[:id]) || scope.find(params[:id])
19
+ end
20
+
21
+ def resource_serializer
22
+ Spree::V2::Storefront::VendorSerializer
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end