spree_multi_vendor 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.rspec +3 -0
- data/.travis.yml +44 -0
- data/Appraisals +11 -0
- data/Gemfile +7 -0
- data/LICENSE +26 -0
- data/README.md +166 -0
- data/Rakefile +21 -0
- data/app/controllers/spree/admin/vendor_settings_controller.rb +34 -0
- data/app/controllers/spree/admin/vendors_controller.rb +60 -0
- data/app/controllers/spree/api/v2/storefront/vendors_controller.rb +28 -0
- data/app/controllers/spree_multi_vendor/spree/admin/base_controller_decorator.rb +10 -0
- data/app/controllers/spree_multi_vendor/spree/admin/option_types_controller_decorator.rb +7 -0
- data/app/controllers/spree_multi_vendor/spree/admin/products_controller_decorator.rb +24 -0
- data/app/controllers/spree_multi_vendor/spree/admin/properties_controller_decorator.rb +7 -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/v1/variants_controller_decorator.rb +22 -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/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 +140 -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 +105 -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 +41 -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/v2/storefront/vendor_image_serializer.rb +11 -0
- data/app/serializers/spree/v2/storefront/vendor_order_totals_serializer.rb +18 -0
- data/app/serializers/spree/v2/storefront/vendor_serializer.rb +14 -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/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_permitted_attributes.rb +10 -0
- data/config/locales/en.yml +34 -0
- data/config/locales/es.yml +33 -0
- data/config/locales/fr.yml +33 -0
- data/config/routes.rb +19 -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/gemfiles/spree_4_2.gemfile +9 -0
- data/gemfiles/spree_master.gemfile +9 -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.rb +14 -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/tasks/vendors.rake +8 -0
- data/spec/factories/spree/vendor_factory.rb +22 -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 +36 -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 +76 -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 +179 -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/v2/storefront/cart_spec.rb +67 -0
- data/spec/requests/spree/api/v2/storefront/products_spec.rb +93 -0
- data/spec/requests/spree/api/v2/storefront/vendors_spec.rb +52 -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 +11 -0
- data/spec/support/shoulda_matchers.rb +6 -0
- data/spree_multi_vendor.gemspec +41 -0
- metadata +313 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
module Spree
|
2
|
+
class VendorOrderTotals
|
3
|
+
include ActiveModel::Model
|
4
|
+
|
5
|
+
METHOD_NAMES = %w[
|
6
|
+
total ship_total subtotal included_tax_total additional_tax_total promo_total
|
7
|
+
pre_tax_item_amount pre_tax_ship_amount pre_tax_total
|
8
|
+
].freeze
|
9
|
+
|
10
|
+
attr_accessor :vendor, :order
|
11
|
+
|
12
|
+
delegate :id, :name, to: :vendor
|
13
|
+
|
14
|
+
METHOD_NAMES.each do |method_name|
|
15
|
+
define_method(method_name) do
|
16
|
+
order.send("vendor_#{method_name}", vendor)
|
17
|
+
end
|
18
|
+
|
19
|
+
define_method("display_#{method_name}") do
|
20
|
+
order.send("display_vendor_#{method_name}", vendor)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def item_count
|
25
|
+
order.vendor_item_count(vendor)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Spree
|
2
|
+
class VendorUser < Spree::Base
|
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
|
5
|
+
|
6
|
+
validates :vendor_id, uniqueness: { scope: :user_id }
|
7
|
+
|
8
|
+
before_save :set_vendor_notification_email
|
9
|
+
|
10
|
+
def set_vendor_notification_email
|
11
|
+
return if vendor&.notification_email.present? || !vendor&.users&.empty?
|
12
|
+
|
13
|
+
vendor.update_notification_email(user.email)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module SpreeMultiVendor
|
2
|
+
class Configuration < Spree::Preferences::Configuration
|
3
|
+
DEFAULT_VENDORIZED_MODELS ||= %w[product variant stock_location shipping_method].freeze
|
4
|
+
|
5
|
+
# Some example preferences are shown below, for more information visit:
|
6
|
+
# https://guides.spreecommerce.org/developer/core/preferences.html
|
7
|
+
|
8
|
+
preference :vendorized_models, :array, default: DEFAULT_VENDORIZED_MODELS
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module SpreeMultiVendor::Spree::BaseDecorator
|
2
|
+
SpreeMultiVendor.vendorized_models.each do |model|
|
3
|
+
model.include Spree::VendorConcern
|
4
|
+
|
5
|
+
if model.method_defined?(:whitelisted_ransackable_associations)
|
6
|
+
if model.whitelisted_ransackable_associations
|
7
|
+
model.whitelisted_ransackable_associations += %w[vendor]
|
8
|
+
else
|
9
|
+
model.whitelisted_ransackable_associations = %w[vendor]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module SpreeMultiVendor::Spree::LineItemDecorator
|
2
|
+
def self.prepended(base)
|
3
|
+
base.scope :for_vendor, ->(vendor) do
|
4
|
+
if ::Spree::LineItem.reflect_on_association(:vendor)
|
5
|
+
where(vendor_id: vendor.id)
|
6
|
+
elsif ::Spree::Product.reflect_on_association(:vendor)
|
7
|
+
joins(variant: :product).where('spree_products.vendor_id' => vendor.id)
|
8
|
+
elsif ::Spree::Variant.reflect_on_association(:vendor)
|
9
|
+
joins(:variant).where('spree_variants.vendor_id' => vendor.id)
|
10
|
+
else
|
11
|
+
none
|
12
|
+
end
|
13
|
+
end
|
14
|
+
base.scope :not_for_vendor, ->(vendor) do
|
15
|
+
if ::Spree::Product.reflect_on_association(:vendor)
|
16
|
+
where.not(vendor_id: vendor.id)
|
17
|
+
elsif ::Spree::Product.reflect_on_association(:vendor)
|
18
|
+
joins(variant: :product).where.not('spree_products.vendor_id' => vendor.id)
|
19
|
+
elsif ::Spree::Variant.reflect_on_association(:vendor)
|
20
|
+
joins(:variant).where.not('spree_variants.vendor_id' => vendor.id)
|
21
|
+
else
|
22
|
+
none
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def vendor
|
28
|
+
@vendor ||= if self.class.reflect_on_association(:vendor) && self[:vendor_id].present?
|
29
|
+
::Spree::Vendor.unscoped.find(self[:vendor_id])
|
30
|
+
elsif product.class.reflect_on_association(:vendor) && product.vendor_id.present?
|
31
|
+
product.vendor
|
32
|
+
elsif variant.class.reflect_on_association(:vendor) && variant.vendor_id.present?
|
33
|
+
variant.vendor
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def vendor_id
|
38
|
+
@vendor_id ||= if self.class.reflect_on_association(:vendor) && self[:vendor_id].present?
|
39
|
+
self[:vendor_id]
|
40
|
+
elsif product.class.reflect_on_association(:vendor) && product.vendor_id.present?
|
41
|
+
product.vendor_id
|
42
|
+
elsif variant.class.reflect_on_association(:vendor) && variant.vendor_id.present?
|
43
|
+
variant.vendor_id
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
Spree::LineItem.prepend SpreeMultiVendor::Spree::LineItemDecorator
|
@@ -0,0 +1,105 @@
|
|
1
|
+
module SpreeMultiVendor::Spree::OrderDecorator
|
2
|
+
def self.prepended(base)
|
3
|
+
base.has_many :commissions, class_name: 'Spree::OrderCommission'
|
4
|
+
base.state_machine.after_transition to: :complete, do: :generate_order_commissions
|
5
|
+
base.state_machine.after_transition to: :complete, do: :send_notification_mails_to_vendors
|
6
|
+
end
|
7
|
+
|
8
|
+
def generate_order_commissions
|
9
|
+
Spree::Orders::GenerateCommissions.call(order: self)
|
10
|
+
end
|
11
|
+
|
12
|
+
def vendor_line_items(vendor)
|
13
|
+
line_items.for_vendor(vendor)
|
14
|
+
end
|
15
|
+
|
16
|
+
def vendor_shipments(vendor)
|
17
|
+
shipments.for_vendor(vendor)
|
18
|
+
end
|
19
|
+
|
20
|
+
def vendor_ship_total(vendor)
|
21
|
+
vendor_shipments(vendor).sum(&:final_price)
|
22
|
+
end
|
23
|
+
|
24
|
+
def vendor_subtotal(vendor)
|
25
|
+
vendor_line_items(vendor).sum(&:total)
|
26
|
+
end
|
27
|
+
|
28
|
+
def vendor_promo_total(vendor)
|
29
|
+
vendor_line_items(vendor).sum(:promo_total) + vendor_shipments(vendor).sum(:promo_total)
|
30
|
+
end
|
31
|
+
|
32
|
+
def vendor_additional_tax_total(vendor)
|
33
|
+
vendor_line_items(vendor).sum(:additional_tax_total) + vendor_shipments(vendor).sum(:additional_tax_total)
|
34
|
+
end
|
35
|
+
|
36
|
+
def vendor_included_tax_total(vendor)
|
37
|
+
vendor_line_items(vendor).sum(:included_tax_total) + vendor_shipments(vendor).sum(:included_tax_total)
|
38
|
+
end
|
39
|
+
|
40
|
+
def vendor_pre_tax_item_amount(vendor)
|
41
|
+
vendor_line_items(vendor).sum(:pre_tax_amount)
|
42
|
+
end
|
43
|
+
|
44
|
+
def vendor_pre_tax_ship_amount(vendor)
|
45
|
+
vendor_shipments(vendor).sum(:pre_tax_amount)
|
46
|
+
end
|
47
|
+
|
48
|
+
def vendor_pre_tax_total(vendor)
|
49
|
+
vendor_line_items(vendor).sum(:pre_tax_amount) + vendor_shipments(vendor).sum(:pre_tax_amount)
|
50
|
+
end
|
51
|
+
|
52
|
+
def vendor_item_count(vendor)
|
53
|
+
vendor_line_items(vendor).sum(:quantity)
|
54
|
+
end
|
55
|
+
|
56
|
+
def vendor_total(vendor)
|
57
|
+
vendor_line_items(vendor).sum(&:total) + vendor_ship_total(vendor)
|
58
|
+
end
|
59
|
+
|
60
|
+
def display_order_commission
|
61
|
+
Spree::Money.new(commissions.sum(:amount), { currency: currency })
|
62
|
+
end
|
63
|
+
|
64
|
+
def vendor_commission(vendor)
|
65
|
+
commissions.for_vendor(vendor).sum(:amount)
|
66
|
+
end
|
67
|
+
|
68
|
+
# money methods
|
69
|
+
METHOD_NAMES = %w[
|
70
|
+
total ship_total subtotal included_tax_total additional_tax_total promo_total
|
71
|
+
pre_tax_item_amount pre_tax_ship_amount pre_tax_total commission
|
72
|
+
].freeze
|
73
|
+
|
74
|
+
METHOD_NAMES.each do |method_name|
|
75
|
+
define_method("display_vendor_#{method_name}") do |vendor|
|
76
|
+
Spree::Money.new(send("vendor_#{method_name}", vendor), { currency: currency })
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def send_notification_mails_to_vendors
|
81
|
+
vendor_ids.each do |vendor_id|
|
82
|
+
Spree::VendorMailer.vendor_notification_email(id, vendor_id).deliver_later
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# we're leaving this on purpose so it can be easily modified to fit desired scenario
|
87
|
+
# eg. scenario A - vendorized products, scenario B - vendorized variants of the same product
|
88
|
+
def vendor_ids
|
89
|
+
@vendor_ids ||= line_items.map(&:vendor_id).uniq.compact
|
90
|
+
end
|
91
|
+
|
92
|
+
def vendor_list
|
93
|
+
@vendor_list ||= line_items.map(&:vendor).uniq.compact
|
94
|
+
end
|
95
|
+
|
96
|
+
def vendor_totals
|
97
|
+
return if vendor_list.none?
|
98
|
+
|
99
|
+
vendor_list.map do |vendor|
|
100
|
+
Spree::VendorOrderTotals.new(vendor: vendor, order: self)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
Spree::Order.prepend SpreeMultiVendor::Spree::OrderDecorator
|
@@ -0,0 +1,8 @@
|
|
1
|
+
module SpreeMultiVendor::Spree::ShipmentDecorator
|
2
|
+
def self.prepended(base)
|
3
|
+
base.scope :for_vendor, ->(vendor) { joins(stock_location: :vendor).where('spree_stock_locations.vendor_id' => vendor.id) }
|
4
|
+
base.scope :not_for_vendor, ->(vendor) { joins(stock_location: :vendor).where.not('spree_stock_locations.vendor_id' => vendor.id) }
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
Spree::Shipment.prepend SpreeMultiVendor::Spree::ShipmentDecorator
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module SpreeMultiVendor::Spree::Stock::PackageDecorator
|
2
|
+
def shipping_methods
|
3
|
+
vendor = Spree::StockLocation.method_defined?(:vendor) ? stock_location.vendor : nil
|
4
|
+
|
5
|
+
# return only shipping methods for this Vendor
|
6
|
+
if vendor && Spree::ShippingMethod.method_defined?(:vendor)
|
7
|
+
vendor.shipping_methods.to_a
|
8
|
+
else
|
9
|
+
shipping_categories.map(&:shipping_methods).reduce(:&).to_a
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
Spree::Stock::Package.prepend SpreeMultiVendor::Spree::Stock::PackageDecorator
|
@@ -0,0 +1,8 @@
|
|
1
|
+
module SpreeMultiVendor::Spree::UserDecorator
|
2
|
+
def self.prepended(base)
|
3
|
+
base.has_many :vendor_users, class_name: 'Spree::VendorUser'
|
4
|
+
base.has_many :vendors, through: :vendor_users, class_name: 'Spree::Vendor'
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
Spree.user_class.prepend SpreeMultiVendor::Spree::UserDecorator
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module SpreeMultiVendor::Spree::VariantDecorator
|
2
|
+
def self.prepended(base)
|
3
|
+
base.before_create :assign_vendor
|
4
|
+
|
5
|
+
base.scope :for_vendor_user, ->(user) { where(vendor_id: user.vendor_ids) }
|
6
|
+
end
|
7
|
+
|
8
|
+
def vendor
|
9
|
+
@vendor ||= if self.class.reflect_on_association(:vendor) && self[:vendor_id].present?
|
10
|
+
product.vendor
|
11
|
+
::Spree::Vendor.unscoped.find(self[:vendor_id])
|
12
|
+
elsif Spree::Product.reflect_on_association(:vendor) && product.vendor_id.present?
|
13
|
+
product.vendor
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def vendor_id
|
18
|
+
@vendor_id ||= if self.class.reflect_on_association(:vendor) && self[:vendor_id].present?
|
19
|
+
self[:vendor_id]
|
20
|
+
elsif Spree::Product.reflect_on_association(:vendor) && product.vendor_id.present?
|
21
|
+
product.vendor_id
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def assign_vendor
|
28
|
+
return if !product.class.reflect_on_association(:vendor) || product.vendor.blank?
|
29
|
+
return if !self.class.reflect_on_association(:vendor) || self[:vendor_id].present?
|
30
|
+
|
31
|
+
self.vendor = product.vendor
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_stock_items
|
35
|
+
Spree::StockLocation.where(propagate_all_variants: true, vendor_id: vendor_id).each do |stock_location|
|
36
|
+
stock_location.propagate_variant(self)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
Spree::Variant.prepend SpreeMultiVendor::Spree::VariantDecorator
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Deface::Override.new(
|
2
|
+
virtual_path: 'spree/admin/orders/_form',
|
3
|
+
name: 'vendorize_shipments',
|
4
|
+
replace: "erb[loud]:contains('render partial: \"spree/admin/orders/shipment\", collection: @order.shipments.order(:created_at), locals: {order: order}')",
|
5
|
+
text: "<%= render partial: \"spree/admin/orders/shipment\", collection: (current_spree_vendor ? @order.shipments.for_vendor(current_spree_vendor).order(:created_at) : @order.shipments.order(:created_at)), locals: {order: order} %>"
|
6
|
+
)
|
7
|
+
|
8
|
+
Deface::Override.new(
|
9
|
+
virtual_path: 'spree/admin/orders/_form',
|
10
|
+
name: 'display_vendor_total',
|
11
|
+
replace: "erb[loud]:contains('order.display_total')",
|
12
|
+
text: "<%= current_spree_vendor ? order.display_vendor_total(current_spree_vendor).to_html : order.display_total.to_html %>"
|
13
|
+
)
|
@@ -0,0 +1,6 @@
|
|
1
|
+
Deface::Override.new(
|
2
|
+
virtual_path: 'spree/admin/orders/_line_items',
|
3
|
+
name: 'vendorize_line_items',
|
4
|
+
replace: "erb[silent]:contains('order.line_items.each do |item|')",
|
5
|
+
text: "<% (current_spree_vendor ? order.line_items.for_vendor(current_spree_vendor) : order.line_items).each do |item| %>"
|
6
|
+
)
|
@@ -0,0 +1,6 @@
|
|
1
|
+
Deface::Override.new(
|
2
|
+
virtual_path: 'spree/admin/orders/_line_items_edit_form',
|
3
|
+
name: 'display_vendor_total',
|
4
|
+
replace: "erb[loud]:contains('order.display_total')",
|
5
|
+
text: "<%= current_spree_vendor ? order.display_vendor_total(current_spree_vendor).to_html : order.display_total.to_html %>"
|
6
|
+
)
|
@@ -0,0 +1,6 @@
|
|
1
|
+
Deface::Override.new(
|
2
|
+
virtual_path: 'spree/admin/orders/index',
|
3
|
+
name: 'display_vendor_total',
|
4
|
+
replace: "erb[loud]:contains('order.display_total.to_html')",
|
5
|
+
text: "<%= current_spree_vendor ? order.display_vendor_total(current_spree_vendor).to_html : order.display_total.to_html %>"
|
6
|
+
)
|
@@ -0,0 +1,29 @@
|
|
1
|
+
Deface::Override.new(
|
2
|
+
virtual_path: 'spree/admin/products/_form',
|
3
|
+
name: 'Enable vendors to manage product master price',
|
4
|
+
replace: 'div[data-hook="admin_product_form_price"]',
|
5
|
+
text: <<-HTML
|
6
|
+
<%= f.field_container :price, class: ['form-group'] do %>
|
7
|
+
<%= f.label :price, raw(Spree.t(:master_price) + content_tag(:span, ' *', class: "required")) %>
|
8
|
+
<%= f.text_field :price, value: number_to_currency(@product.price, unit: ''), class: 'form-control', disabled: (cannot? :update, Spree::Price) %>
|
9
|
+
<%= f.error_message_on :price %>
|
10
|
+
<% end %>
|
11
|
+
HTML
|
12
|
+
)
|
13
|
+
|
14
|
+
Deface::Override.new(
|
15
|
+
virtual_path: 'spree/admin/products/_form',
|
16
|
+
name: 'Enable admin to menage product vendor',
|
17
|
+
insert_before: 'div[data-hook="admin_product_form_taxons"]',
|
18
|
+
text: <<-HTML
|
19
|
+
<% if current_spree_user.respond_to?(:has_spree_role?) && current_spree_user.has_spree_role?(:admin) %>
|
20
|
+
<div data-hook="admin_product_form_vendor">
|
21
|
+
<%= f.field_container :vendor, class: ['form-group'] do %>
|
22
|
+
<%= f.label :vendor_id, Spree.t(:vendor) %>
|
23
|
+
<%= f.collection_select(:vendor_id, @vendors, :id, :name, { include_blank: Spree.t('match_choices.none') }, { class: 'select2' }) %>
|
24
|
+
<%= f.error_message_on :vendor %>
|
25
|
+
<% end %>
|
26
|
+
</div>
|
27
|
+
<% end %>
|
28
|
+
HTML
|
29
|
+
)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Deface::Override.new(
|
2
|
+
virtual_path: 'spree/admin/products/new',
|
3
|
+
name: 'Enable admin to create product with assigned vendor',
|
4
|
+
insert_after: 'div[data-hook="new_product_shipping_category"]',
|
5
|
+
text: <<-HTML
|
6
|
+
<% if current_spree_user.respond_to?(:has_spree_role?) && current_spree_user.has_spree_role?(:admin) %>
|
7
|
+
<div data-hook="new_product_vendor" class="col-12 col-md-4">
|
8
|
+
<%= f.field_container :vendor, class: ['form-group'] do %>
|
9
|
+
<%= f.label :vendor_id, Spree.t(:vendor) %>
|
10
|
+
<%= f.collection_select(:vendor_id, @vendors, :id, :name, { include_blank: Spree.t('match_choices.none') }, { class: 'select2' }) %>
|
11
|
+
<%= f.error_message_on :vendor %>
|
12
|
+
<% end %>
|
13
|
+
</div>
|
14
|
+
<% end %>
|
15
|
+
HTML
|
16
|
+
)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Deface::Override.new(
|
2
|
+
virtual_path: 'spree/admin/shared/_main_menu',
|
3
|
+
name: 'Display configuration tab for vendors',
|
4
|
+
replace: 'erb[silent]:contains("current_store")',
|
5
|
+
text: '<% if can?(:admin, current_store) || current_spree_user.vendors.any? %>'
|
6
|
+
)
|
7
|
+
Deface::Override.new(
|
8
|
+
virtual_path: 'spree/admin/shared/_main_menu',
|
9
|
+
name: 'vendors_main_menu_tabs',
|
10
|
+
insert_bottom: 'nav',
|
11
|
+
text: <<-HTML
|
12
|
+
<% if current_spree_user.respond_to?(:has_spree_role?) && current_spree_user.has_spree_role?(:admin) %>
|
13
|
+
<ul class="nav nav-sidebar border-bottom">
|
14
|
+
<%= tab plural_resource_name(Spree::Vendor), url: admin_vendors_path, icon: 'money' %>
|
15
|
+
</ul>
|
16
|
+
<% end %>
|
17
|
+
<% if defined?(current_spree_vendor) && current_spree_vendor %>
|
18
|
+
<ul class="nav nav-sidebar border-bottom">
|
19
|
+
<%= tab Spree::Vendor.model_name.human, url: admin_vendor_settings_path, icon: 'money' %>
|
20
|
+
</ul>
|
21
|
+
<% end %>
|
22
|
+
HTML
|
23
|
+
)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
Deface::Override.new(
|
2
|
+
virtual_path: 'spree/admin/shared/_order_summary',
|
3
|
+
name: 'display_vendor_subtotal',
|
4
|
+
replace: "erb[loud]:contains('@order.display_item_total.to_html')",
|
5
|
+
text: "<%= current_spree_vendor ? @order.display_vendor_subtotal(current_spree_vendor).to_html : @order.display_item_total.to_html %>"
|
6
|
+
)
|
7
|
+
|
8
|
+
Deface::Override.new(
|
9
|
+
virtual_path: 'spree/admin/shared/_order_summary',
|
10
|
+
name: 'display_vendor_ship_total',
|
11
|
+
replace: "erb[loud]:contains('@order.display_ship_total.to_html')",
|
12
|
+
text: "<%= current_spree_vendor ? @order.display_vendor_ship_total(current_spree_vendor).to_html : @order.display_ship_total.to_html %>"
|
13
|
+
)
|
14
|
+
|
15
|
+
Deface::Override.new(
|
16
|
+
virtual_path: 'spree/admin/shared/_order_summary',
|
17
|
+
name: 'display_vendor_total',
|
18
|
+
replace: "erb[loud]:contains('@order.display_total.to_html')",
|
19
|
+
text: "<%= current_spree_vendor ? @order.display_vendor_total(current_spree_vendor).to_html : @order.display_total.to_html %>"
|
20
|
+
)
|
21
|
+
Deface::Override.new(
|
22
|
+
virtual_path: 'spree/admin/shared/_order_summary',
|
23
|
+
name: 'display_commission',
|
24
|
+
insert_after: 'td[id="item_total"]',
|
25
|
+
text: <<-HTML
|
26
|
+
<tr>
|
27
|
+
<td data-hook='admin_order_tab_commission'>
|
28
|
+
<strong><%= Spree.t(:commission) %></strong>
|
29
|
+
</td>
|
30
|
+
<td id='order_commission'>
|
31
|
+
<%= current_spree_vendor ? @order.display_vendor_commission(current_spree_vendor) : @order.display_order_commission %>
|
32
|
+
</td>
|
33
|
+
</tr>
|
34
|
+
HTML
|
35
|
+
)
|