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.
Files changed (134) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +10 -0
  3. data/LICENSE +26 -0
  4. data/README.md +181 -0
  5. data/Rakefile +21 -0
  6. data/app/controllers/spree/admin/vendor_settings_controller.rb +34 -0
  7. data/app/controllers/spree/admin/vendors_controller.rb +68 -0
  8. data/app/controllers/spree/api/v1/vendors_controller.rb +62 -0
  9. data/app/controllers/spree/api/v2/platform/vendors_controller.rb +32 -0
  10. data/app/controllers/spree/api/v2/storefront/vendors_controller.rb +33 -0
  11. data/app/controllers/spree_multi_vendor/spree/admin/base_controller_decorator.rb +10 -0
  12. data/app/controllers/spree_multi_vendor/spree/admin/products_controller_decorator.rb +79 -0
  13. data/app/controllers/spree_multi_vendor/spree/admin/resource_controller_decorator.rb +8 -0
  14. data/app/controllers/spree_multi_vendor/spree/admin/shipping_methods_controller_decorator.rb +7 -0
  15. data/app/controllers/spree_multi_vendor/spree/admin/stock_locations_controller_decorator.rb +7 -0
  16. data/app/controllers/spree_multi_vendor/spree/admin/users_controller_decorator.rb +13 -0
  17. data/app/controllers/spree_multi_vendor/spree/admin/variants_controller_decorator.rb +7 -0
  18. data/app/controllers/spree_multi_vendor/spree/api/base_controller_decorator.rb +17 -0
  19. data/app/controllers/spree_multi_vendor/spree/api/v1/products_controller_decorator.rb +9 -0
  20. data/app/controllers/spree_multi_vendor/spree/api/v1/users_controller_decorator.rb +13 -0
  21. data/app/controllers/spree_multi_vendor/spree/api/v2/platform/products_controller_decorator.rb +65 -0
  22. data/app/finders/spree_multi_vendor/products_finder_decorator.rb +31 -0
  23. data/app/helpers/spree/admin/vendor_helper.rb +15 -0
  24. data/app/helpers/spree/api/vendor_helper.rb +13 -0
  25. data/app/helpers/spree_multi_vendor/spree/api/api_helpers_decorator.rb +19 -0
  26. data/app/mailers/spree/vendor_mailer.rb +15 -0
  27. data/app/models/concerns/spree/vendor_concern.rb +11 -0
  28. data/app/models/spree/order_commission.rb +11 -0
  29. data/app/models/spree/vendor.rb +77 -0
  30. data/app/models/spree/vendor_ability.rb +155 -0
  31. data/app/models/spree/vendor_image.rb +18 -0
  32. data/app/models/spree/vendor_order_totals.rb +28 -0
  33. data/app/models/spree/vendor_user.rb +16 -0
  34. data/app/models/spree_multi_vendor/configuration.rb +10 -0
  35. data/app/models/spree_multi_vendor/spree/ability_decorator.rb +9 -0
  36. data/app/models/spree_multi_vendor/spree/base_decorator.rb +13 -0
  37. data/app/models/spree_multi_vendor/spree/line_item_decorator.rb +48 -0
  38. data/app/models/spree_multi_vendor/spree/order_decorator.rb +107 -0
  39. data/app/models/spree_multi_vendor/spree/shipment_decorator.rb +8 -0
  40. data/app/models/spree_multi_vendor/spree/stock/package_decorator.rb +14 -0
  41. data/app/models/spree_multi_vendor/spree/user_decorator.rb +8 -0
  42. data/app/models/spree_multi_vendor/spree/variant_decorator.rb +40 -0
  43. data/app/overrides/spree/admin/orders/_form.rb +13 -0
  44. data/app/overrides/spree/admin/orders/_line_items.rb +6 -0
  45. data/app/overrides/spree/admin/orders/_line_items_edit_form.rb +6 -0
  46. data/app/overrides/spree/admin/orders/index.rb +6 -0
  47. data/app/overrides/spree/admin/products/form.rb +29 -0
  48. data/app/overrides/spree/admin/products/new.rb +16 -0
  49. data/app/overrides/spree/admin/shared/_main_menu.rb +23 -0
  50. data/app/overrides/spree/admin/shared/_order_summary.rb +35 -0
  51. data/app/overrides/spree/admin/users/_form.rb +13 -0
  52. data/app/serializers/spree/api/v2/platform/vendor_serializer.rb +12 -0
  53. data/app/serializers/spree/v2/storefront/vendor_image_serializer.rb +11 -0
  54. data/app/serializers/spree/v2/storefront/vendor_order_totals_serializer.rb +20 -0
  55. data/app/serializers/spree/v2/storefront/vendor_serializer.rb +15 -0
  56. data/app/serializers/spree_multi_vendor/cart_serializer_decorator.rb +19 -0
  57. data/app/serializers/spree_multi_vendor/serializer_decorator.rb +23 -0
  58. data/app/services/spree/orders/generate_commissions.rb +34 -0
  59. data/app/views/spree/admin/translations/vendor.html.erb +21 -0
  60. data/app/views/spree/admin/vendor_settings/edit.html.erb +47 -0
  61. data/app/views/spree/admin/vendors/_form.html.erb +36 -0
  62. data/app/views/spree/admin/vendors/edit.html.erb +11 -0
  63. data/app/views/spree/admin/vendors/index.html.erb +83 -0
  64. data/app/views/spree/admin/vendors/new.html.erb +11 -0
  65. data/app/views/spree/api/v1/vendors/index.rabl +3 -0
  66. data/app/views/spree/api/v1/vendors/show.rabl +2 -0
  67. data/app/views/spree/vendor_mailer/vendor_notification_email.html.erb +81 -0
  68. data/app/views/spree/vendor_mailer/vendor_notification_email.text.erb +36 -0
  69. data/bin/rails +7 -0
  70. data/config/initializers/spree.rb +31 -0
  71. data/config/initializers/spree_permitted_attributes.rb +12 -0
  72. data/config/locales/en.yml +34 -0
  73. data/config/locales/es.yml +36 -0
  74. data/config/locales/fr.yml +33 -0
  75. data/config/routes.rb +29 -0
  76. data/db/default/vendors.rb +13 -0
  77. data/db/migrate/20170406102250_create_spree_vendors.rb +9 -0
  78. data/db/migrate/20170406102944_add_vendor_id_to_spree_models.rb +10 -0
  79. data/db/migrate/20170410111150_add_state_to_vendors.rb +6 -0
  80. data/db/migrate/20170412124925_add_deleted_at_to_spree_vendors.rb +6 -0
  81. data/db/migrate/20170413094447_create_spree_vendor_users.rb +11 -0
  82. data/db/migrate/20190212161426_add_slug_to_spree_vendors.rb +6 -0
  83. data/db/migrate/20190214120226_add_about_us_to_spree_vendors.rb +5 -0
  84. data/db/migrate/20190214142526_add_contact_us_to_spree_vendors.rb +5 -0
  85. data/db/migrate/20190305120337_add_commission_to_spree_vendors.rb +5 -0
  86. data/db/migrate/20190308091546_add_priority_to_vendor.rb +8 -0
  87. data/db/migrate/20190312130754_create_spree_order_commissions.rb +14 -0
  88. data/db/migrate/20190322133128_add_notification_email_to_vendors.rb +5 -0
  89. data/db/migrate/20200416030721_add_translations_to_vendor.rb +19 -0
  90. data/db/migrate/20210728120649_change_vendorized_models_vendor_id_type.rb +10 -0
  91. data/db/migrate/20210728120910_change_vendor_id_and_user_id_type_for_spree_vendor_users.rb +14 -0
  92. data/db/migrate/20210728121024_change_vendor_id_and_order_id_type_for_spree_order_commissions.rb +14 -0
  93. data/db/migrate/20221123095256_add_code_to_vendors.rb +6 -0
  94. data/lib/generators/spree_multi_vendor/install/install_generator.rb +21 -0
  95. data/lib/generators/spree_multi_vendor/mailers_preview/mailers_preview_generator.rb +22 -0
  96. data/lib/generators/spree_multi_vendor/mailers_preview/templates/mailers/previews/vendor_notification_preview.rb +5 -0
  97. data/lib/spree_multi_vendor/engine.rb +24 -0
  98. data/lib/spree_multi_vendor/factories.rb +7 -0
  99. data/lib/spree_multi_vendor/version.rb +11 -0
  100. data/lib/spree_multi_vendor.rb +16 -0
  101. data/lib/tasks/vendors.rake +8 -0
  102. data/spec/factories/spree/vendor_factory.rb +28 -0
  103. data/spec/factories/spree/vendor_image_factory.rb +5 -0
  104. data/spec/factories/spree/vendor_user_factory.rb +6 -0
  105. data/spec/features/spree/admin/orders_spec.rb +86 -0
  106. data/spec/features/spree/admin/product_spec.rb +177 -0
  107. data/spec/features/spree/admin/shipping_method_spec.rb +72 -0
  108. data/spec/features/spree/admin/stock_location_spec.rb +90 -0
  109. data/spec/features/spree/admin/vendor_settings_spec.rb +74 -0
  110. data/spec/features/spree/admin/vendor_spec.rb +125 -0
  111. data/spec/fixtures/thinking-cat.jpg +0 -0
  112. data/spec/mailers/vendor_mailer_spec.rb +45 -0
  113. data/spec/models/spree/line_item_spec.rb +32 -0
  114. data/spec/models/spree/order_commission_spec.rb +8 -0
  115. data/spec/models/spree/order_spec.rb +193 -0
  116. data/spec/models/spree/product_spec.rb +19 -0
  117. data/spec/models/spree/variant_spec.rb +104 -0
  118. data/spec/models/spree/vendor_order_totals_spec.rb +33 -0
  119. data/spec/models/spree/vendor_spec.rb +57 -0
  120. data/spec/models/spree/vendor_user_spec.rb +12 -0
  121. data/spec/requests/spree/api/v1/products_spec.rb +221 -0
  122. data/spec/requests/spree/api/v1/users_spec.rb +31 -0
  123. data/spec/requests/spree/api/v1/vendors_spec.rb +210 -0
  124. data/spec/requests/spree/api/v2/storefront/cart_spec.rb +85 -0
  125. data/spec/requests/spree/api/v2/storefront/products_spec.rb +96 -0
  126. data/spec/requests/spree/api/v2/storefront/vendors_spec.rb +118 -0
  127. data/spec/serializers/spree/v2/storefront/stock_location_serializer_spec.rb +32 -0
  128. data/spec/serializers/spree/v2/storefront/vendor_image_serializer_spec.rb +18 -0
  129. data/spec/serializers/spree/v2/storefront/vendor_order_totals_serializer_spec.rb +54 -0
  130. data/spec/serializers/spree/v2/storefront/vendor_serializer_spec.rb +34 -0
  131. data/spec/spec_helper.rb +13 -0
  132. data/spec/support/shoulda_matchers.rb +6 -0
  133. data/spree_multi_vendor.gemspec +42 -0
  134. metadata +308 -0
@@ -0,0 +1,81 @@
1
+ <table class="row header">
2
+ <tr>
3
+ <td>
4
+ <p class="lede">
5
+ <%= Spree.t('order_mailer.vendor_notification_email.dear_vendor') %>
6
+ </p>
7
+ <p>
8
+ <%= Spree.t('order_mailer.vendor_notification_email.order_summary', number: @order.number) %>
9
+ </p>
10
+ <table class="container">
11
+ <tr>
12
+ <td class="wrapper last">
13
+ <table class="twelve columns">
14
+ <%= render collection: @line_items, partial: 'spree/shared/mailer_line_item', as: :line_item %>
15
+ <tr>
16
+ <td class="six sub-columns">
17
+ <%= Spree.t('order_mailer.subtotal') %>
18
+ </td>
19
+ <td class="six sub-columns last right">
20
+ <%= Spree::Money.new(@subtotal, currency: @order.currency) %>
21
+ </td>
22
+ </tr>
23
+ <% if @order.line_item_adjustments.exists? %>
24
+ <% if @order.all_adjustments.promotion.eligible.exists? %>
25
+ <% @order.all_adjustments.promotion.eligible.group_by(&:label).each do |label, adjustments| %>
26
+ <tr>
27
+ <td class="six sub-columns">
28
+ <%= Spree.t(:promotion) %> <%= label %>:
29
+ </td>
30
+ <td class="six sub-columns last right">
31
+ <%= Spree::Money.new(adjustments.sum(&:amount), currency: @order.currency) %>
32
+ </td>
33
+ </tr>
34
+ <% end %>
35
+ <% end %>
36
+ <% end %>
37
+ <% @order.shipments.for_vendor(@vendor).group_by { |s| s.selected_shipping_rate.try(:name) }.each do |name, shipments| %>
38
+ <tr>
39
+ <td class="six sub-columns">
40
+ <%= Spree.t(:shipping) %> <%= name %>:
41
+ </td>
42
+ <td class="six sub-columns last right">
43
+ <%= Spree::Money.new(shipments.sum(&:discounted_cost), currency: @order.currency) %>
44
+ </td>
45
+ </tr>
46
+ <% end %>
47
+ <% if @order.all_adjustments.eligible.tax.exists? %>
48
+ <% @order.all_adjustments.eligible.tax.group_by(&:label).each do |label, adjustments| %>
49
+ <tr>
50
+ <td class="six sub-columns">
51
+ <%= Spree.t(:tax) %> <%= label %>:
52
+ </td>
53
+ <td class="six sub-columns last right">
54
+ <%= Spree::Money.new(adjustments.sum(&:amount), currency: @order.currency) %>
55
+ </td>
56
+ </tr>
57
+ <% end %>
58
+ <% end %>
59
+ <% @order.adjustments.eligible.each do |adjustment| %>
60
+ <% next if (adjustment.source_type == 'Spree::TaxRate') || (adjustment.amount == 0) %>
61
+ <%= render 'spree/order_mailer/adjustment', adjustment: adjustment %>
62
+ <% end %>
63
+ <tr>
64
+ <td class="six sub-columns">
65
+ <strong><%= Spree.t('order_mailer.total') %></strong>
66
+ </td>
67
+ <td class="six sub-columns last right">
68
+ <strong><%= Spree::Money.new(@total, currency: @order.currency) %></strong>
69
+ </td>
70
+ </tr>
71
+ </table>
72
+ </td>
73
+ </tr>
74
+ </table>
75
+ <p>
76
+ <%= Spree.t('order_mailer.vendor_notification_email.thanks') %>
77
+ </p>
78
+ </td>
79
+ <td class="expander"></td>
80
+ </tr>
81
+ </table>
@@ -0,0 +1,36 @@
1
+ <%= Spree.t('order_mailer.vendor_notification_email.dear_vendor') %>
2
+
3
+ ============================================================
4
+ <%= Spree.t('order_mailer.vendor_notification_email.order_summary', number: @order.number) %>
5
+ ============================================================
6
+ <% @line_items.each do |item| %>
7
+ <%= item.variant.sku %> <%= raw(item.variant.product.name) %> <%= raw(item.variant.options_text) -%> (<%=item.quantity%>) <%= Spree.t('at_symbol') %> <%= item.single_money %> = <%= item.display_amount %>
8
+ <% end %>
9
+ ============================================================
10
+ <%= Spree.t('order_mailer.subtotal') %> <%= Spree::Money.new(@subtotal, currency: @order.currency) %>
11
+ <% if @order.line_item_adjustments.exists? %>
12
+ <% if @order.all_adjustments.promotion.eligible.exists? %>
13
+ <% @order.all_adjustments.promotion.eligible.group_by(&:label).each do |label, adjustments| %>
14
+ <%= Spree.t(:promotion) %>: <%= label %> <%= Spree::Money.new(adjustments.sum(&:amount), currency: @order.currency) %>
15
+ <% end %>
16
+ <% end %>
17
+ <% end %>
18
+
19
+ <% @order.shipments.group_by { |s| s.selected_shipping_rate.try(:name) }.each do |name, shipments| %>
20
+ <%= Spree.t(:shipping) %>: <%= name %> <%= Spree::Money.new(shipments.sum(&:discounted_cost), currency: @order.currency) %>
21
+ <% end %>
22
+
23
+ <% if @order.all_adjustments.eligible.tax.exists? %>
24
+ <% @order.all_adjustments.eligible.tax.group_by(&:label).each do |label, adjustments| %>
25
+ <%= Spree.t(:tax) %>: <%= label %> <%= Spree::Money.new(adjustments.sum(&:amount), currency: @order.currency) %>
26
+ <% end %>
27
+ <% end %>
28
+
29
+ <% @order.adjustments.eligible.each do |adjustment| %>
30
+ <% next if (adjustment.source_type == 'Spree::TaxRate') and (adjustment.amount == 0) %>
31
+ <%= adjustment.label %> <%= adjustment.display_amount %>
32
+ <% end %>
33
+ ============================================================
34
+ <%= Spree.t('order_mailer.total') %> <%= Spree::Money.new(@total, currency: @order.currency) %>
35
+
36
+ <%= Spree.t('order_mailer.vendor_notification_email.thanks') %>
data/bin/rails ADDED
@@ -0,0 +1,7 @@
1
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
2
+
3
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
4
+ ENGINE_PATH = File.expand_path('../../lib/spree_multi_vendor/engine', __FILE__)
5
+
6
+ require 'rails/all'
7
+ require 'rails/engine/commands'
@@ -0,0 +1,31 @@
1
+ # Configure Spree Preferences
2
+ #
3
+ # Note: Initializing preferences available within the Admin will overwrite any changes that were made through the user interface when you restart.
4
+ # If you would like users to be able to update a setting with the Admin it should NOT be set here.
5
+ #
6
+ # Note: If a preference is set here it will be stored within the cache & database upon initialization.
7
+ # Just removing an entry from this initializer will not make the preference value go away.
8
+ # Instead you must either set a new value or remove entry, clear cache, and remove database entry.
9
+ #
10
+ # In order to initialize a setting do:
11
+ # config.setting_name = 'new value'
12
+ Spree.config do |config|
13
+ # Example:
14
+ # Uncomment to stop tracking inventory levels in the application
15
+ # config.track_inventory_levels = false
16
+ end
17
+
18
+ # Configure Spree Dependencies
19
+ #
20
+ # Note: If a dependency is set here it will NOT be stored within the cache & database upon initialization.
21
+ # Just removing an entry from this initializer will make the dependency value go away.
22
+ #
23
+ Spree.dependencies do |dependencies|
24
+ # Example:
25
+ # Uncomment to change the default Service handling adding Items to Cart
26
+ # dependencies.cart_add_item_service = 'MyNewAwesomeService'
27
+ end
28
+
29
+ # Spree::Api::Dependencies.storefront_cart_serializer = 'MyRailsApp::CartSerializer'
30
+
31
+ Spree.user_class = "Spree::LegacyUser"
@@ -0,0 +1,12 @@
1
+ module Spree
2
+ module PermittedAttributes
3
+ ATTRIBUTES << :vendor_attributes
4
+
5
+ mattr_reader *ATTRIBUTES
6
+
7
+ @@vendor_attributes = [:name, :about_us, :contact_us, :notification_email, :code]
8
+ @@vendor_attributes << :image if Spree.version.to_f >= 3.6
9
+
10
+ @@product_attributes << :vendor_id if SpreeMultiVendor::Config[:vendorized_models].include?('product')
11
+ end
12
+ end
@@ -0,0 +1,34 @@
1
+ en:
2
+ activerecord:
3
+ models:
4
+ spree/vendor:
5
+ one: Vendor
6
+ other: Vendors
7
+ attributes:
8
+ spree/vendor:
9
+ about_us: About us
10
+ contact_us: Contact us
11
+ image: Image
12
+ name: name
13
+ state: state
14
+ created_at: created at
15
+ priority: priority
16
+ spree:
17
+ back_to_vendors_list: Back To Vendors List
18
+ blocked: Blocked
19
+ edit_vendor: Edit Vendor
20
+ new_vendor: New Vendor
21
+ only_alphanumeric_chars: should contain only letters and digits
22
+ order_mailer:
23
+ vendor_notification_email:
24
+ dear_vendor: Dear Vendor,
25
+ subject: Vendor notification
26
+ thanks: Thanks
27
+ vendor: Vendor
28
+ vendor_name: Vendor Name
29
+ vendor_states:
30
+ active: Active
31
+ blocked: Blocked
32
+ pending: Pending
33
+ admin:
34
+ commission: Commission
@@ -0,0 +1,36 @@
1
+ es:
2
+ activerecord:
3
+ models:
4
+ spree/vendor:
5
+ one: Vendedor
6
+ other: Vendedores
7
+ attributes:
8
+ spree/vendor:
9
+ about_us: Acerca de
10
+ commission_rate: Porcentaje Comisión
11
+ contact_us: Contáctanos
12
+ image: Imagen
13
+ name: Nombre
14
+ notification_email: Email notificación pedido
15
+ state: estado
16
+ created_at: creado en
17
+ priority: prioridad
18
+ spree:
19
+ back_to_vendors_list: Volver a la lista de vendedores
20
+ edit_vendor: Editar vendedor
21
+ new_vendor: Nuevo vendedor
22
+ only_alphanumeric_chars: Debería contener solo letras y dígitos
23
+ order_mailer:
24
+ vendor_notification_email:
25
+ dear_vendor: Estimado vendedor,
26
+ order_summary: Resumen del pedido
27
+ subject: Notificación de vendedor
28
+ thanks: Gracias
29
+ vendor: Vendedor
30
+ vendor_name: Nombre del vendedor
31
+ vendor_states:
32
+ active: Activo
33
+ blocked: Bloqueado
34
+ pending: Pendiente
35
+ admin:
36
+ commission: Comisión
@@ -0,0 +1,33 @@
1
+ fr:
2
+ activerecord:
3
+ models:
4
+ spree/vendor:
5
+ one: Vendeur
6
+ other: Vendeurs
7
+ attributes:
8
+ spree/vendor:
9
+ about_us: A propos
10
+ contact_us: Contact
11
+ image: Image
12
+ name: Nom
13
+ state: Status
14
+ created_at: créé le
15
+ priority: priorité
16
+ spree:
17
+ back_to_vendors_list: Retour à la liste des vendeurs
18
+ edit_vendor: Modifier vendeur
19
+ new_vendor: Nouveau vendeur
20
+ only_alphanumeric_chars: ne doit contenir que des caractères alphanumériques
21
+ order_mailer:
22
+ vendor_notification_email:
23
+ dear_vendor: Cher vendeur,
24
+ subject: Notification vendeur
25
+ thanks: Merci
26
+ vendor: Vendeur
27
+ vendor_name: Nom du vendeur
28
+ vendor_states:
29
+ active: Actif
30
+ blocked: Bloqué
31
+ pending: En attente
32
+ admin:
33
+ commission: Commission
data/config/routes.rb ADDED
@@ -0,0 +1,29 @@
1
+ Spree::Core::Engine.routes.draw do
2
+ namespace :admin do
3
+ resources :vendors do
4
+ collection do
5
+ post :update_positions
6
+ end
7
+ end
8
+ get 'vendor_settings' => 'vendor_settings#edit'
9
+ patch 'vendor_settings' => 'vendor_settings#update'
10
+ end
11
+
12
+ namespace :api, defaults: { format: 'json' } do
13
+ namespace :v2 do
14
+ namespace :storefront do
15
+ resources :vendors, only: [:show,:index]
16
+ end
17
+ end
18
+
19
+ namespace :v2 do
20
+ namespace :platform do
21
+ resources :vendors
22
+ end
23
+ end
24
+
25
+ namespace :v1 do
26
+ resources :vendors
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,13 @@
1
+ vendor = Spree::Vendor.first_or_initialize do |v|
2
+ v.name = 'Test Vendor'
3
+ end
4
+ vendor.save!
5
+
6
+ puts "Created Vendor with the name \"#{vendor.name}\"!"
7
+
8
+ user = Spree.user_class.where(email: 'user@vendor.com').first_or_initialize do |u|
9
+ u.password = u.password_confirmation = 'vendor123'
10
+ end
11
+
12
+ vendor.users << user unless vendor.users.include?(user)
13
+ puts "Created Vendor Admin User with an email \"#{user.email}\" and password \"#{user.password}\"!"
@@ -0,0 +1,9 @@
1
+ class CreateSpreeVendors < SpreeExtension::Migration[4.2]
2
+ def change
3
+ create_table :spree_vendors do |t|
4
+ t.string :name
5
+ t.timestamps
6
+ end
7
+ add_index :spree_vendors, :name, unique: true
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ class AddVendorIdToSpreeModels < SpreeExtension::Migration[4.2]
2
+ def change
3
+ SpreeMultiVendor.vendorized_models.each do |klass|
4
+ add_reference klass.table_name, :vendor, index: true
5
+ rescue
6
+ message = "Could not add vendor_id column to spree_#{klass}"
7
+ Rails.logger.error message
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ class AddStateToVendors < SpreeExtension::Migration[4.2]
2
+ def change
3
+ add_column :spree_vendors, :state, :string
4
+ add_index :spree_vendors, :state
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ class AddDeletedAtToSpreeVendors < SpreeExtension::Migration[4.2]
2
+ def change
3
+ add_column :spree_vendors, :deleted_at, :datetime
4
+ add_index :spree_vendors, :deleted_at
5
+ end
6
+ end
@@ -0,0 +1,11 @@
1
+ class CreateSpreeVendorUsers < SpreeExtension::Migration[4.2]
2
+ def change
3
+ create_table :spree_vendor_users do |t|
4
+ t.references :vendor
5
+ t.references :user
6
+ end
7
+ add_index :spree_vendor_users, [:vendor_id, :user_id], unique: true
8
+ add_index :spree_vendor_users, :vendor_id
9
+ add_index :spree_vendor_users, :user_id
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ class AddSlugToSpreeVendors < SpreeExtension::Migration[4.2]
2
+ def change
3
+ add_column :spree_vendors, :slug, :string
4
+ add_index :spree_vendors, :slug, unique: true
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ class AddAboutUsToSpreeVendors < SpreeExtension::Migration[4.2]
2
+ def change
3
+ add_column :spree_vendors, :about_us, :text
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddContactUsToSpreeVendors < SpreeExtension::Migration[4.2]
2
+ def change
3
+ add_column :spree_vendors, :contact_us, :text
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddCommissionToSpreeVendors < SpreeExtension::Migration[4.2]
2
+ def change
3
+ add_column :spree_vendors, :commission_rate, :float, default: '5.0'
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ class AddPriorityToVendor < SpreeExtension::Migration[4.2]
2
+ def change
3
+ add_column :spree_vendors, :priority, :integer
4
+ Spree::Vendor.order(:updated_at).each.with_index(1) do |vendor, index|
5
+ vendor.update_column :priority, index
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,14 @@
1
+ class CreateSpreeOrderCommissions < SpreeExtension::Migration[4.2]
2
+ def change
3
+ create_table :spree_order_commissions do |t|
4
+ t.references :order
5
+ t.references :vendor
6
+ t.float :amount
7
+
8
+ t.timestamps
9
+ end
10
+ add_index :spree_order_commissions, [:order_id, :vendor_id], unique: true
11
+ add_index :spree_order_commissions, :order_id
12
+ add_index :spree_order_commissions, :vendor_id
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ class AddNotificationEmailToVendors < SpreeExtension::Migration[4.2]
2
+ def change
3
+ add_column :spree_vendors, :notification_email, :string
4
+ end
5
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Based on issue https://github.com/spree-contrib/spree_multi_vendor/issues/104
4
+ # This is a patch for Spree globalize to be friendly with the gem
5
+
6
+ class AddTranslationsToVendor < ActiveRecord::Migration[4.2]
7
+ def up
8
+ params = { name: :string, about_us: :text, contact_us: :text, slug: :string }
9
+ if defined?(SpreeGlobalize)
10
+ Spree::Vendor.create_translation_table!(params, { migrate_data: true })
11
+ end
12
+ end
13
+
14
+ def down
15
+ if defined?(SpreeGlobalize)
16
+ Spree::Vendor.drop_translation_table! migrate_data: true
17
+ end
18
+ end
19
+ 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
@@ -0,0 +1,14 @@
1
+ class ChangeVendorIdAndUserIdTypeForSpreeVendorUsers < ActiveRecord::Migration[4.2]
2
+ def up
3
+ change_table(:spree_vendor_users) do |t|
4
+ t.change :vendor_id, :bigint
5
+ t.change :user_id, :bigint
6
+ end
7
+ end
8
+ def down
9
+ change_table(:spree_vendor_users) do |t|
10
+ t.change :vendor_id, :integer
11
+ t.change :user_id, :integer
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ class ChangeVendorIdAndOrderIdTypeForSpreeOrderCommissions < ActiveRecord::Migration[4.2]
2
+ def up
3
+ change_table(:spree_order_commissions) do |t|
4
+ t.change :vendor_id, :bigint
5
+ t.change :order_id, :bigint
6
+ end
7
+ end
8
+ def down
9
+ change_table(:spree_order_commissions) do |t|
10
+ t.change :vendor_id, :integer
11
+ t.change :order_id, :integer
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,6 @@
1
+ class AddCodeToVendors < ActiveRecord::Migration[6.1]
2
+ def change
3
+ add_column :spree_vendors, :code, :string
4
+ add_index :spree_vendors, :code, unique: true
5
+ end
6
+ end
@@ -0,0 +1,21 @@
1
+ module SpreeMultiVendor
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+
5
+ class_option :auto_run_migrations, type: :boolean, default: false
6
+
7
+ def add_migrations
8
+ run 'bundle exec rake railties:install:migrations FROM=spree_multi_vendor'
9
+ end
10
+
11
+ def run_migrations
12
+ run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask 'Would you like to run the migrations now? [Y/n]')
13
+ if run_migrations
14
+ run 'bundle exec rake db:migrate'
15
+ else
16
+ puts 'Skipping rake db:migrate, don\'t forget to run it!'
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ require 'rails/generators'
2
+ require 'spree/core'
3
+
4
+ module SpreeMultiVendor
5
+ module Generators
6
+ class MailersPreviewGenerator < Rails::Generators::Base
7
+ desc 'Generates mailers preview for development proposes'
8
+
9
+ def self.source_paths
10
+ [
11
+ File.expand_path('templates', __dir__)
12
+ ]
13
+ end
14
+
15
+ def copy_mailers_previews
16
+ preview_path = Rails.application.config.action_mailer.preview_path || 'test/mailers/previews'
17
+
18
+ template 'mailers/previews/vendor_notification_preview.rb', "#{preview_path}/vendor_notification_preview.rb"
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ class VendorNotificationPreview < ActionMailer::Preview
2
+ def vendor_notification_email
3
+ Spree::VendorMailer.vendor_notification_email(Spree::Order.complete.first.id, Spree::Vendor.first.id)
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ module SpreeMultiVendor
2
+ class Engine < Rails::Engine
3
+ require 'spree/core'
4
+ isolate_namespace Spree
5
+ engine_name 'spree_multi_vendor'
6
+
7
+ # use rspec for tests
8
+ config.generators do |g|
9
+ g.test_framework :rspec
10
+ end
11
+
12
+ initializer 'spree_multi_vendor.environment', before: :load_config_initializers do |_app|
13
+ SpreeMultiVendor::Config = SpreeMultiVendor::Configuration.new
14
+ end
15
+
16
+ def self.activate
17
+ Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
18
+ Rails.configuration.cache_classes ? require(c) : load(c)
19
+ end
20
+ end
21
+
22
+ config.to_prepare &method(:activate).to_proc
23
+ end
24
+ end
@@ -0,0 +1,7 @@
1
+ FactoryBot.define do
2
+ GEM_ROOT = File.dirname(File.dirname(File.dirname(__FILE__)))
3
+
4
+ Dir[File.join(GEM_ROOT, 'spec', 'factories', '**', '*.rb')].each do |factory|
5
+ require(factory)
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ module SpreeMultiVendor
2
+ VERSION = '2.3.0'
3
+
4
+ module_function
5
+
6
+ # Returns the version of the currently loaded SpreeMultiVendor as a
7
+ # <tt>Gem::Version</tt>.
8
+ def version
9
+ Gem::Version.new VERSION
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ require 'spree_core'
2
+ require 'spree_backend'
3
+ require 'spree_emails'
4
+ require 'spree_multi_vendor/engine'
5
+ require 'spree_multi_vendor/version'
6
+ require 'spree_extension'
7
+ require 'deface'
8
+
9
+ module SpreeMultiVendor
10
+ # TODO: this should be moved into preferences
11
+ def self.vendorized_models
12
+ SpreeMultiVendor::Config[:vendorized_models].map(&:classify).map do |class_name|
13
+ "::Spree::#{class_name}".safe_constantize
14
+ end.compact.uniq
15
+ end
16
+ end
@@ -0,0 +1,8 @@
1
+ namespace :spree_multi_vendor do
2
+ namespace :sample do
3
+ desc 'Create sample Vendor and Vendor User'
4
+ task create: :environment do
5
+ require File.join(File.dirname(__FILE__), '..', '..', 'db', 'default', 'vendors.rb')
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,28 @@
1
+ FactoryBot.define do
2
+ factory :vendor, class: Spree::Vendor do
3
+ name { FFaker::Company.name }
4
+ about_us { 'About us...' }
5
+ contact_us { 'Contact us...' }
6
+
7
+ factory :active_vendor do
8
+ name { 'Active vendor' }
9
+ state { :active }
10
+ end
11
+
12
+ factory :active_vendor_list do
13
+ name { "#{FFaker::Company.name} #{FFaker::Company.suffix }" }
14
+ state { :active }
15
+ end
16
+
17
+
18
+ factory :pending_vendor do
19
+ name { 'Pending vendor' }
20
+ state { :pending }
21
+ end
22
+
23
+ factory :blocked_vendor do
24
+ name { 'Blocked vendor' }
25
+ state { :blocked }
26
+ end
27
+ end
28
+ end