spree_core 5.2.0.rc3 → 5.2.1
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/app/helpers/spree/integrations_helper.rb +1 -1
- data/app/jobs/spree/images/save_from_url_job.rb +1 -1
- data/app/models/concerns/spree/calculated_adjustments.rb +1 -1
- data/app/models/concerns/spree/user_methods.rb +1 -1
- data/app/models/spree/ability.rb +75 -10
- data/app/models/spree/address.rb +1 -1
- data/app/models/spree/adjustable/adjustments_updater.rb +1 -1
- data/app/models/spree/asset.rb +2 -2
- data/app/models/spree/calculator.rb +1 -1
- data/app/models/spree/data_feed.rb +1 -1
- data/app/models/spree/export.rb +1 -1
- data/app/models/spree/gateway/bogus.rb +1 -1
- data/app/models/spree/import.rb +1 -1
- data/app/models/spree/metafield_definition.rb +3 -3
- data/app/models/spree/order/payments.rb +2 -0
- data/app/models/spree/order.rb +1 -0
- data/app/models/spree/payment/processing.rb +13 -0
- data/app/models/spree/payment.rb +20 -0
- data/app/models/spree/payment_method.rb +1 -1
- data/app/models/spree/permission_sets/base.rb +81 -0
- data/app/models/spree/permission_sets/configuration_management.rb +47 -0
- data/app/models/spree/permission_sets/dashboard_display.rb +17 -0
- data/app/models/spree/permission_sets/default_customer.rb +66 -0
- data/app/models/spree/permission_sets/order_display.rb +27 -0
- data/app/models/spree/permission_sets/order_management.rb +33 -0
- data/app/models/spree/permission_sets/product_display.rb +27 -0
- data/app/models/spree/permission_sets/product_management.rb +27 -0
- data/app/models/spree/permission_sets/promotion_management.rb +22 -0
- data/app/models/spree/permission_sets/role_management.rb +21 -0
- data/app/models/spree/permission_sets/stock_display.rb +19 -0
- data/app/models/spree/permission_sets/stock_management.rb +19 -0
- data/app/models/spree/permission_sets/super_user.rb +28 -0
- data/app/models/spree/permission_sets/user_display.rb +19 -0
- data/app/models/spree/permission_sets/user_management.rb +20 -0
- data/app/models/spree/product.rb +37 -3
- data/app/models/spree/stock/coordinator.rb +1 -1
- data/app/models/spree/taxon.rb +1 -0
- data/app/models/spree/theme.rb +4 -4
- data/app/services/spree/compare_line_items.rb +1 -1
- data/app/views/spree/shared/_base_mailer_stylesheets.html.erb +5 -0
- data/config/locales/en.yml +5 -0
- data/lib/friendly_id/history_decorator.rb +26 -0
- data/lib/generators/spree/cursor_rules/templates/spree_rules.mdc +1 -1
- data/lib/generators/spree/install/templates/config/initializers/spree.rb +56 -24
- data/lib/generators/spree/model/model_generator.rb +21 -0
- data/lib/generators/spree/model/templates/model.rb.tt +22 -0
- data/lib/generators/spree/model_decorator/model_decorator_generator.rb +37 -0
- data/lib/generators/spree/model_decorator/templates/model_decorator.rb.tt +12 -0
- data/lib/spree/analytics.rb +2 -2
- data/lib/spree/core/engine.rb +10 -4
- data/lib/spree/core/partials.rb +42 -0
- data/lib/spree/core/permission_configuration.rb +102 -0
- data/lib/spree/core/token_generator.rb +1 -0
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/core.rb +208 -0
- data/lib/spree/testing_support/factories/order_factory.rb +7 -4
- data/lib/spree_core.rb +1 -0
- metadata +31 -12
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Permission set for full product and catalog management.
|
|
2
|
+
#
|
|
3
|
+
# This permission set provides complete access to manage products, variants,
|
|
4
|
+
# and related catalog models like taxonomies and properties.
|
|
5
|
+
#
|
|
6
|
+
# @example
|
|
7
|
+
# Spree.permissions.assign(:merchandiser, Spree::PermissionSets::ProductManagement)
|
|
8
|
+
#
|
|
9
|
+
module Spree
|
|
10
|
+
module PermissionSets
|
|
11
|
+
class ProductManagement < Base
|
|
12
|
+
def activate!
|
|
13
|
+
can :manage, Spree::Product
|
|
14
|
+
can :manage, Spree::Variant
|
|
15
|
+
can :manage, Spree::OptionType
|
|
16
|
+
can :manage, Spree::OptionValue
|
|
17
|
+
can :manage, Spree::Property
|
|
18
|
+
can :manage, Spree::ProductProperty
|
|
19
|
+
can :manage, Spree::Taxon
|
|
20
|
+
can :manage, Spree::Taxonomy
|
|
21
|
+
can :manage, Spree::Classification
|
|
22
|
+
can :manage, Spree::Price
|
|
23
|
+
can :manage, Spree::Asset
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Permission set for managing promotions and discounts.
|
|
2
|
+
#
|
|
3
|
+
# This permission set provides access to create and manage promotions,
|
|
4
|
+
# coupon codes, and promotion rules.
|
|
5
|
+
#
|
|
6
|
+
# @example
|
|
7
|
+
# Spree.permissions.assign(:marketing, Spree::PermissionSets::PromotionManagement)
|
|
8
|
+
#
|
|
9
|
+
module Spree
|
|
10
|
+
module PermissionSets
|
|
11
|
+
class PromotionManagement < Base
|
|
12
|
+
def activate!
|
|
13
|
+
can :manage, Spree::Promotion
|
|
14
|
+
can :manage, Spree::PromotionRule
|
|
15
|
+
can :manage, Spree::PromotionAction
|
|
16
|
+
can :manage, Spree::PromotionCategory
|
|
17
|
+
can :manage, Spree::CouponCode
|
|
18
|
+
can [:read, :admin], Spree::Metafield
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Permission set for managing roles and permissions.
|
|
2
|
+
#
|
|
3
|
+
# This permission set provides access to manage roles and user assignments.
|
|
4
|
+
# Note: The admin role cannot be modified.
|
|
5
|
+
#
|
|
6
|
+
# @example
|
|
7
|
+
# Spree.permissions.assign(:admin, Spree::PermissionSets::RoleManagement)
|
|
8
|
+
#
|
|
9
|
+
module Spree
|
|
10
|
+
module PermissionSets
|
|
11
|
+
class RoleManagement < Base
|
|
12
|
+
def activate!
|
|
13
|
+
can :manage, Spree::Role
|
|
14
|
+
can :manage, Spree::RoleUser
|
|
15
|
+
|
|
16
|
+
# Protect the admin role from modification
|
|
17
|
+
cannot [:update, :destroy], Spree::Role, name: ['admin']
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Permission set for viewing stock and inventory information.
|
|
2
|
+
#
|
|
3
|
+
# This permission set provides read-only access to stock items,
|
|
4
|
+
# locations, and movements.
|
|
5
|
+
#
|
|
6
|
+
# @example
|
|
7
|
+
# Spree.permissions.assign(:warehouse_viewer, Spree::PermissionSets::StockDisplay)
|
|
8
|
+
#
|
|
9
|
+
module Spree
|
|
10
|
+
module PermissionSets
|
|
11
|
+
class StockDisplay < Base
|
|
12
|
+
def activate!
|
|
13
|
+
can [:read, :admin, :index], Spree::StockItem
|
|
14
|
+
can [:read, :admin], Spree::StockLocation
|
|
15
|
+
can [:read, :admin], Spree::StockMovement
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Permission set for full stock and inventory management.
|
|
2
|
+
#
|
|
3
|
+
# This permission set provides complete access to manage stock items,
|
|
4
|
+
# locations, and movements.
|
|
5
|
+
#
|
|
6
|
+
# @example
|
|
7
|
+
# Spree.permissions.assign(:warehouse_manager, Spree::PermissionSets::StockManagement)
|
|
8
|
+
#
|
|
9
|
+
module Spree
|
|
10
|
+
module PermissionSets
|
|
11
|
+
class StockManagement < Base
|
|
12
|
+
def activate!
|
|
13
|
+
can :manage, Spree::StockItem
|
|
14
|
+
can :manage, Spree::StockLocation
|
|
15
|
+
can :manage, Spree::StockMovement
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Permission set granting full administrative access.
|
|
2
|
+
#
|
|
3
|
+
# This permission set provides unrestricted access to all resources,
|
|
4
|
+
# with some safety restrictions for critical operations.
|
|
5
|
+
#
|
|
6
|
+
# @example
|
|
7
|
+
# Spree.permissions.assign(:admin, Spree::PermissionSets::SuperUser)
|
|
8
|
+
#
|
|
9
|
+
module Spree
|
|
10
|
+
module PermissionSets
|
|
11
|
+
class SuperUser < Base
|
|
12
|
+
def activate!
|
|
13
|
+
can :manage, :all
|
|
14
|
+
|
|
15
|
+
# Safety restrictions
|
|
16
|
+
cannot :cancel, Spree::Order
|
|
17
|
+
can :cancel, Spree::Order, &:allow_cancel?
|
|
18
|
+
cannot :destroy, Spree::Order
|
|
19
|
+
can :destroy, Spree::Order, &:can_be_deleted?
|
|
20
|
+
cannot [:edit, :update], Spree::RefundReason, mutable: false
|
|
21
|
+
cannot [:edit, :update], Spree::ReimbursementType, mutable: false
|
|
22
|
+
|
|
23
|
+
# Protect the admin role from modification
|
|
24
|
+
cannot [:update, :destroy], Spree::Role, name: ['admin']
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Permission set for viewing users and related information.
|
|
2
|
+
#
|
|
3
|
+
# This permission set provides read-only access to user accounts,
|
|
4
|
+
# addresses, and credit cards.
|
|
5
|
+
#
|
|
6
|
+
# @example
|
|
7
|
+
# Spree.permissions.assign(:support_staff, Spree::PermissionSets::UserDisplay)
|
|
8
|
+
#
|
|
9
|
+
module Spree
|
|
10
|
+
module PermissionSets
|
|
11
|
+
class UserDisplay < Base
|
|
12
|
+
def activate!
|
|
13
|
+
can [:read, :admin, :index], Spree.user_class
|
|
14
|
+
can [:read, :admin], Spree::Address
|
|
15
|
+
can [:read, :admin], Spree::CreditCard
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Permission set for full user management.
|
|
2
|
+
#
|
|
3
|
+
# This permission set provides complete access to manage user accounts,
|
|
4
|
+
# addresses, and credit cards.
|
|
5
|
+
#
|
|
6
|
+
# @example
|
|
7
|
+
# Spree.permissions.assign(:customer_service, Spree::PermissionSets::UserManagement)
|
|
8
|
+
#
|
|
9
|
+
module Spree
|
|
10
|
+
module PermissionSets
|
|
11
|
+
class UserManagement < Base
|
|
12
|
+
def activate!
|
|
13
|
+
can :manage, Spree.user_class
|
|
14
|
+
can :manage, Spree::Address
|
|
15
|
+
can :manage, Spree::CreditCard
|
|
16
|
+
can [:read, :admin], Spree::Metafield
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
data/app/models/spree/product.rb
CHANGED
|
@@ -255,8 +255,6 @@ module Spree
|
|
|
255
255
|
delegate :display_amount, :display_price, :has_default_price?, :track_inventory?,
|
|
256
256
|
:display_compare_at_price, :images, to: :default_variant
|
|
257
257
|
|
|
258
|
-
delegate :name, to: :brand, prefix: true, allow_nil: true
|
|
259
|
-
|
|
260
258
|
alias master_images images
|
|
261
259
|
|
|
262
260
|
state_machine :status, initial: :draft do
|
|
@@ -550,7 +548,22 @@ module Spree
|
|
|
550
548
|
super || variants_including_master.with_deleted.find_by(is_master: true)
|
|
551
549
|
end
|
|
552
550
|
|
|
551
|
+
# Returns the brand for the product
|
|
552
|
+
# If a brand association is defined (e.g., belongs_to :brand), it will be used
|
|
553
|
+
# Otherwise, falls back to brand_taxon for compatibility
|
|
554
|
+
# @return [Spree::Brand, Spree::Taxon]
|
|
553
555
|
def brand
|
|
556
|
+
if self.class.reflect_on_association(:brand)
|
|
557
|
+
super
|
|
558
|
+
else
|
|
559
|
+
Spree::Deprecation.warn('Spree::Product#brand is deprecated and will be removed in Spree 6. Please use Spree::Product#brand_taxon instead.')
|
|
560
|
+
brand_taxon
|
|
561
|
+
end
|
|
562
|
+
end
|
|
563
|
+
|
|
564
|
+
# Returns the brand taxon for the product
|
|
565
|
+
# @return [Spree::Taxon]
|
|
566
|
+
def brand_taxon
|
|
554
567
|
@brand ||= if Spree.use_translations?
|
|
555
568
|
taxons.joins(:taxonomy).
|
|
556
569
|
join_translation_table(Taxonomy).
|
|
@@ -564,7 +577,28 @@ module Spree
|
|
|
564
577
|
end
|
|
565
578
|
end
|
|
566
579
|
|
|
580
|
+
# Returns the brand name for the product
|
|
581
|
+
# @return [String]
|
|
582
|
+
def brand_name
|
|
583
|
+
brand&.name
|
|
584
|
+
end
|
|
585
|
+
|
|
586
|
+
# Returns the category for the product
|
|
587
|
+
# If a category association is defined (e.g., belongs_to :category), it will be used
|
|
588
|
+
# Otherwise, falls back to category_taxon for compatibility
|
|
589
|
+
# @return [Spree::Category, Spree::Taxon]
|
|
567
590
|
def category
|
|
591
|
+
if self.class.reflect_on_association(:category)
|
|
592
|
+
super
|
|
593
|
+
else
|
|
594
|
+
Spree::Deprecation.warn('Spree::Product#category is deprecated and will be removed in Spree 6. Please use Spree::Product#category_taxon instead.')
|
|
595
|
+
category_taxon
|
|
596
|
+
end
|
|
597
|
+
end
|
|
598
|
+
|
|
599
|
+
# Returns the category taxon for the product
|
|
600
|
+
# @return [Spree::Taxon]
|
|
601
|
+
def category_taxon
|
|
568
602
|
@category ||= if Spree.use_translations?
|
|
569
603
|
taxons.joins(:taxonomy).
|
|
570
604
|
join_translation_table(Taxonomy).
|
|
@@ -580,7 +614,7 @@ module Spree
|
|
|
580
614
|
end
|
|
581
615
|
|
|
582
616
|
def main_taxon
|
|
583
|
-
|
|
617
|
+
category_taxon || taxons.first
|
|
584
618
|
end
|
|
585
619
|
|
|
586
620
|
def taxons_for_store(store)
|
data/app/models/spree/taxon.rb
CHANGED
|
@@ -324,6 +324,7 @@ module Spree
|
|
|
324
324
|
# indicate which filters should be used for a taxon
|
|
325
325
|
# this method should be customized to your own site
|
|
326
326
|
def applicable_filters
|
|
327
|
+
Spree::Deprecation.warn('applicable_filters is deprecated and will be removed in Spree 6.0')
|
|
327
328
|
fs = []
|
|
328
329
|
# fs << ProductFilters.taxons_below(self)
|
|
329
330
|
## unless it's a root taxon? left open for demo purposes
|
data/app/models/spree/theme.rb
CHANGED
|
@@ -56,7 +56,7 @@ module Spree
|
|
|
56
56
|
#
|
|
57
57
|
# @return [Array<Spree::Theme>]
|
|
58
58
|
def self.available_themes
|
|
59
|
-
@available_themes ||=
|
|
59
|
+
@available_themes ||= Spree.page_builder.themes.sort_by(&:display_name)
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
def self.metadata
|
|
@@ -98,7 +98,7 @@ module Spree
|
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
def create_default_pages
|
|
101
|
-
|
|
101
|
+
Spree.page_builder.pages.map(&:to_s).map(&:constantize).each do |page_class|
|
|
102
102
|
next if page_class == Spree::Pages::Custom
|
|
103
103
|
|
|
104
104
|
page_class.where(pageable: self).first_or_create!
|
|
@@ -160,7 +160,7 @@ module Spree
|
|
|
160
160
|
# @return [Array<Class>]
|
|
161
161
|
def available_layout_sections
|
|
162
162
|
[
|
|
163
|
-
*
|
|
163
|
+
*Spree.page_builder.theme_layout_sections,
|
|
164
164
|
*custom_layout_sections
|
|
165
165
|
]
|
|
166
166
|
end
|
|
@@ -181,7 +181,7 @@ module Spree
|
|
|
181
181
|
return @available_page_sections if @available_page_sections
|
|
182
182
|
|
|
183
183
|
@available_page_sections ||= [
|
|
184
|
-
*
|
|
184
|
+
*Spree.page_builder.page_sections.find_all do |section_class|
|
|
185
185
|
section_class.role == 'content'
|
|
186
186
|
end,
|
|
187
187
|
*custom_page_sections
|
|
@@ -4,7 +4,7 @@ module Spree
|
|
|
4
4
|
prepend Spree::ServiceModule::Base
|
|
5
5
|
|
|
6
6
|
def call(order:, line_item:, options: {}, comparison_hooks: nil)
|
|
7
|
-
comparison_hooks ||=
|
|
7
|
+
comparison_hooks ||= Spree.line_item_comparison_hooks
|
|
8
8
|
|
|
9
9
|
legacy_part = comparison_hooks.all? do |hook|
|
|
10
10
|
order.send(hook, line_item, options)
|
data/config/locales/en.yml
CHANGED
|
@@ -105,6 +105,8 @@ en:
|
|
|
105
105
|
phone: Shipping address phone
|
|
106
106
|
state: Shipping address state
|
|
107
107
|
zipcode: Shipping address zipcode
|
|
108
|
+
spree/page_link:
|
|
109
|
+
open_in_new_tab: Open in new tab
|
|
108
110
|
spree/payment:
|
|
109
111
|
amount: Amount
|
|
110
112
|
number: Number
|
|
@@ -200,6 +202,7 @@ en:
|
|
|
200
202
|
spree/taxonomy:
|
|
201
203
|
name: Name
|
|
202
204
|
spree/user:
|
|
205
|
+
avatar: Avatar
|
|
203
206
|
email: Email
|
|
204
207
|
password: Password
|
|
205
208
|
password_confirmation: Password Confirmation
|
|
@@ -621,6 +624,7 @@ en:
|
|
|
621
624
|
add_new_style: Add New Style
|
|
622
625
|
add_one: Add One
|
|
623
626
|
add_option_value: Add Option Value
|
|
627
|
+
add_page_block: Add Block
|
|
624
628
|
add_product: Add Product
|
|
625
629
|
add_product_properties: Add Product Properties
|
|
626
630
|
add_products: Add Products
|
|
@@ -1622,6 +1626,7 @@ en:
|
|
|
1622
1626
|
payment_updated: Payment Updated
|
|
1623
1627
|
payments: Payments
|
|
1624
1628
|
payments_count: Payments count
|
|
1629
|
+
payments_gateway_processing_errors: "%{payment_method_name} processing errors"
|
|
1625
1630
|
pending: Pending
|
|
1626
1631
|
pending_sale: Pending Sale
|
|
1627
1632
|
percent: Percent
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module FriendlyId
|
|
2
|
+
module HistoryDecorator
|
|
3
|
+
private
|
|
4
|
+
|
|
5
|
+
# This a patch to friendly_id history module.
|
|
6
|
+
# Originally, it removes and re-creates a slug record if it already exists. The issue is that we use `acts_as_paranoid`
|
|
7
|
+
# for slugs so it sets the `deleted_at` timestamp instead of deleting the record. We need to delete the record instead.
|
|
8
|
+
def create_slug
|
|
9
|
+
return unless friendly_id
|
|
10
|
+
return if history_is_up_to_date?
|
|
11
|
+
# Allow reversion back to a previously used slug
|
|
12
|
+
relation = slugs.where(slug: friendly_id)
|
|
13
|
+
if friendly_id_config.uses?(:scoped)
|
|
14
|
+
relation = relation.where(scope: serialized_scope)
|
|
15
|
+
end
|
|
16
|
+
# Use `delete_all` instead of `destroy_all` to avoid the unique index error.
|
|
17
|
+
relation.delete_all unless relation.empty?
|
|
18
|
+
slugs.create! do |record|
|
|
19
|
+
record.slug = friendly_id
|
|
20
|
+
record.scope = serialized_scope if friendly_id_config.uses?(:scoped)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
FriendlyId::History.prepend(FriendlyId::HistoryDecorator)
|
|
@@ -255,7 +255,7 @@ bin/rails g spree:storefront:theme MyTheme
|
|
|
255
255
|
|
|
256
256
|
```ruby
|
|
257
257
|
# Register theme in config/initializers/spree.rb
|
|
258
|
-
|
|
258
|
+
Spree.page_builder.themes << Spree::Themes::MyTheme
|
|
259
259
|
```
|
|
260
260
|
|
|
261
261
|
#### View Overrides
|
|
@@ -61,33 +61,65 @@ end
|
|
|
61
61
|
# uncomment lines below to add your own custom business logic
|
|
62
62
|
# such as promotions, shipping methods, etc
|
|
63
63
|
Rails.application.config.after_initialize do
|
|
64
|
-
#
|
|
65
|
-
#
|
|
64
|
+
# Payment methods and shipping calculators
|
|
65
|
+
# Spree.payment_methods << Spree::PaymentMethods::VerySafeAndReliablePaymentMethod
|
|
66
|
+
# Spree.calculators.shipping_methods << Spree::ShippingMethods::SuperExpensiveNotVeryFastShipping
|
|
67
|
+
# Spree.calculators.tax_rates << Spree::TaxRates::FinanceTeamForcedMeToCodeThis
|
|
66
68
|
|
|
67
|
-
#
|
|
68
|
-
|
|
69
|
-
#
|
|
70
|
-
|
|
71
|
-
# Rails.application.config.spree.adjusters << Spree::Adjustable::Adjuster::TaxTheRich
|
|
69
|
+
# Stock splitters and adjusters
|
|
70
|
+
# Spree.stock_splitters << Spree::Stock::Splitters::SecretLogicSplitter
|
|
71
|
+
# Spree.adjusters << Spree::Adjustable::Adjuster::TaxTheRich
|
|
72
72
|
|
|
73
73
|
# Custom promotions
|
|
74
|
-
#
|
|
75
|
-
#
|
|
76
|
-
#
|
|
77
|
-
#
|
|
78
|
-
|
|
79
|
-
#
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
#
|
|
83
|
-
|
|
84
|
-
#
|
|
85
|
-
|
|
86
|
-
#
|
|
87
|
-
#
|
|
88
|
-
#
|
|
89
|
-
|
|
90
|
-
#
|
|
74
|
+
# Spree.calculators.promotion_actions_create_adjustments << Spree::Calculators::PromotionActions::CreateAdjustments::AddDiscountForFriends
|
|
75
|
+
# Spree.calculators.promotion_actions_create_item_adjustments << Spree::Calculators::PromotionActions::CreateItemAdjustments::FinanceTeamForcedMeToCodeThis
|
|
76
|
+
# Spree.promotions.rules << Spree::Promotions::Rules::OnlyForVIPCustomers
|
|
77
|
+
# Spree.promotions.actions << Spree::Promotions::Actions::GiftWithPurchase
|
|
78
|
+
|
|
79
|
+
# Taxon rules
|
|
80
|
+
# Spree.taxon_rules << Spree::TaxonRules::ProductsWithColor
|
|
81
|
+
|
|
82
|
+
# Exports and reports
|
|
83
|
+
# Spree.export_types << Spree::Exports::Payments
|
|
84
|
+
# Spree.reports << Spree::Reports::MassivelyOvercomplexReportForCfo
|
|
85
|
+
|
|
86
|
+
# Page builder (themes, pages, sections, blocks)
|
|
87
|
+
# Spree.page_builder.themes << Spree::Themes::NewShinyTheme
|
|
88
|
+
# Spree.page_builder.theme_layout_sections << Spree::PageSections::SuperImportantCeoBio
|
|
89
|
+
# Spree.page_builder.pages << Spree::Pages::CustomLandingPage
|
|
90
|
+
# Spree.page_builder.page_sections << Spree::PageSections::ContactFormToGetInTouch
|
|
91
|
+
# Spree.page_builder.page_blocks << Spree::PageBlocks::BigRedButtonToCallSales
|
|
92
|
+
|
|
93
|
+
# Storefront partials
|
|
94
|
+
# Spree.storefront.partials.head << 'spree/shared/that_js_snippet_that_marketing_forced_me_to_include'
|
|
95
|
+
|
|
96
|
+
# Admin partials
|
|
97
|
+
# Spree.admin.partials.product_form << 'spree/admin/products/custom_section'
|
|
98
|
+
|
|
99
|
+
# Role-based permissions
|
|
100
|
+
# Configure which permission sets are assigned to each role
|
|
101
|
+
# More on permission sets: https://spreecommerce.org/docs/developer/customization/permissions
|
|
102
|
+
Spree.permissions.assign(:default, [Spree::PermissionSets::DefaultCustomer])
|
|
103
|
+
Spree.permissions.assign(:admin, [Spree::PermissionSets::SuperUser])
|
|
104
|
+
|
|
105
|
+
# Example: Create a custom role with specific permissions
|
|
106
|
+
# Spree.permissions.assign(:customer_service, [
|
|
107
|
+
# Spree::PermissionSets::DashboardDisplay,
|
|
108
|
+
# Spree::PermissionSets::OrderManagement,
|
|
109
|
+
# Spree::PermissionSets::UserDisplay
|
|
110
|
+
# ])
|
|
111
|
+
#
|
|
112
|
+
# Available permission sets:
|
|
113
|
+
# - Spree::PermissionSets::SuperUser (full admin access)
|
|
114
|
+
# - Spree::PermissionSets::DefaultCustomer (storefront access)
|
|
115
|
+
# - Spree::PermissionSets::DashboardDisplay (view admin dashboard)
|
|
116
|
+
# - Spree::PermissionSets::OrderDisplay / OrderManagement
|
|
117
|
+
# - Spree::PermissionSets::ProductDisplay / ProductManagement
|
|
118
|
+
# - Spree::PermissionSets::UserDisplay / UserManagement
|
|
119
|
+
# - Spree::PermissionSets::StockDisplay / StockManagement
|
|
120
|
+
# - Spree::PermissionSets::PromotionManagement
|
|
121
|
+
# - Spree::PermissionSets::ConfigurationManagement
|
|
122
|
+
# - Spree::PermissionSets::RoleManagement
|
|
91
123
|
end
|
|
92
124
|
|
|
93
125
|
Spree.user_class = <%= (options[:user_class].blank? ? 'Spree::LegacyUser' : options[:user_class]).inspect %>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require "rails/generators/active_record/model/model_generator"
|
|
2
|
+
|
|
3
|
+
module Spree
|
|
4
|
+
class ModelGenerator < ActiveRecord::Generators::ModelGenerator
|
|
5
|
+
|
|
6
|
+
def self.source_paths
|
|
7
|
+
paths = superclass.source_paths
|
|
8
|
+
paths << File.expand_path('templates', __dir__)
|
|
9
|
+
paths.flatten
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class_option :parent, type: :string, default: "Spree::Base", desc: "The parent class for the generated model"
|
|
13
|
+
|
|
14
|
+
desc 'Creates a new Spree model'
|
|
15
|
+
|
|
16
|
+
# Override to prevent module file from being created
|
|
17
|
+
def create_module_file
|
|
18
|
+
return
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
class <%= class_name.demodulize %> < <%= parent_class_name.classify %>
|
|
3
|
+
<% attributes.select(&:reference?).each do |attribute| -%>
|
|
4
|
+
belongs_to :<%= attribute.name %><%= ", polymorphic: true" if attribute.polymorphic? %>
|
|
5
|
+
<% end -%>
|
|
6
|
+
<% attributes.select(&:rich_text?).each do |attribute| -%>
|
|
7
|
+
has_rich_text :<%= attribute.name %>
|
|
8
|
+
<% end -%>
|
|
9
|
+
<% attributes.select(&:attachment?).each do |attribute| -%>
|
|
10
|
+
has_one_attached :<%= attribute.name %>
|
|
11
|
+
<% end -%>
|
|
12
|
+
<% attributes.select(&:attachments?).each do |attribute| -%>
|
|
13
|
+
has_many_attached :<%= attribute.name %>
|
|
14
|
+
<% end -%>
|
|
15
|
+
<% attributes.select(&:token?).each do |attribute| -%>
|
|
16
|
+
has_secure_token<% if attribute.name != "token" %> :<%= attribute.name %><% end %>
|
|
17
|
+
<% end -%>
|
|
18
|
+
<% if attributes.any?(&:password_digest?) -%>
|
|
19
|
+
has_secure_password
|
|
20
|
+
<% end -%>
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
class ModelDecoratorGenerator < Rails::Generators::NamedBase
|
|
3
|
+
desc 'Creates a model decorator for a Spree model'
|
|
4
|
+
|
|
5
|
+
argument :name, type: :string, required: true, banner: 'Spree::ModelName'
|
|
6
|
+
|
|
7
|
+
def self.source_paths
|
|
8
|
+
paths = superclass.source_paths
|
|
9
|
+
paths << File.expand_path('templates', __dir__)
|
|
10
|
+
paths.flatten
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def create_model_decorator_file
|
|
14
|
+
template 'model_decorator.rb.tt', "app/models/#{file_path}_decorator.rb"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
# Returns the model name without the Spree:: prefix
|
|
20
|
+
# e.g., "Spree::Product" => "Product", "Product" => "Product"
|
|
21
|
+
def model_name
|
|
22
|
+
name.sub(/^Spree::/, '').classify
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Returns the decorator module name
|
|
26
|
+
# e.g., "Spree::Product" => "ProductDecorator"
|
|
27
|
+
def decorator_name
|
|
28
|
+
"#{model_name}Decorator"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Returns the file path for the decorator
|
|
32
|
+
# e.g., "Spree::Product" => "spree/product", "Product" => "spree/product"
|
|
33
|
+
def file_path
|
|
34
|
+
"spree/#{model_name.underscore}"
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
data/lib/spree/analytics.rb
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
module Spree
|
|
2
2
|
module Analytics
|
|
3
3
|
def self.events
|
|
4
|
-
@@supported_events ||=
|
|
4
|
+
@@supported_events ||= Spree.analytics.events
|
|
5
5
|
end
|
|
6
6
|
|
|
7
7
|
def self.event_handlers
|
|
8
|
-
@@event_handlers ||=
|
|
8
|
+
@@event_handlers ||= Spree.analytics.handlers
|
|
9
9
|
end
|
|
10
10
|
end
|
|
11
11
|
end
|
data/lib/spree/core/engine.rb
CHANGED
|
@@ -24,14 +24,14 @@ module Spree
|
|
|
24
24
|
:page_blocks,
|
|
25
25
|
:reports,
|
|
26
26
|
:translatable_resources,
|
|
27
|
-
:
|
|
28
|
-
:metafield_enabled_resources,
|
|
27
|
+
:metafields,
|
|
29
28
|
:analytics_events,
|
|
30
29
|
:analytics_event_handlers,
|
|
31
30
|
:integrations)
|
|
32
31
|
SpreeCalculators = Struct.new(:shipping_methods, :tax_rates, :promotion_actions_create_adjustments, :promotion_actions_create_item_adjustments)
|
|
33
32
|
PromoEnvironment = Struct.new(:rules, :actions)
|
|
34
33
|
SpreeValidators = Struct.new(:addresses)
|
|
34
|
+
MetafieldsEnvironment = Struct.new(:types, :enabled_resources)
|
|
35
35
|
isolate_namespace Spree
|
|
36
36
|
engine_name 'spree'
|
|
37
37
|
|
|
@@ -66,6 +66,12 @@ module Spree
|
|
|
66
66
|
initializer 'spree.register.adjustable_adjusters' do |app|
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
+
initializer 'spree.register.metafields' do |app|
|
|
70
|
+
app.config.spree.metafields = MetafieldsEnvironment.new
|
|
71
|
+
app.config.spree.metafields.types = []
|
|
72
|
+
app.config.spree.metafields.enabled_resources = []
|
|
73
|
+
end
|
|
74
|
+
|
|
69
75
|
# We need to define promotions rules here so extensions and existing apps
|
|
70
76
|
# can add their custom classes on their initializer files
|
|
71
77
|
initializer 'spree.promo.environment' do |app|
|
|
@@ -260,7 +266,7 @@ module Spree
|
|
|
260
266
|
Spree::Policy
|
|
261
267
|
]
|
|
262
268
|
|
|
263
|
-
Rails.application.config.spree.
|
|
269
|
+
Rails.application.config.spree.metafields.types = [
|
|
264
270
|
Spree::Metafields::ShortText,
|
|
265
271
|
Spree::Metafields::LongText,
|
|
266
272
|
Spree::Metafields::RichText,
|
|
@@ -269,7 +275,7 @@ module Spree
|
|
|
269
275
|
Spree::Metafields::Json
|
|
270
276
|
]
|
|
271
277
|
|
|
272
|
-
Rails.application.config.spree.
|
|
278
|
+
Rails.application.config.spree.metafields.enabled_resources = [
|
|
273
279
|
Spree::Address,
|
|
274
280
|
Spree::Asset,
|
|
275
281
|
Spree::CreditCard,
|