spree_multi_vendor 2.0.1 → 2.3.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 +4 -4
- data/.github/dependabot.yml +7 -0
- data/.travis.yml +1 -8
- data/Gemfile +5 -2
- data/README.md +12 -1
- data/app/controllers/spree/admin/vendor_settings_controller.rb +1 -1
- data/app/controllers/spree/admin/vendors_controller.rb +10 -2
- data/app/controllers/spree/api/v1/vendors_controller.rb +61 -0
- data/app/controllers/spree/api/v2/storefront/vendors_controller.rb +6 -1
- 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/finders/spree_multi_vendor/products_finder_decorator.rb +1 -1
- data/app/helpers/spree/api/vendor_helper.rb +11 -0
- data/app/helpers/spree_multi_vendor/spree/api/api_helpers_decorator.rb +19 -0
- data/app/models/spree/vendor_ability.rb +24 -9
- data/app/models/spree/vendor_user.rb +1 -1
- data/app/models/spree_multi_vendor/configuration.rb +1 -1
- data/app/models/spree_multi_vendor/spree/order_decorator.rb +5 -3
- data/app/overrides/spree/admin/shared/_main_menu.rb +1 -1
- data/app/serializers/spree/v2/storefront/vendor_order_totals_serializer.rb +2 -0
- data/app/views/spree/admin/vendor_settings/edit.html.erb +1 -1
- data/app/views/spree/admin/vendors/_form.html.erb +1 -1
- data/app/views/spree/api/v1/vendors/index.rabl +3 -0
- data/app/views/spree/api/v1/vendors/show.rabl +2 -0
- data/config/initializers/spree_permitted_attributes.rb +2 -0
- data/config/locales/es.yml +3 -0
- data/config/routes.rb +4 -1
- 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 +8 -0
- data/db/migrate/20210728121024_change_vendor_id_and_order_id_type_for_spree_order_commissions.rb +8 -0
- data/lib/spree_multi_vendor/factories.rb +1 -1
- data/lib/spree_multi_vendor/version.rb +1 -1
- data/lib/spree_multi_vendor.rb +2 -1
- data/spec/factories/spree/vendor_factory.rb +6 -0
- data/spec/features/spree/admin/orders_spec.rb +62 -12
- data/spec/features/spree/admin/vendor_settings_spec.rb +6 -8
- data/spec/models/spree/order_spec.rb +16 -2
- 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 +19 -1
- data/spec/requests/spree/api/v2/storefront/products_spec.rb +4 -1
- data/spec/requests/spree/api/v2/storefront/vendors_spec.rb +66 -0
- data/spec/serializers/spree/v2/storefront/vendor_order_totals_serializer_spec.rb +2 -2
- data/spec/spec_helper.rb +3 -1
- data/spree_multi_vendor.gemspec +5 -4
- metadata +32 -38
- data/Appraisals +0 -11
- data/app/controllers/spree_multi_vendor/spree/admin/option_types_controller_decorator.rb +0 -7
- data/app/controllers/spree_multi_vendor/spree/admin/properties_controller_decorator.rb +0 -7
- data/app/controllers/spree_multi_vendor/spree/api/v1/variants_controller_decorator.rb +0 -22
- data/gemfiles/spree_4_2.gemfile +0 -9
- data/gemfiles/spree_master.gemfile +0 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fc35d0a2ae81399b7daa7f806f69725d71bfb5f7ea5b54ff0680d4b95e93e9e9
|
|
4
|
+
data.tar.gz: a19370e4fc2ae70fd6749ae829560d250ebb579844132d8fa9766043c0374c72
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6d55aa0438bf0ef0005320b21b90417370b388502b0b6a8957e5f291b988dd0b8b6c486e3d785360cb4c853b36ce978e5b972dee0a609eb5867435cc40aa532b
|
|
7
|
+
data.tar.gz: fbb4c2094e074e06edee73ea7338ddcac6d6d800ab1810d3134efdcd5283c0d3976161f7aa9b5803e79ad58e3cc68e71b690aa48e6a4397243c838db3b63f085
|
data/.travis.yml
CHANGED
|
@@ -11,6 +11,7 @@ addons:
|
|
|
11
11
|
services:
|
|
12
12
|
- mysql
|
|
13
13
|
- postgresql
|
|
14
|
+
- redis-server
|
|
14
15
|
|
|
15
16
|
language: ruby
|
|
16
17
|
|
|
@@ -22,14 +23,6 @@ env:
|
|
|
22
23
|
- DB=mysql
|
|
23
24
|
- DB=postgres
|
|
24
25
|
|
|
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
26
|
before_install:
|
|
34
27
|
- mysql -u root -e "GRANT ALL ON *.* TO 'travis'@'%';"
|
|
35
28
|
|
data/Gemfile
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
source 'https://rubygems.org'
|
|
2
2
|
|
|
3
|
-
gem 'spree', github: 'spree/spree', branch: '
|
|
4
|
-
gem '
|
|
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'
|
|
5
8
|
gem 'rails-controller-testing'
|
|
6
9
|
|
|
7
10
|
gemspec
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Spree Multi Vendor
|
|
2
2
|
|
|
3
|
-
[](https://travis-ci.com/spree-contrib/spree_multi_vendor)
|
|
4
4
|
|
|
5
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
6
|
|
|
@@ -97,6 +97,17 @@ Spree Multi Vendor adds new [API v2](https://api.spreecommerce.org/docs/api-v2/a
|
|
|
97
97
|
|
|
98
98
|
`/api/v2/storefront/vendors/test-vendor?include=image,products`
|
|
99
99
|
|
|
100
|
+
2. `GET` Returns a list of Vendors
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
/api/v2/storefront/vendors
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
you can also include Vendor image and/or Products in that call:
|
|
107
|
+
|
|
108
|
+
`/api/v2/storefront/vendors?include=image,products`
|
|
109
|
+
|
|
110
|
+
|
|
100
111
|
And modfies existing:
|
|
101
112
|
|
|
102
113
|
1. `GET` Filtering Products by Vendor ID(s):
|
|
@@ -3,14 +3,14 @@ module Spree
|
|
|
3
3
|
class VendorsController < ResourceController
|
|
4
4
|
|
|
5
5
|
def create
|
|
6
|
-
if permitted_resource_params[:image]
|
|
6
|
+
if permitted_resource_params[:image]
|
|
7
7
|
@vendor.build_image(attachment: permitted_resource_params.delete(:image))
|
|
8
8
|
end
|
|
9
9
|
super
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def update
|
|
13
|
-
if permitted_resource_params[:image]
|
|
13
|
+
if permitted_resource_params[:image]
|
|
14
14
|
@vendor.create_image(attachment: permitted_resource_params.delete(:image))
|
|
15
15
|
end
|
|
16
16
|
format_translations if defined? SpreeGlobalize
|
|
@@ -40,10 +40,18 @@ module Spree
|
|
|
40
40
|
@search = vendors.ransack(params[:q])
|
|
41
41
|
|
|
42
42
|
@collection = @search.result.
|
|
43
|
+
includes(vendor_includes).
|
|
43
44
|
page(params[:page]).
|
|
44
45
|
per(params[:per_page])
|
|
45
46
|
end
|
|
46
47
|
|
|
48
|
+
def vendor_includes
|
|
49
|
+
{
|
|
50
|
+
image: [],
|
|
51
|
+
products: []
|
|
52
|
+
}
|
|
53
|
+
end
|
|
54
|
+
|
|
47
55
|
def format_translations
|
|
48
56
|
return if params[:vendor][:translations_attributes].blank?
|
|
49
57
|
params[:vendor][:translations_attributes].each do |_, data|
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
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
|
+
end
|
|
31
|
+
|
|
32
|
+
def update
|
|
33
|
+
@vendor = scope.find(params[:id])
|
|
34
|
+
authorize! :update, @vendor
|
|
35
|
+
if @vendor.update(vendor_params)
|
|
36
|
+
render :show
|
|
37
|
+
else
|
|
38
|
+
invalid_resource!(@vendor)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def destroy
|
|
43
|
+
@vendor = scope.find(params[:id])
|
|
44
|
+
authorize! :destroy, @vendor
|
|
45
|
+
@vendor.destroy
|
|
46
|
+
render plain: nil, status: 204
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
|
|
51
|
+
def scope
|
|
52
|
+
Spree::Vendor.accessible_by(current_ability)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def vendor_params
|
|
56
|
+
params.require(:vendor).permit(Spree::PermittedAttributes.vendor_attributes)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -3,7 +3,7 @@ module Spree
|
|
|
3
3
|
module V2
|
|
4
4
|
module Storefront
|
|
5
5
|
class VendorsController < ::Spree::Api::V2::ResourceController
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
private
|
|
8
8
|
|
|
9
9
|
def model_class
|
|
@@ -21,6 +21,11 @@ module Spree
|
|
|
21
21
|
def resource_serializer
|
|
22
22
|
Spree::V2::Storefront::VendorSerializer
|
|
23
23
|
end
|
|
24
|
+
|
|
25
|
+
def collection_serializer
|
|
26
|
+
Spree::V2::Storefront::VendorSerializer
|
|
27
|
+
end
|
|
28
|
+
|
|
24
29
|
end
|
|
25
30
|
end
|
|
26
31
|
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module SpreeMultiVendor::Spree::Api::BaseControllerDecorator
|
|
2
|
+
Spree::Api::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::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::V1::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::V1::UsersController.prepend SpreeMultiVendor::Spree::Api::V1::UsersControllerDecorator
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Api
|
|
3
|
+
module VendorHelper
|
|
4
|
+
def current_spree_vendor
|
|
5
|
+
if current_api_user.vendors.any? && (!current_api_user.respond_to?(:has_spree_role?) || !current_api_user.has_spree_role?(:admin))
|
|
6
|
+
current_api_user.vendors.first
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module SpreeMultiVendor
|
|
2
|
+
module Spree
|
|
3
|
+
module Api
|
|
4
|
+
module ApiHelpersDecorator
|
|
5
|
+
def self.prepended(base)
|
|
6
|
+
base::ATTRIBUTES.push(:vendor_attributes)
|
|
7
|
+
|
|
8
|
+
base.mattr_reader *base::ATTRIBUTES
|
|
9
|
+
|
|
10
|
+
base.user_attributes << :vendor_ids
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
@@vendor_attributes = [:id, :name, :slug, :state, :about_us, :contact_us]
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
::Spree::Api::ApiHelpers.prepend(SpreeMultiVendor::Spree::Api::ApiHelpersDecorator)
|
|
@@ -36,8 +36,21 @@ class Spree::VendorAbility
|
|
|
36
36
|
|
|
37
37
|
def apply_order_permissions
|
|
38
38
|
cannot :create, Spree::Order
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
|
|
40
|
+
order_scope = if ::Spree::Order.reflect_on_association(:vendor)
|
|
41
|
+
{ vendor_id: @vendor_ids }
|
|
42
|
+
elsif ::Spree::LineItem.reflect_on_association(:vendor)
|
|
43
|
+
{ line_items: { vendor_id: @vendor_ids } }
|
|
44
|
+
elsif ::Spree::Product.reflect_on_association(:vendor)
|
|
45
|
+
{ line_items: { product: { vendor_id: @vendor_ids } } }
|
|
46
|
+
elsif ::Spree::Variant.reflect_on_association(:vendor)
|
|
47
|
+
{ line_items: { variant: { vendor_id: @vendor_ids } } }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
if order_scope.present?
|
|
51
|
+
can %i[admin show index edit update cart], Spree::Order, order_scope.merge(state: 'complete')
|
|
52
|
+
else
|
|
53
|
+
cannot_display_model(Spree::Order)
|
|
41
54
|
end
|
|
42
55
|
end
|
|
43
56
|
|
|
@@ -51,9 +64,8 @@ class Spree::VendorAbility
|
|
|
51
64
|
end
|
|
52
65
|
|
|
53
66
|
def apply_option_type_permissions
|
|
54
|
-
|
|
55
|
-
can :
|
|
56
|
-
can :create, Spree::OptionType
|
|
67
|
+
can :display, Spree::OptionType
|
|
68
|
+
can :display, Spree::OptionValue
|
|
57
69
|
end
|
|
58
70
|
|
|
59
71
|
def apply_price_permissions
|
|
@@ -61,8 +73,6 @@ class Spree::VendorAbility
|
|
|
61
73
|
end
|
|
62
74
|
|
|
63
75
|
def apply_product_option_type_permissions
|
|
64
|
-
can :display, Spree::OptionType
|
|
65
|
-
can :display, Spree::OptionValue
|
|
66
76
|
can :manage, Spree::ProductOptionType, product: { vendor_id: @vendor_ids }
|
|
67
77
|
can :create, Spree::ProductOptionType
|
|
68
78
|
can :manage, Spree::OptionValueVariant, variant: { vendor_id: @vendor_ids }
|
|
@@ -71,6 +81,9 @@ class Spree::VendorAbility
|
|
|
71
81
|
|
|
72
82
|
def apply_product_permissions
|
|
73
83
|
cannot_display_model(Spree::Product)
|
|
84
|
+
|
|
85
|
+
return unless Spree::Product.reflect_on_association(:vendor)
|
|
86
|
+
|
|
74
87
|
can :manage, Spree::Product, vendor_id: @vendor_ids
|
|
75
88
|
can :create, Spree::Product
|
|
76
89
|
end
|
|
@@ -78,7 +91,7 @@ class Spree::VendorAbility
|
|
|
78
91
|
def apply_properties_permissions
|
|
79
92
|
can :display, Spree::Property
|
|
80
93
|
end
|
|
81
|
-
|
|
94
|
+
|
|
82
95
|
def apply_product_properties_permissions
|
|
83
96
|
can :manage, Spree::ProductProperty, product: { vendor_id: @vendor_ids }
|
|
84
97
|
can :create, Spree::ProductProperty
|
|
@@ -116,12 +129,14 @@ class Spree::VendorAbility
|
|
|
116
129
|
end
|
|
117
130
|
|
|
118
131
|
def apply_variant_permissions
|
|
132
|
+
cannot_display_model(Spree::Variant)
|
|
119
133
|
can :manage, Spree::Variant, vendor_id: @vendor_ids
|
|
120
134
|
can :create, Spree::Variant
|
|
121
135
|
end
|
|
122
136
|
|
|
123
137
|
def apply_vendor_permissions
|
|
124
|
-
can
|
|
138
|
+
can :manage, Spree::Vendor, id: @vendor_ids
|
|
139
|
+
cannot :create, Spree::Vendor
|
|
125
140
|
end
|
|
126
141
|
|
|
127
142
|
def apply_vendor_settings_permissions
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module Spree
|
|
2
2
|
class VendorUser < Spree::Base
|
|
3
3
|
belongs_to :vendor, class_name: 'Spree::Vendor', required: Spree.version.to_f >= 3.5
|
|
4
|
-
belongs_to :user, class_name: Spree.user_class.name, required: Spree.version.to_f >= 3.5
|
|
4
|
+
belongs_to :user, class_name: Spree.user_class.name, required: Spree.version.to_f >= 3.5, touch: true
|
|
5
5
|
|
|
6
6
|
validates :vendor_id, uniqueness: { scope: :user_id }
|
|
7
7
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
module SpreeMultiVendor
|
|
2
|
-
class Configuration < Spree::Preferences::Configuration
|
|
2
|
+
class Configuration < ::Spree::Preferences::Configuration
|
|
3
3
|
DEFAULT_VENDORIZED_MODELS ||= %w[product variant stock_location shipping_method].freeze
|
|
4
4
|
|
|
5
5
|
# Some example preferences are shown below, for more information visit:
|
|
@@ -22,7 +22,9 @@ module SpreeMultiVendor::Spree::OrderDecorator
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
def vendor_subtotal(vendor)
|
|
25
|
-
|
|
25
|
+
vendor_pre_tax_item_amount(vendor) +
|
|
26
|
+
vendor_pre_tax_ship_amount(vendor) +
|
|
27
|
+
vendor_additional_tax_total(vendor)
|
|
26
28
|
end
|
|
27
29
|
|
|
28
30
|
def vendor_promo_total(vendor)
|
|
@@ -66,7 +68,7 @@ module SpreeMultiVendor::Spree::OrderDecorator
|
|
|
66
68
|
end
|
|
67
69
|
|
|
68
70
|
# money methods
|
|
69
|
-
METHOD_NAMES
|
|
71
|
+
METHOD_NAMES ||= %w[
|
|
70
72
|
total ship_total subtotal included_tax_total additional_tax_total promo_total
|
|
71
73
|
pre_tax_item_amount pre_tax_ship_amount pre_tax_total commission
|
|
72
74
|
].freeze
|
|
@@ -102,4 +104,4 @@ module SpreeMultiVendor::Spree::OrderDecorator
|
|
|
102
104
|
end
|
|
103
105
|
end
|
|
104
106
|
|
|
105
|
-
Spree::Order.prepend SpreeMultiVendor::Spree::OrderDecorator
|
|
107
|
+
Spree::Order.prepend SpreeMultiVendor::Spree::OrderDecorator unless Spree::Order.included_modules.include?(SpreeMultiVendor::Spree::OrderDecorator)
|
|
@@ -2,7 +2,7 @@ Deface::Override.new(
|
|
|
2
2
|
virtual_path: 'spree/admin/shared/_main_menu',
|
|
3
3
|
name: 'Display configuration tab for vendors',
|
|
4
4
|
replace: 'erb[silent]:contains("current_store")',
|
|
5
|
-
text: '<% if can?(:admin, current_store) || current_spree_user
|
|
5
|
+
text: '<% if can?(:admin, current_store) || current_spree_user&.vendors&.any? %>'
|
|
6
6
|
)
|
|
7
7
|
Deface::Override.new(
|
|
8
8
|
virtual_path: 'spree/admin/shared/_main_menu',
|
|
@@ -4,6 +4,8 @@ module Spree
|
|
|
4
4
|
class VendorOrderTotalsSerializer < BaseSerializer
|
|
5
5
|
set_type :vendor_totals
|
|
6
6
|
|
|
7
|
+
cache_options store: nil
|
|
8
|
+
|
|
7
9
|
attributes :name, :subtotal, :ship_total, :total, :display_subtotal,
|
|
8
10
|
:display_ship_total, :display_total, :promo_total,
|
|
9
11
|
:display_promo_total, :included_tax_total,
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
<%= form_for [:admin, @vendor], url: admin_vendor_settings_url do |f| %>
|
|
6
6
|
<fieldset>
|
|
7
|
-
<%= render partial: 'spree/shared/error_messages', locals: { target: @vendor } %>
|
|
7
|
+
<%= render partial: 'spree/admin/shared/error_messages', locals: { target: @vendor } %>
|
|
8
8
|
<div class="form-group">
|
|
9
9
|
<%= f.field_container :name do %>
|
|
10
10
|
<%= f.label :name %>
|
|
@@ -6,5 +6,7 @@ module Spree
|
|
|
6
6
|
|
|
7
7
|
@@vendor_attributes = [:name, :about_us, :contact_us, :notification_email]
|
|
8
8
|
@@vendor_attributes << :image if Spree.version.to_f >= 3.6
|
|
9
|
+
|
|
10
|
+
@@product_attributes << :vendor_id if SpreeMultiVendor::Config[:vendorized_models].include?('product')
|
|
9
11
|
end
|
|
10
12
|
end
|
data/config/locales/es.yml
CHANGED
|
@@ -7,9 +7,11 @@ es:
|
|
|
7
7
|
attributes:
|
|
8
8
|
spree/vendor:
|
|
9
9
|
about_us: Acerca de
|
|
10
|
+
commission_rate: Porcentaje Comisión
|
|
10
11
|
contact_us: Contáctanos
|
|
11
12
|
image: Imagen
|
|
12
13
|
name: Nombre
|
|
14
|
+
notification_email: Email notificación pedido
|
|
13
15
|
state: estado
|
|
14
16
|
created_at: creado en
|
|
15
17
|
priority: prioridad
|
|
@@ -21,6 +23,7 @@ es:
|
|
|
21
23
|
order_mailer:
|
|
22
24
|
vendor_notification_email:
|
|
23
25
|
dear_vendor: Estimado vendedor,
|
|
26
|
+
order_summary: Resumen del pedido
|
|
24
27
|
subject: Notificación de vendedor
|
|
25
28
|
thanks: Gracias
|
|
26
29
|
vendor: Vendedor
|
data/config/routes.rb
CHANGED
|
@@ -12,8 +12,11 @@ Spree::Core::Engine.routes.draw do
|
|
|
12
12
|
namespace :api, defaults: { format: 'json' } do
|
|
13
13
|
namespace :v2 do
|
|
14
14
|
namespace :storefront do
|
|
15
|
-
resources :vendors, only: [:show]
|
|
15
|
+
resources :vendors, only: [:show,:index]
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
|
+
namespace :v1 do
|
|
19
|
+
resources :vendors
|
|
20
|
+
end
|
|
18
21
|
end
|
|
19
22
|
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
class ChangeVendorizedModelsVendorIdType < ActiveRecord::Migration[4.2]
|
|
2
|
+
def change
|
|
3
|
+
SpreeMultiVendor.vendorized_models.each do |klass|
|
|
4
|
+
change_column klass.table_name, :vendor_id, :bigint
|
|
5
|
+
rescue
|
|
6
|
+
message = "Could not change vendor_id column for spree_#{klass}"
|
|
7
|
+
Rails.logger.error message
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
data/lib/spree_multi_vendor.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'spree_core'
|
|
2
|
+
require 'spree_backend'
|
|
2
3
|
require 'spree_multi_vendor/engine'
|
|
3
4
|
require 'spree_multi_vendor/version'
|
|
4
5
|
require 'spree_extension'
|
|
@@ -8,7 +9,7 @@ module SpreeMultiVendor
|
|
|
8
9
|
# TODO: this should be moved into preferences
|
|
9
10
|
def self.vendorized_models
|
|
10
11
|
SpreeMultiVendor::Config[:vendorized_models].map(&:classify).map do |class_name|
|
|
11
|
-
"Spree::#{class_name}".safe_constantize
|
|
12
|
+
"::Spree::#{class_name}".safe_constantize
|
|
12
13
|
end.compact.uniq
|
|
13
14
|
end
|
|
14
15
|
end
|
|
@@ -9,6 +9,12 @@ FactoryBot.define do
|
|
|
9
9
|
state { :active }
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
+
factory :active_vendor_list do
|
|
13
|
+
name { "#{FFaker::Company.name} #{FFaker::Company.suffix }" }
|
|
14
|
+
state { :active }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
|
|
12
18
|
factory :pending_vendor do
|
|
13
19
|
name { 'Pending vendor' }
|
|
14
20
|
state { :pending }
|