atkhayar-dev-spree-multi-vendor 0.0.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.
- checksums.yaml +7 -0
- data/Gemfile +10 -0
- data/LICENSE +26 -0
- data/README.md +181 -0
- data/Rakefile +21 -0
- data/app/controllers/spree/admin/vendor_settings_controller.rb +34 -0
- data/app/controllers/spree/admin/vendors_controller.rb +68 -0
- data/app/controllers/spree/api/v1/vendors_controller.rb +62 -0
- data/app/controllers/spree/api/v2/platform/vendors_controller.rb +32 -0
- data/app/controllers/spree/api/v2/storefront/vendors_controller.rb +33 -0
- data/app/controllers/spree_multi_vendor/spree/admin/base_controller_decorator.rb +10 -0
- data/app/controllers/spree_multi_vendor/spree/admin/products_controller_decorator.rb +79 -0
- data/app/controllers/spree_multi_vendor/spree/admin/resource_controller_decorator.rb +8 -0
- data/app/controllers/spree_multi_vendor/spree/admin/shipping_methods_controller_decorator.rb +7 -0
- data/app/controllers/spree_multi_vendor/spree/admin/stock_locations_controller_decorator.rb +7 -0
- data/app/controllers/spree_multi_vendor/spree/admin/users_controller_decorator.rb +13 -0
- data/app/controllers/spree_multi_vendor/spree/admin/variants_controller_decorator.rb +7 -0
- data/app/controllers/spree_multi_vendor/spree/api/base_controller_decorator.rb +17 -0
- data/app/controllers/spree_multi_vendor/spree/api/v1/products_controller_decorator.rb +9 -0
- data/app/controllers/spree_multi_vendor/spree/api/v1/users_controller_decorator.rb +13 -0
- data/app/controllers/spree_multi_vendor/spree/api/v2/platform/products_controller_decorator.rb +65 -0
- data/app/finders/spree_multi_vendor/products_finder_decorator.rb +31 -0
- data/app/helpers/spree/admin/vendor_helper.rb +15 -0
- data/app/helpers/spree/api/vendor_helper.rb +13 -0
- data/app/helpers/spree_multi_vendor/spree/api/api_helpers_decorator.rb +19 -0
- data/app/mailers/spree/vendor_mailer.rb +15 -0
- data/app/models/concerns/spree/vendor_concern.rb +11 -0
- data/app/models/spree/order_commission.rb +11 -0
- data/app/models/spree/vendor.rb +77 -0
- data/app/models/spree/vendor_ability.rb +155 -0
- data/app/models/spree/vendor_image.rb +18 -0
- data/app/models/spree/vendor_order_totals.rb +28 -0
- data/app/models/spree/vendor_user.rb +16 -0
- data/app/models/spree_multi_vendor/configuration.rb +10 -0
- data/app/models/spree_multi_vendor/spree/ability_decorator.rb +9 -0
- data/app/models/spree_multi_vendor/spree/base_decorator.rb +13 -0
- data/app/models/spree_multi_vendor/spree/line_item_decorator.rb +48 -0
- data/app/models/spree_multi_vendor/spree/order_decorator.rb +107 -0
- data/app/models/spree_multi_vendor/spree/shipment_decorator.rb +8 -0
- data/app/models/spree_multi_vendor/spree/stock/package_decorator.rb +14 -0
- data/app/models/spree_multi_vendor/spree/user_decorator.rb +8 -0
- data/app/models/spree_multi_vendor/spree/variant_decorator.rb +40 -0
- data/app/overrides/spree/admin/orders/_form.rb +13 -0
- data/app/overrides/spree/admin/orders/_line_items.rb +6 -0
- data/app/overrides/spree/admin/orders/_line_items_edit_form.rb +6 -0
- data/app/overrides/spree/admin/orders/index.rb +6 -0
- data/app/overrides/spree/admin/products/form.rb +29 -0
- data/app/overrides/spree/admin/products/new.rb +16 -0
- data/app/overrides/spree/admin/shared/_main_menu.rb +23 -0
- data/app/overrides/spree/admin/shared/_order_summary.rb +35 -0
- data/app/overrides/spree/admin/users/_form.rb +13 -0
- data/app/serializers/spree/api/v2/platform/vendor_serializer.rb +12 -0
- data/app/serializers/spree/v2/storefront/vendor_image_serializer.rb +11 -0
- data/app/serializers/spree/v2/storefront/vendor_order_totals_serializer.rb +20 -0
- data/app/serializers/spree/v2/storefront/vendor_serializer.rb +15 -0
- data/app/serializers/spree_multi_vendor/cart_serializer_decorator.rb +19 -0
- data/app/serializers/spree_multi_vendor/serializer_decorator.rb +23 -0
- data/app/services/spree/orders/generate_commissions.rb +34 -0
- data/app/views/spree/admin/translations/vendor.html.erb +21 -0
- data/app/views/spree/admin/vendor_settings/edit.html.erb +47 -0
- data/app/views/spree/admin/vendors/_form.html.erb +36 -0
- data/app/views/spree/admin/vendors/edit.html.erb +11 -0
- data/app/views/spree/admin/vendors/index.html.erb +83 -0
- data/app/views/spree/admin/vendors/new.html.erb +11 -0
- data/app/views/spree/api/v1/vendors/index.rabl +3 -0
- data/app/views/spree/api/v1/vendors/show.rabl +2 -0
- data/app/views/spree/vendor_mailer/vendor_notification_email.html.erb +81 -0
- data/app/views/spree/vendor_mailer/vendor_notification_email.text.erb +36 -0
- data/bin/rails +7 -0
- data/config/initializers/spree.rb +31 -0
- data/config/initializers/spree_permitted_attributes.rb +12 -0
- data/config/locales/en.yml +34 -0
- data/config/locales/es.yml +36 -0
- data/config/locales/fr.yml +33 -0
- data/config/routes.rb +29 -0
- data/db/default/vendors.rb +13 -0
- data/db/migrate/20170406102250_create_spree_vendors.rb +9 -0
- data/db/migrate/20170406102944_add_vendor_id_to_spree_models.rb +10 -0
- data/db/migrate/20170410111150_add_state_to_vendors.rb +6 -0
- data/db/migrate/20170412124925_add_deleted_at_to_spree_vendors.rb +6 -0
- data/db/migrate/20170413094447_create_spree_vendor_users.rb +11 -0
- data/db/migrate/20190212161426_add_slug_to_spree_vendors.rb +6 -0
- data/db/migrate/20190214120226_add_about_us_to_spree_vendors.rb +5 -0
- data/db/migrate/20190214142526_add_contact_us_to_spree_vendors.rb +5 -0
- data/db/migrate/20190305120337_add_commission_to_spree_vendors.rb +5 -0
- data/db/migrate/20190308091546_add_priority_to_vendor.rb +8 -0
- data/db/migrate/20190312130754_create_spree_order_commissions.rb +14 -0
- data/db/migrate/20190322133128_add_notification_email_to_vendors.rb +5 -0
- data/db/migrate/20200416030721_add_translations_to_vendor.rb +19 -0
- data/db/migrate/20210728120649_change_vendorized_models_vendor_id_type.rb +10 -0
- data/db/migrate/20210728120910_change_vendor_id_and_user_id_type_for_spree_vendor_users.rb +14 -0
- data/db/migrate/20210728121024_change_vendor_id_and_order_id_type_for_spree_order_commissions.rb +14 -0
- data/db/migrate/20221123095256_add_code_to_vendors.rb +6 -0
- data/lib/generators/spree_multi_vendor/install/install_generator.rb +21 -0
- data/lib/generators/spree_multi_vendor/mailers_preview/mailers_preview_generator.rb +22 -0
- data/lib/generators/spree_multi_vendor/mailers_preview/templates/mailers/previews/vendor_notification_preview.rb +5 -0
- data/lib/spree_multi_vendor/engine.rb +24 -0
- data/lib/spree_multi_vendor/factories.rb +7 -0
- data/lib/spree_multi_vendor/version.rb +11 -0
- data/lib/spree_multi_vendor.rb +16 -0
- data/lib/tasks/vendors.rake +8 -0
- data/spec/factories/spree/vendor_factory.rb +28 -0
- data/spec/factories/spree/vendor_image_factory.rb +5 -0
- data/spec/factories/spree/vendor_user_factory.rb +6 -0
- data/spec/features/spree/admin/orders_spec.rb +86 -0
- data/spec/features/spree/admin/product_spec.rb +177 -0
- data/spec/features/spree/admin/shipping_method_spec.rb +72 -0
- data/spec/features/spree/admin/stock_location_spec.rb +90 -0
- data/spec/features/spree/admin/vendor_settings_spec.rb +74 -0
- data/spec/features/spree/admin/vendor_spec.rb +125 -0
- data/spec/fixtures/thinking-cat.jpg +0 -0
- data/spec/mailers/vendor_mailer_spec.rb +45 -0
- data/spec/models/spree/line_item_spec.rb +32 -0
- data/spec/models/spree/order_commission_spec.rb +8 -0
- data/spec/models/spree/order_spec.rb +193 -0
- data/spec/models/spree/product_spec.rb +19 -0
- data/spec/models/spree/variant_spec.rb +104 -0
- data/spec/models/spree/vendor_order_totals_spec.rb +33 -0
- data/spec/models/spree/vendor_spec.rb +57 -0
- data/spec/models/spree/vendor_user_spec.rb +12 -0
- data/spec/requests/spree/api/v1/products_spec.rb +221 -0
- data/spec/requests/spree/api/v1/users_spec.rb +31 -0
- data/spec/requests/spree/api/v1/vendors_spec.rb +210 -0
- data/spec/requests/spree/api/v2/storefront/cart_spec.rb +85 -0
- data/spec/requests/spree/api/v2/storefront/products_spec.rb +96 -0
- data/spec/requests/spree/api/v2/storefront/vendors_spec.rb +118 -0
- data/spec/serializers/spree/v2/storefront/stock_location_serializer_spec.rb +32 -0
- data/spec/serializers/spree/v2/storefront/vendor_image_serializer_spec.rb +18 -0
- data/spec/serializers/spree/v2/storefront/vendor_order_totals_serializer_spec.rb +54 -0
- data/spec/serializers/spree/v2/storefront/vendor_serializer_spec.rb +34 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/support/shoulda_matchers.rb +6 -0
- data/spree_multi_vendor.gemspec +42 -0
- metadata +308 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: f8d441270696f26a0ec197744282b7e53cb4a397a0286096865cdb40aaf53602
|
|
4
|
+
data.tar.gz: e5426a049d5bb36210ddaf1f805a8d665a702a495ff6d389234ff18079fc4e1a
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ad638c991ec5c6d4a30b90ab19cb29122ffc85304e7be0a3c45e0f8e3640893a7490377518177175648d42890033c068f1d5656026be1477141280de9734ec7d
|
|
7
|
+
data.tar.gz: 4896ff5234fe10c63eaa544729bee2039feac8b04f0021fc9f912cd9a3db68f015c0da592bfca1cdcd0d1395580dc687c32988c4228587b047250e7c25aac889
|
data/Gemfile
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
source 'https://rubygems.org'
|
|
2
|
+
|
|
3
|
+
gem 'spree', github: 'spree/spree', branch: 'main'
|
|
4
|
+
gem 'spree_backend', github: 'spree/spree_backend', branch: 'main'
|
|
5
|
+
gem 'spree_frontend', github: 'spree/spree_legacy_frontend', branch: 'main'
|
|
6
|
+
gem 'spree_emails', github: 'spree/spree', branch: 'main'
|
|
7
|
+
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: 'main'
|
|
8
|
+
gem 'rails-controller-testing'
|
|
9
|
+
|
|
10
|
+
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,181 @@
|
|
|
1
|
+
# Spree Multi Vendor
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
## Developed by
|
|
6
|
+
|
|
7
|
+
[](https://getvendo.com?utm_source=spree_multi_vendor_github)
|
|
8
|
+
|
|
9
|
+
> All-in-one platform for all your Marketplace and B2B eCommerce needs. [Start your 30-day free trial](https://e98esoirr8c.typeform.com/contactvendo?typeform-source=spree_multi_vendor_github)
|
|
10
|
+
|
|
11
|
+
## Open source vs Vendo
|
|
12
|
+
|
|
13
|
+
If you need a product that has all of the features out of the box, such us supplier onboarding, Stripe connect payment splitting and payouts, and don't require any custom development - we recommend using [Vendo](http://getvendo.com?utm_source=spree_multi_vendor_github) which is also based on Spree.
|
|
14
|
+
|
|
15
|
+
| feature | open source | [vendo] |
|
|
16
|
+
|---|---|---|
|
|
17
|
+
| basic vendorization | ✔️ | ✔️ |
|
|
18
|
+
| supplier onboarding | | ✔️ |
|
|
19
|
+
| supplier dashboard | | ✔️ |
|
|
20
|
+
| supplier management | | ✔️ |
|
|
21
|
+
| supplier product curation | | ✔️ |
|
|
22
|
+
| automatic payment splitting | | ✔️ |
|
|
23
|
+
| automatic payouts | | ✔️ |
|
|
24
|
+
| Afterpay / klarna / apple pay | | ✔️ |
|
|
25
|
+
| shopify / bigcommerce / woocommerce integration | | ✔️ |
|
|
26
|
+
| USPS, UPS, FedEx, DHL, and more | | ✔️ |
|
|
27
|
+
| bulk upload / import of products from CSV and XSLX | | ✔️ |
|
|
28
|
+
| bulk export of orders, shipments and more | | ✔️ |
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
1. Add this extension to your Gemfile with this line:
|
|
33
|
+
```ruby
|
|
34
|
+
gem 'spree_multi_vendor'
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
2. Install the gem using Bundler:
|
|
38
|
+
```ruby
|
|
39
|
+
bundle install
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
3. Copy & run migrations
|
|
43
|
+
```ruby
|
|
44
|
+
bundle exec rails g spree_multi_vendor:install
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
4. Restart your server
|
|
48
|
+
|
|
49
|
+
If your server was running, restart it so that it can find the assets properly.
|
|
50
|
+
|
|
51
|
+
5. Optionally you can also create sample Vendor by running:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
bundle exec rake spree_multi_vendor:sample:create
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Upgrading
|
|
58
|
+
|
|
59
|
+
1. Fetch new database migrations:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
bundle exec rake railties:install:migrations FROM=spree_multi_vendor
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
2. Run migrations
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
bundle exec rails db:migrate
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Configuration
|
|
72
|
+
|
|
73
|
+
To change which models should be vendorized, in your Spree initializer (`config/initializers/spree.rb`) add:
|
|
74
|
+
|
|
75
|
+
```ruby
|
|
76
|
+
SpreeMultiVendor::Config[:vendorized_models] = %w[product variant stock_location shipping_method other_model]
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
This will lookup for `Spree::OtherModel` class. To add `vendor_id` column to that model run:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
bundle exec rails g migration AddVendorToSpreeOtherModels vendor:references
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## API endpoints
|
|
86
|
+
|
|
87
|
+
Spree Multi Vendor adds new [API v2](https://api.spreecommerce.org/docs/api-v2/api/docs/v2/storefront/index.yaml) endpoints:
|
|
88
|
+
|
|
89
|
+
1. `GET` Display Vendor information endpoint
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
/api/v2/storefront/vendors/<vendor_slug>
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
eg. `/api/v2/storefront/vendors/test-vendor`
|
|
96
|
+
|
|
97
|
+
you can also include Vendor image and/or Products in that call:
|
|
98
|
+
|
|
99
|
+
`/api/v2/storefront/vendors/test-vendor?include=image,products`
|
|
100
|
+
|
|
101
|
+
2. `GET` Returns a list of Vendors
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
/api/v2/storefront/vendors
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
you can also include Vendor image and/or Products in that call:
|
|
108
|
+
|
|
109
|
+
`/api/v2/storefront/vendors?include=image,products`
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
And modfies existing:
|
|
113
|
+
|
|
114
|
+
1. `GET` Filtering Products by Vendor ID(s):
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
/api/v2/storefront/products?filter[vendor_ids]=1,2,3
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
2. `GET` Include Vendor information in Cart endpoint:
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
/api/v2/storefront/cart?include=vendors,vendor_totals
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Email previews
|
|
127
|
+
|
|
128
|
+
Spree offers emails preview generator for development purposes.
|
|
129
|
+
To generate them, use command:
|
|
130
|
+
|
|
131
|
+
`bundle exec rails g spree_multi_vendor:mailers_preview`
|
|
132
|
+
|
|
133
|
+
After that, start rails server locally and go to:
|
|
134
|
+
`localhost:3000/rails/mailers`
|
|
135
|
+
|
|
136
|
+
(it requires seeded development database in order to work properly)
|
|
137
|
+
|
|
138
|
+
## Testing
|
|
139
|
+
|
|
140
|
+
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`.
|
|
141
|
+
|
|
142
|
+
```shell
|
|
143
|
+
bundle
|
|
144
|
+
bundle exec rake
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
When testing your applications integration with this extension you may use it's factories.
|
|
148
|
+
Simply add this require statement to your spec_helper:
|
|
149
|
+
|
|
150
|
+
```ruby
|
|
151
|
+
require 'spree_multi_vendor/factories'
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Contributing
|
|
155
|
+
|
|
156
|
+
If you'd like to contribute, please take a look at the
|
|
157
|
+
[instructions](CONTRIBUTING.md) for installing dependencies and crafting a good
|
|
158
|
+
pull request.
|
|
159
|
+
|
|
160
|
+
## License
|
|
161
|
+
|
|
162
|
+
Spree Multi Vendor is copyright © 2017-2021
|
|
163
|
+
[Spark Solutions Sp. z o.o.][spark]. It is free software,
|
|
164
|
+
and may be redistributed under the terms specified in the
|
|
165
|
+
[LICENCE](LICENSE) file.
|
|
166
|
+
|
|
167
|
+
[LICENSE]: https://github.com/spark-solutions/spree_braintree_vzero/blob/master/LICENSE
|
|
168
|
+
|
|
169
|
+
## About Vendo
|
|
170
|
+
|
|
171
|
+
<a href="https://getvendo.com?utm_source=spree_multi_vendor_github">
|
|
172
|
+
<img src="https://uploads-ssl.webflow.com/6230c485f2c32ea1b0daa438/62386b96518cdcbe111f134a_OG%20Image%20(2).png" style="max-height:400px" />
|
|
173
|
+
</a>
|
|
174
|
+
|
|
175
|
+
> [Vendo][vendo] is a great fit for marketplaces of all sizes - either with own fulfillment and multiple warehouses or in a dropshipping model. Vendo **automates everything** from **vendor onboarding**, accepting buyer **payments in over 135 currencies**, to supplier **payouts in 50 countries**.
|
|
176
|
+
|
|
177
|
+
> Vendo ensures excellent buyer experience with smooth product discovery and search, a multitude of payment methods and optimal shipping cost calculation. Vendo keeps suppliers happy with easy onboarding, automated products sync using their preferred method and easy payouts.
|
|
178
|
+
|
|
179
|
+
> [Start your 30-day free trial](https://e98esoirr8c.typeform.com/contactvendo?typeform-source=spree_multi_vendor_github)
|
|
180
|
+
|
|
181
|
+
[vendo]:http://getvendo.com?utm_source=spree_multi_vendor_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]
|
|
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,68 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Admin
|
|
3
|
+
class VendorsController < ResourceController
|
|
4
|
+
|
|
5
|
+
def create
|
|
6
|
+
if permitted_resource_params[:image]
|
|
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]
|
|
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
|
+
includes(vendor_includes).
|
|
44
|
+
page(params[:page]).
|
|
45
|
+
per(params[:per_page])
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def vendor_includes
|
|
49
|
+
{
|
|
50
|
+
image: [],
|
|
51
|
+
products: []
|
|
52
|
+
}
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def format_translations
|
|
56
|
+
return if params[:vendor][:translations_attributes].blank?
|
|
57
|
+
params[:vendor][:translations_attributes].each do |_, data|
|
|
58
|
+
translation = @vendor.translations.find_or_create_by(locale: data[:locale])
|
|
59
|
+
translation.name = data[:name]
|
|
60
|
+
translation.about_us = data[:about_us]
|
|
61
|
+
translation.contact_us = data[:contact_us]
|
|
62
|
+
translation.slug = data[:slug]
|
|
63
|
+
translation.save!
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Api
|
|
3
|
+
module V1
|
|
4
|
+
class VendorsController < Spree::Api::BaseController
|
|
5
|
+
def index
|
|
6
|
+
@vendors = if params[:ids].present?
|
|
7
|
+
scope.where(id: params[:ids].split(','))
|
|
8
|
+
else
|
|
9
|
+
scope.load.ransack(
|
|
10
|
+
params[:q]
|
|
11
|
+
).result
|
|
12
|
+
end
|
|
13
|
+
respond_with(@vendors)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def show
|
|
17
|
+
@vendor = scope.find(params[:id])
|
|
18
|
+
authorize! :show, @vendor
|
|
19
|
+
respond_with(@vendor)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def create
|
|
23
|
+
spree_authorize! :create, Spree::Vendor
|
|
24
|
+
@vendor = Spree::Vendor.new(vendor_params)
|
|
25
|
+
if @vendor.save
|
|
26
|
+
#render :show, status: 201
|
|
27
|
+
else
|
|
28
|
+
invalid_resource!(@vendor)
|
|
29
|
+
end
|
|
30
|
+
#render_order()
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def update
|
|
34
|
+
@vendor = scope.find(params[:id])
|
|
35
|
+
authorize! :update, @vendor
|
|
36
|
+
if @vendor.update(vendor_params)
|
|
37
|
+
render :show
|
|
38
|
+
else
|
|
39
|
+
invalid_resource!(@vendor)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def destroy
|
|
44
|
+
@vendor = scope.find(params[:id])
|
|
45
|
+
authorize! :destroy, @vendor
|
|
46
|
+
@vendor.destroy
|
|
47
|
+
render plain: nil, status: 204
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
def scope
|
|
53
|
+
Spree::Vendor.accessible_by(current_ability)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def vendor_params
|
|
57
|
+
params.require(:vendor).permit(Spree::PermittedAttributes.vendor_attributes)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Api
|
|
3
|
+
module V2
|
|
4
|
+
module Platform
|
|
5
|
+
class VendorsController < ::Spree::Api::V2::Platform::ResourceController
|
|
6
|
+
private
|
|
7
|
+
|
|
8
|
+
def model_class
|
|
9
|
+
::Spree::Vendor
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def scope
|
|
13
|
+
::Spree::Vendor.active
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def resource_serializer
|
|
17
|
+
Spree::Api::V2::Platform::VendorSerializer
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def collection_serializer
|
|
21
|
+
Spree::Api::V2::Platform::VendorSerializer
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def spree_permitted_attributes
|
|
25
|
+
super + [:code]
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
|
|
25
|
+
def collection_serializer
|
|
26
|
+
Spree::V2::Storefront::VendorSerializer
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
module SpreeMultiVendor::Spree::Admin::BaseControllerDecorator
|
|
2
|
+
Spree::Admin::BaseController.include(Spree::Admin::VendorHelper)
|
|
3
|
+
|
|
4
|
+
def self.prepended(base)
|
|
5
|
+
base.helper_method :current_spree_vendor
|
|
6
|
+
base.helper_method :vendor_state_options
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
Spree::Admin::BaseController.prepend SpreeMultiVendor::Spree::Admin::BaseControllerDecorator
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
require 'typesense'
|
|
2
|
+
|
|
3
|
+
module SpreeMultiVendor::Spree::Admin::ProductsControllerDecorator
|
|
4
|
+
def self.prepended(base)
|
|
5
|
+
base.before_action only: [:create, :update] do
|
|
6
|
+
set_vendor_id(:product)
|
|
7
|
+
end
|
|
8
|
+
# base.after_action :load_product_vendor
|
|
9
|
+
base.before_action :initiate_ts_client
|
|
10
|
+
base.after_action :create_ts_product, only: [:create]
|
|
11
|
+
base.after_action :update_ts_product, only: [:update]
|
|
12
|
+
base.after_action :delete_ts_product, only: [:destroy]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def initiate_ts_client
|
|
16
|
+
@typesense = Typesense::Client.new(
|
|
17
|
+
nodes: [
|
|
18
|
+
{
|
|
19
|
+
host: 'iraxmydlt35g8v6qp-1.a1.typesense.net',
|
|
20
|
+
port: 443,
|
|
21
|
+
protocol: 'https'
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
api_key: 'P524ViQst3aE0xlpbVY7or8bCAWbVtqv',
|
|
25
|
+
num_retries: 10,
|
|
26
|
+
healthcheck_interval_seconds: 1,
|
|
27
|
+
retry_interval_seconds: 0.01,
|
|
28
|
+
connection_timeout_seconds: 10
|
|
29
|
+
)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def create_ts_product
|
|
33
|
+
if @product
|
|
34
|
+
puts @product.vendor_id
|
|
35
|
+
@product_vendor = Spree::Vendor.find_by(id: @product.vendor_id)
|
|
36
|
+
classifications = Spree::Classification.where(product_id: @product.id)
|
|
37
|
+
categories = []
|
|
38
|
+
if !classifications.empty?
|
|
39
|
+
classifications.each do |classification|
|
|
40
|
+
taxon = Spree::Taxon.find_by(id: classification.taxon_id)
|
|
41
|
+
categories.push(taxon.name)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
document = {
|
|
45
|
+
'id' => @product.id.to_s,
|
|
46
|
+
'name' => @product.name,
|
|
47
|
+
'categories' => categories,
|
|
48
|
+
'tag' => [],
|
|
49
|
+
'store_id' => @product_vendor.code
|
|
50
|
+
}
|
|
51
|
+
document = @typesense.collections['dev-products'].documents.create(document)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def update_ts_product
|
|
56
|
+
if @product
|
|
57
|
+
classifications = Spree::Classification.where(product_id: @product.id)
|
|
58
|
+
categories = []
|
|
59
|
+
if !classifications.empty?
|
|
60
|
+
classifications.each do |classification|
|
|
61
|
+
taxon = Spree::Taxon.find_by(id: classification.taxon_id)
|
|
62
|
+
categories.push(taxon.name)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
@typesense.collections['dev-products'].documents[@product.id.to_s].update(
|
|
66
|
+
'name' => @product.name,
|
|
67
|
+
'categories' => categories
|
|
68
|
+
)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def delete_ts_product
|
|
73
|
+
if @product
|
|
74
|
+
@typesense.collections['dev-products'].documents[@product.id.to_s].delete()
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
Spree::Admin::ProductsController.prepend SpreeMultiVendor::Spree::Admin::ProductsControllerDecorator
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
module SpreeMultiVendor::Spree::Admin::ResourceControllerDecorator
|
|
2
|
+
def set_vendor_id
|
|
3
|
+
return unless current_spree_vendor
|
|
4
|
+
params[resource.object_name.to_sym][:vendor_id] = current_spree_vendor.id
|
|
5
|
+
end
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
Spree::Admin::ResourceController.prepend SpreeMultiVendor::Spree::Admin::ResourceControllerDecorator
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
module SpreeMultiVendor::Spree::Admin::ShippingMethodsControllerDecorator
|
|
2
|
+
def self.prepended(base)
|
|
3
|
+
base.before_action :set_vendor_id, only: [:create, :update]
|
|
4
|
+
end
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
Spree::Admin::ShippingMethodsController.prepend SpreeMultiVendor::Spree::Admin::ShippingMethodsControllerDecorator
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
module SpreeMultiVendor::Spree::Admin::StockLocationsControllerDecorator
|
|
2
|
+
def self.prepended(base)
|
|
3
|
+
base.before_action :set_vendor_id, only: [:create, :update]
|
|
4
|
+
end
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
Spree::Admin::StockLocationsController.prepend SpreeMultiVendor::Spree::Admin::StockLocationsControllerDecorator
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module SpreeMultiVendor::Spree::Admin::UsersControllerDecorator
|
|
2
|
+
private
|
|
3
|
+
|
|
4
|
+
def user_params
|
|
5
|
+
params.require(:user).permit(permitted_user_attributes |
|
|
6
|
+
[spree_role_ids: [],
|
|
7
|
+
vendor_ids: [],
|
|
8
|
+
ship_address_attributes: permitted_address_attributes,
|
|
9
|
+
bill_address_attributes: permitted_address_attributes])
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
Spree::Admin::UsersController.prepend SpreeMultiVendor::Spree::Admin::UsersControllerDecorator
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
module SpreeMultiVendor::Spree::Admin::VariantsControllerDecorator
|
|
2
|
+
def self.prepended(base)
|
|
3
|
+
base.before_action :set_vendor_id, only: [:create, :update]
|
|
4
|
+
end
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
Spree::Admin::VariantsController.prepend SpreeMultiVendor::Spree::Admin::VariantsControllerDecorator
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module SpreeMultiVendor::Spree::Api::BaseControllerDecorator
|
|
2
|
+
Spree::Api::V2::BaseController.include(Spree::Api::VendorHelper)
|
|
3
|
+
|
|
4
|
+
def self.prepended(base)
|
|
5
|
+
base.helper_method :current_spree_vendor
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
private
|
|
9
|
+
|
|
10
|
+
def set_vendor_id(resource_name)
|
|
11
|
+
return unless current_spree_vendor
|
|
12
|
+
|
|
13
|
+
params[resource_name][:vendor_id] = current_spree_vendor.id
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
::Spree::Api::V2::BaseController.prepend SpreeMultiVendor::Spree::Api::BaseControllerDecorator
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
module SpreeMultiVendor::Spree::Api::V1::ProductsControllerDecorator
|
|
2
|
+
def self.prepended(base)
|
|
3
|
+
base.before_action only: [:create, :update] do
|
|
4
|
+
set_vendor_id(:product)
|
|
5
|
+
end
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
Spree::Api::V2::Platform::ProductsController.prepend SpreeMultiVendor::Spree::Api::V1::ProductsControllerDecorator
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module SpreeMultiVendor::Spree::Api::V1::UsersControllerDecorator
|
|
2
|
+
private
|
|
3
|
+
|
|
4
|
+
def user_params
|
|
5
|
+
params.require(:user).permit(permitted_user_attributes |
|
|
6
|
+
[spree_role_ids: [],
|
|
7
|
+
vendor_ids: [],
|
|
8
|
+
ship_address_attributes: permitted_address_attributes,
|
|
9
|
+
bill_address_attributes: permitted_address_attributes])
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
Spree::Api::V2::Platform::UsersController.prepend SpreeMultiVendor::Spree::Api::V1::UsersControllerDecorator
|