solidus_core 4.4.2 → 4.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/helpers/spree/core/controller_helpers/auth.rb +66 -0
- data/app/helpers/spree/core/controller_helpers/common.rb +82 -0
- data/app/helpers/spree/core/controller_helpers/order.rb +86 -0
- data/app/helpers/spree/core/controller_helpers/payment_parameters.rb +165 -0
- data/app/helpers/spree/core/controller_helpers/pricing.rb +19 -0
- data/app/helpers/spree/core/controller_helpers/search.rb +16 -0
- data/app/helpers/spree/core/controller_helpers/store.rb +19 -0
- data/app/helpers/spree/core/controller_helpers/strong_parameters.rb +74 -0
- data/app/models/concerns/spree/metadata.rb +64 -0
- data/app/models/concerns/spree/user_address_book.rb +4 -5
- data/app/models/spree/core/state_machines/inventory_unit.rb +42 -0
- data/app/models/spree/core/state_machines/order/class_methods.rb +217 -0
- data/app/models/spree/core/state_machines/order.rb +42 -0
- data/app/models/spree/core/state_machines/payment.rb +61 -0
- data/app/models/spree/core/state_machines/reimbursement.rb +33 -0
- data/app/models/spree/core/state_machines/return_authorization.rb +32 -0
- data/app/models/spree/core/state_machines/return_item/acceptance_status.rb +51 -0
- data/app/models/spree/core/state_machines/return_item/reception_status.rb +42 -0
- data/app/models/spree/core/state_machines/shipment.rb +58 -0
- data/app/models/spree/customer_return.rb +2 -0
- data/app/models/spree/item_total.rb +28 -0
- data/app/models/spree/legacy_user.rb +1 -0
- data/app/models/spree/line_item.rb +21 -0
- data/app/models/spree/money.rb +120 -0
- data/app/models/spree/order.rb +20 -9
- data/app/models/spree/order_merger.rb +1 -1
- data/app/models/spree/order_taxation.rb +1 -0
- data/app/models/spree/order_updater.rb +13 -30
- data/app/models/spree/payment.rb +1 -0
- data/app/models/spree/permission_sets/base.rb +45 -0
- data/app/models/spree/permission_sets/configuration_display.rb +53 -0
- data/app/models/spree/permission_sets/configuration_management.rb +52 -0
- data/app/models/spree/permission_sets/dashboard_display.rb +28 -0
- data/app/models/spree/permission_sets/default_customer.rb +83 -0
- data/app/models/spree/permission_sets/order_display.rb +50 -0
- data/app/models/spree/permission_sets/order_management.rb +50 -0
- data/app/models/spree/permission_sets/product_display.rb +43 -0
- data/app/models/spree/permission_sets/product_management.rb +47 -0
- data/app/models/spree/permission_sets/restricted_stock_display.rb +33 -0
- data/app/models/spree/permission_sets/restricted_stock_management.rb +33 -0
- data/app/models/spree/permission_sets/stock_display.rb +26 -0
- data/app/models/spree/permission_sets/stock_management.rb +26 -0
- data/app/models/spree/permission_sets/super_user.rb +26 -0
- data/app/models/spree/permission_sets/user_display.rb +27 -0
- data/app/models/spree/permission_sets/user_management.rb +44 -0
- data/app/models/spree/product.rb +7 -0
- data/app/models/spree/refund.rb +2 -0
- data/app/models/spree/return_authorization.rb +2 -0
- data/app/models/spree/shipment.rb +2 -0
- data/app/models/spree/simple_order_contents.rb +4 -1
- data/app/models/spree/store_credit_event.rb +1 -0
- data/app/models/spree/tax/tax_helpers.rb +12 -1
- data/app/models/spree/tax_calculator/default.rb +1 -1
- data/app/models/spree/taxon.rb +22 -2
- data/app/models/spree/taxon_brand_selector.rb +22 -0
- data/app/models/spree/unauthorized_redirect_handler.rb +24 -0
- data/app/models/spree/user_address.rb +9 -3
- data/app/models/spree/variant.rb +14 -1
- data/config/locales/en.yml +14 -0
- data/db/migrate/20220419170826_remove_archived_user_addresses.rb +12 -0
- data/db/migrate/20250129061658_add_metadata_to_spree_resources.rb +29 -0
- data/db/migrate/20250201172950_add_gtin_and_condition_to_spree_variant.rb +6 -0
- data/db/migrate/20250207104016_add_primary_taxon_to_products.rb +7 -0
- data/lib/generators/solidus/install/app_templates/authentication/custom.rb +0 -5
- data/lib/generators/solidus/install/app_templates/frontend/starter.rb +1 -1
- data/lib/generators/spree/dummy/dummy_generator.rb +1 -1
- data/lib/generators/spree/dummy/templates/rails/application.rb.tt +1 -1
- data/lib/generators/spree/dummy/templates/rails/manifest.js +3 -0
- data/lib/spree/app_configuration.rb +49 -0
- data/lib/spree/core/controller_helpers/auth.rb +5 -61
- data/lib/spree/core/controller_helpers/common.rb +5 -80
- data/lib/spree/core/controller_helpers/order.rb +5 -86
- data/lib/spree/core/controller_helpers/payment_parameters.rb +5 -163
- data/lib/spree/core/controller_helpers/pricing.rb +5 -17
- data/lib/spree/core/controller_helpers/search.rb +5 -14
- data/lib/spree/core/controller_helpers/store.rb +5 -17
- data/lib/spree/core/controller_helpers/strong_parameters.rb +5 -71
- data/lib/spree/core/engine.rb +5 -0
- data/lib/spree/core/state_machines/inventory_unit.rb +5 -40
- data/lib/spree/core/state_machines/order.rb +5 -250
- data/lib/spree/core/state_machines/payment.rb +5 -59
- data/lib/spree/core/state_machines/reimbursement.rb +5 -31
- data/lib/spree/core/state_machines/return_authorization.rb +5 -30
- data/lib/spree/core/state_machines/return_item/acceptance_status.rb +5 -49
- data/lib/spree/core/state_machines/return_item/reception_status.rb +5 -40
- data/lib/spree/core/state_machines/shipment.rb +5 -56
- data/lib/spree/core/state_machines.rb +48 -81
- data/lib/spree/core/version.rb +2 -2
- data/lib/spree/core.rb +0 -10
- data/lib/spree/money.rb +5 -118
- data/lib/spree/permission_sets/base.rb +5 -42
- data/lib/spree/permission_sets/configuration_display.rb +5 -51
- data/lib/spree/permission_sets/configuration_management.rb +5 -50
- data/lib/spree/permission_sets/dashboard_display.rb +5 -26
- data/lib/spree/permission_sets/default_customer.rb +5 -81
- data/lib/spree/permission_sets/order_display.rb +5 -48
- data/lib/spree/permission_sets/order_management.rb +5 -48
- data/lib/spree/permission_sets/product_display.rb +5 -41
- data/lib/spree/permission_sets/product_management.rb +5 -45
- data/lib/spree/permission_sets/restricted_stock_display.rb +5 -31
- data/lib/spree/permission_sets/restricted_stock_management.rb +5 -31
- data/lib/spree/permission_sets/stock_display.rb +5 -24
- data/lib/spree/permission_sets/stock_management.rb +5 -24
- data/lib/spree/permission_sets/super_user.rb +5 -24
- data/lib/spree/permission_sets/user_display.rb +5 -25
- data/lib/spree/permission_sets/user_management.rb +5 -42
- data/lib/spree/permission_sets.rb +5 -16
- data/lib/spree/permitted_attributes.rb +18 -7
- data/lib/spree/preferences/configuration.rb +4 -0
- data/lib/spree/preferences/persistable.rb +1 -1
- data/lib/spree/testing_support/capybara_ext.rb +10 -0
- data/lib/spree/testing_support/dummy_app.rb +1 -1
- data/lib/spree/testing_support/factories/order_factory.rb +9 -1
- data/solidus_core.gemspec +1 -1
- metadata +64 -24
- data/lib/generators/spree/dummy/templates/rails/script/rails +0 -6
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
module PermissionSets
|
5
|
+
# Full permissions for product management.
|
6
|
+
#
|
7
|
+
# This permission set grants full control over all product and related resources,
|
8
|
+
# including:
|
9
|
+
#
|
10
|
+
# - Products
|
11
|
+
# - Images
|
12
|
+
# - Variants
|
13
|
+
# - Option values
|
14
|
+
# - Product properties
|
15
|
+
# - Option types
|
16
|
+
# - Properties
|
17
|
+
# - Taxonomies
|
18
|
+
# - Taxons
|
19
|
+
# - Classifications
|
20
|
+
# - Prices
|
21
|
+
class ProductManagement < PermissionSets::Base
|
22
|
+
class << self
|
23
|
+
def privilege
|
24
|
+
:management
|
25
|
+
end
|
26
|
+
|
27
|
+
def category
|
28
|
+
:product
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def activate!
|
33
|
+
can :manage, Spree::Classification
|
34
|
+
can :manage, Spree::Image
|
35
|
+
can :manage, Spree::OptionType
|
36
|
+
can :manage, Spree::OptionValue
|
37
|
+
can :manage, Spree::Price
|
38
|
+
can :manage, Spree::Product
|
39
|
+
can :manage, Spree::ProductProperty
|
40
|
+
can :manage, Spree::Property
|
41
|
+
can :manage, Spree::Taxon
|
42
|
+
can :manage, Spree::Taxonomy
|
43
|
+
can :manage, Spree::Variant
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
module PermissionSets
|
5
|
+
# Read permissions for stock limited to allowed locations.
|
6
|
+
#
|
7
|
+
# This permission set allows users to view information about stock items and
|
8
|
+
# locations, both of them limited to locations they have access to.
|
9
|
+
# Permissions are also granted for the admin panel for items.
|
10
|
+
class RestrictedStockDisplay < PermissionSets::Base
|
11
|
+
class << self
|
12
|
+
def privilege
|
13
|
+
:display
|
14
|
+
end
|
15
|
+
|
16
|
+
def category
|
17
|
+
:restricted_stock
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def activate!
|
22
|
+
can [:read, :admin], Spree::StockItem, stock_location_id: location_ids
|
23
|
+
can :read, Spree::StockLocation, id: location_ids
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def location_ids
|
29
|
+
@ids ||= user.stock_locations.pluck(:id)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
module PermissionSets
|
5
|
+
# Full permissions for stock management limited to allowed locations.
|
6
|
+
#
|
7
|
+
# This permission set grants full control over all stock items a user has
|
8
|
+
# access to their locations. Those locations are also readable by the
|
9
|
+
# corresponding ability.
|
10
|
+
class RestrictedStockManagement < PermissionSets::Base
|
11
|
+
class << self
|
12
|
+
def privilege
|
13
|
+
:management
|
14
|
+
end
|
15
|
+
|
16
|
+
def category
|
17
|
+
:restricted_stock
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def activate!
|
22
|
+
can :manage, Spree::StockItem, stock_location_id: location_ids
|
23
|
+
can :read, Spree::StockLocation, id: location_ids
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def location_ids
|
29
|
+
@ids ||= user.stock_locations.pluck(:id)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
module PermissionSets
|
5
|
+
# Read-only permissions for stock.
|
6
|
+
#
|
7
|
+
# This permission set allows users to view information about stock items
|
8
|
+
# (also from the admin panel) and stock locations.
|
9
|
+
class StockDisplay < PermissionSets::Base
|
10
|
+
class << self
|
11
|
+
def privilege
|
12
|
+
:display
|
13
|
+
end
|
14
|
+
|
15
|
+
def category
|
16
|
+
:stock
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def activate!
|
21
|
+
can [:read, :admin], Spree::StockItem
|
22
|
+
can :read, Spree::StockLocation
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
module PermissionSets
|
5
|
+
# Full permissions for stock management.
|
6
|
+
#
|
7
|
+
# This permission set grants full control over all stock items and read
|
8
|
+
# access to locations.
|
9
|
+
class StockManagement < PermissionSets::Base
|
10
|
+
class << self
|
11
|
+
def privilege
|
12
|
+
:management
|
13
|
+
end
|
14
|
+
|
15
|
+
def category
|
16
|
+
:stock
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def activate!
|
21
|
+
can :manage, Spree::StockItem
|
22
|
+
can :read, Spree::StockLocation
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
module PermissionSets
|
5
|
+
# Full permissions for store administration.
|
6
|
+
#
|
7
|
+
# This permission set is always added to users with the `:admin` role.
|
8
|
+
#
|
9
|
+
# It grants permission to perform any read or write action on any resource.
|
10
|
+
class SuperUser < PermissionSets::Base
|
11
|
+
class << self
|
12
|
+
def privilege
|
13
|
+
:other
|
14
|
+
end
|
15
|
+
|
16
|
+
def category
|
17
|
+
:super_user
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def activate!
|
22
|
+
can :manage, :all
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
module PermissionSets
|
5
|
+
# Read-only permissions for users, roles and store credits.
|
6
|
+
#
|
7
|
+
# This permission set allows users to view all related information about
|
8
|
+
# users, roles and store credits, also from the admin panel.
|
9
|
+
class UserDisplay < PermissionSets::Base
|
10
|
+
class << self
|
11
|
+
def privilege
|
12
|
+
:display
|
13
|
+
end
|
14
|
+
|
15
|
+
def category
|
16
|
+
:user
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def activate!
|
21
|
+
can [:read, :admin, :edit, :addresses, :orders, :items], Spree.user_class
|
22
|
+
can [:read, :admin], Spree::StoreCredit
|
23
|
+
can :read, Spree::Role
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
module PermissionSets
|
5
|
+
# Full permissions for user management.
|
6
|
+
#
|
7
|
+
# This permission set grants full control over all user and
|
8
|
+
# related resources, including:
|
9
|
+
#
|
10
|
+
# - Users
|
11
|
+
# - Store credits
|
12
|
+
# - Roles
|
13
|
+
# - API keys
|
14
|
+
class UserManagement < PermissionSets::Base
|
15
|
+
class << self
|
16
|
+
def privilege
|
17
|
+
:management
|
18
|
+
end
|
19
|
+
|
20
|
+
def category
|
21
|
+
:user
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def activate!
|
26
|
+
can [:admin, :read, :create, :update, :save_in_address_book, :remove_from_address_book, :addresses, :orders, :items], Spree.user_class
|
27
|
+
|
28
|
+
# NOTE: This does not work with accessible_by.
|
29
|
+
# See https://github.com/solidusio/solidus/pull/1263
|
30
|
+
can :update_email, Spree.user_class do |user|
|
31
|
+
user.spree_roles.none?
|
32
|
+
end
|
33
|
+
can :update_password, Spree.user_class do |user|
|
34
|
+
user.spree_roles.none?
|
35
|
+
end
|
36
|
+
|
37
|
+
cannot :destroy, Spree.user_class
|
38
|
+
can :manage, Spree::StoreCredit
|
39
|
+
can :manage, :api_key
|
40
|
+
can :read, Spree::Role
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/app/models/spree/product.rb
CHANGED
@@ -32,6 +32,7 @@ module Spree
|
|
32
32
|
|
33
33
|
belongs_to :tax_category, class_name: 'Spree::TaxCategory', optional: true
|
34
34
|
belongs_to :shipping_category, class_name: 'Spree::ShippingCategory', inverse_of: :products, optional: true
|
35
|
+
belongs_to :primary_taxon, class_name: 'Spree::Taxon', optional: true
|
35
36
|
|
36
37
|
has_one :master,
|
37
38
|
-> { where(is_master: true).with_discarded },
|
@@ -84,6 +85,8 @@ module Spree
|
|
84
85
|
:track_inventory,
|
85
86
|
:weight,
|
86
87
|
:width,
|
88
|
+
:gtin,
|
89
|
+
:condition
|
87
90
|
]
|
88
91
|
MASTER_ATTRIBUTES.each do |attr|
|
89
92
|
delegate :"#{attr}", :"#{attr}=", to: :find_or_build_master
|
@@ -291,6 +294,10 @@ module Spree
|
|
291
294
|
@gallery ||= Spree::Config.product_gallery_class.new(self)
|
292
295
|
end
|
293
296
|
|
297
|
+
def brand
|
298
|
+
Spree::Config.brand_selector_class.new(self).call
|
299
|
+
end
|
300
|
+
|
294
301
|
private
|
295
302
|
|
296
303
|
def any_variants_not_track_inventory?
|
data/app/models/spree/refund.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
module Spree
|
4
4
|
class Refund < Spree::Base
|
5
|
+
include Metadata
|
6
|
+
|
5
7
|
belongs_to :payment, inverse_of: :refunds, optional: true
|
6
8
|
belongs_to :reason, class_name: 'Spree::RefundReason', foreign_key: :refund_reason_id, optional: true
|
7
9
|
belongs_to :reimbursement, inverse_of: :refunds, optional: true
|
@@ -4,6 +4,8 @@ module Spree
|
|
4
4
|
# Models the return of Inventory Units to a Stock Location for an Order.
|
5
5
|
#
|
6
6
|
class ReturnAuthorization < Spree::Base
|
7
|
+
include Metadata
|
8
|
+
|
7
9
|
belongs_to :order, class_name: 'Spree::Order', inverse_of: :return_authorizations, optional: true
|
8
10
|
|
9
11
|
has_many :return_items, inverse_of: :return_authorization, dependent: :destroy
|
@@ -4,6 +4,8 @@ module Spree
|
|
4
4
|
# An order's planned shipments including tracking and cost.
|
5
5
|
#
|
6
6
|
class Shipment < Spree::Base
|
7
|
+
include Metadata
|
8
|
+
|
7
9
|
belongs_to :order, class_name: 'Spree::Order', touch: true, inverse_of: :shipments, optional: true
|
8
10
|
belongs_to :stock_location, class_name: 'Spree::StockLocation', optional: true
|
9
11
|
|
@@ -85,8 +85,11 @@ module Spree
|
|
85
85
|
adjustments: []
|
86
86
|
)
|
87
87
|
|
88
|
+
permitted_attributes = Spree::PermittedAttributes.line_item_attributes.dup
|
89
|
+
permitted_attributes << { admin_metadata: {} } if options[:admin_metadata].present?
|
90
|
+
|
88
91
|
line_item.quantity += quantity.to_i
|
89
|
-
line_item.options = ActionController::Parameters.new(options).permit(
|
92
|
+
line_item.options = ActionController::Parameters.new(options).permit(permitted_attributes).to_h
|
90
93
|
|
91
94
|
line_item.target_shipment = options[:shipment]
|
92
95
|
line_item.save!
|
@@ -5,11 +5,22 @@ module Spree
|
|
5
5
|
module TaxHelpers
|
6
6
|
private
|
7
7
|
|
8
|
+
# Select active rates matching tax category and address
|
9
|
+
#
|
10
|
+
# @private
|
11
|
+
# @param [Spree::LineItem, Spree::Shipment, Spree::ShippingRate] item
|
12
|
+
# the line item, shipment, or shipping rate to select rates for
|
13
|
+
# @return [Array<Spree::TaxRate>] the active Tax Rates that match both
|
14
|
+
# Tax Category and the item's order's tax address
|
8
15
|
def rates_for_item(item)
|
9
16
|
@rates_for_item ||= Spree::TaxRate.item_level.for_address(item.order.tax_address)
|
17
|
+
# try is used here to ensure that a LineItem has rates selected for the
|
18
|
+
# currently configured Tax Category. Shipments and ShippingRates do not
|
19
|
+
# implement variant_tax_category_id, so try is necessary instead of .&
|
20
|
+
tax_category_id = item.try(:variant_tax_category_id) || item.tax_category_id
|
10
21
|
|
11
22
|
@rates_for_item.select do |rate|
|
12
|
-
rate.active? && rate.tax_categories.map(&:id).include?(
|
23
|
+
rate.active? && rate.tax_categories.map(&:id).include?(tax_category_id)
|
13
24
|
end
|
14
25
|
end
|
15
26
|
end
|
@@ -99,7 +99,7 @@ module Spree
|
|
99
99
|
# @return [Array<Spree::TaxRate>] rates that apply to an order
|
100
100
|
def rates_for_order
|
101
101
|
tax_category_ids = Set[
|
102
|
-
*@order.line_items.map(&:
|
102
|
+
*@order.line_items.map(&:variant_tax_category_id),
|
103
103
|
*@order.shipments.map(&:tax_category_id)
|
104
104
|
]
|
105
105
|
rates = Spree::TaxRate.active.order_level.for_address(@order.tax_address)
|
data/app/models/spree/taxon.rb
CHANGED
@@ -4,6 +4,9 @@ require 'spree/core/product_filters'
|
|
4
4
|
|
5
5
|
module Spree
|
6
6
|
class Taxon < Spree::Base
|
7
|
+
extend FriendlyId
|
8
|
+
friendly_id :permalink, use: :history, slug_column: :permalink
|
9
|
+
|
7
10
|
acts_as_nested_set dependent: :destroy
|
8
11
|
|
9
12
|
belongs_to :taxonomy, class_name: 'Spree::Taxonomy', inverse_of: :taxons
|
@@ -13,8 +16,7 @@ module Spree
|
|
13
16
|
has_many :promotion_rule_taxons
|
14
17
|
has_many :promotion_rules, through: :promotion_rule_taxons
|
15
18
|
|
16
|
-
|
17
|
-
before_update :set_permalink
|
19
|
+
before_save :set_permalink
|
18
20
|
after_update :update_child_permalinks, if: :saved_change_to_permalink?
|
19
21
|
|
20
22
|
validates :name, presence: true
|
@@ -121,6 +123,24 @@ module Spree
|
|
121
123
|
end
|
122
124
|
end
|
123
125
|
|
126
|
+
# override for {FriendlyId::Slugged#should_generate_new_friendly_id?} method,
|
127
|
+
# to control exactly when new friendly ids are set or updated
|
128
|
+
def should_generate_new_friendly_id?
|
129
|
+
permalink_changed? || super
|
130
|
+
end
|
131
|
+
|
132
|
+
# override for {FriendlyId::Slugged#normalize_friendly_id} method,
|
133
|
+
# to control over the slug format
|
134
|
+
def normalize_friendly_id(value)
|
135
|
+
return '' if value.blank?
|
136
|
+
|
137
|
+
parts = value.to_s.split('/')
|
138
|
+
last_word = parts.pop
|
139
|
+
corrected_last_word = Spree::Config.taxon_url_parametizer_class.parameterize(last_word)
|
140
|
+
|
141
|
+
(parts << corrected_last_word).join('/')
|
142
|
+
end
|
143
|
+
|
124
144
|
private
|
125
145
|
|
126
146
|
def touch_ancestors_and_taxonomy
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
class TaxonBrandSelector
|
5
|
+
BRANDS_TAXONOMY_NAME = "Brands"
|
6
|
+
|
7
|
+
def initialize(product)
|
8
|
+
@product = product
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
product.taxons
|
13
|
+
.joins(:taxonomy)
|
14
|
+
.where(spree_taxonomies: { name: BRANDS_TAXONOMY_NAME })
|
15
|
+
.first
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
attr_reader :product
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
# This service object is responsible for handling unauthorized redirects
|
5
|
+
class UnauthorizedRedirectHandler
|
6
|
+
# @param controller [ApplicationController] an instance of ApplicationController
|
7
|
+
# or its subclasses.
|
8
|
+
def initialize(controller)
|
9
|
+
@controller = controller
|
10
|
+
end
|
11
|
+
|
12
|
+
# This method is responsible for handling unauthorized redirects
|
13
|
+
def call
|
14
|
+
flash[:error] = I18n.t('spree.authorization_failure')
|
15
|
+
redirect_back(fallback_location: "/unauthorized")
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
attr_reader :controller
|
21
|
+
|
22
|
+
delegate :flash, :redirect_back, to: :controller
|
23
|
+
end
|
24
|
+
end
|
@@ -6,7 +6,7 @@ module Spree
|
|
6
6
|
belongs_to :address, class_name: "Spree::Address", optional: true
|
7
7
|
|
8
8
|
validates_uniqueness_of :address_id, scope: :user_id
|
9
|
-
validates_uniqueness_of :user_id, conditions: -> {
|
9
|
+
validates_uniqueness_of :user_id, conditions: -> { default_shipping }, message: :default_address_exists, if: :default?
|
10
10
|
|
11
11
|
scope :with_address_values, ->(address_attributes) do
|
12
12
|
joins(:address).merge(
|
@@ -14,10 +14,16 @@ module Spree
|
|
14
14
|
)
|
15
15
|
end
|
16
16
|
|
17
|
-
scope :all_historical, -> {
|
17
|
+
scope :all_historical, -> {
|
18
|
+
Spree::Deprecation.warn("This scope does not do anything and will be removed from Solidus 5.")
|
19
|
+
all
|
20
|
+
}
|
18
21
|
scope :default_shipping, -> { where(default: true) }
|
19
22
|
scope :default_billing, -> { where(default_billing: true) }
|
20
|
-
scope :active, -> {
|
23
|
+
scope :active, -> {
|
24
|
+
Spree::Deprecation.warn("This scope does not do anything and will be removed from Solidus 5.")
|
25
|
+
all
|
26
|
+
}
|
21
27
|
|
22
28
|
default_scope -> { order([default: :desc, updated_at: :desc]) }
|
23
29
|
end
|
data/app/models/spree/variant.rb
CHANGED
@@ -28,6 +28,10 @@ module Spree
|
|
28
28
|
attr_writer :rebuild_vat_prices
|
29
29
|
include Spree::DefaultPrice
|
30
30
|
|
31
|
+
# Consider that not all platforms digest structured data in the same way,
|
32
|
+
# you might have to modify the output on the frontend or in feeds accordingly.
|
33
|
+
enum :condition, { damaged: "damaged", new: "new", refurbished: "refurbished", used: "used" }, prefix: true
|
34
|
+
|
31
35
|
belongs_to :product, -> { with_discarded }, touch: true, class_name: 'Spree::Product', inverse_of: :variants_including_master, optional: false
|
32
36
|
belongs_to :tax_category, class_name: 'Spree::TaxCategory', optional: true
|
33
37
|
belongs_to :shipping_category, class_name: "Spree::ShippingCategory", optional: true
|
@@ -35,7 +39,7 @@ module Spree
|
|
35
39
|
delegate :name, :description, :slug, :available_on, :discontinue_on, :discontinued?,
|
36
40
|
:meta_description, :meta_keywords,
|
37
41
|
to: :product
|
38
|
-
delegate :tax_category, to: :product, prefix: true
|
42
|
+
delegate :tax_category, :tax_category_id, to: :product, prefix: true
|
39
43
|
delegate :shipping_category, :shipping_category_id,
|
40
44
|
to: :product, prefix: true
|
41
45
|
delegate :tax_rates, to: :tax_category
|
@@ -150,6 +154,15 @@ module Spree
|
|
150
154
|
super || product_tax_category
|
151
155
|
end
|
152
156
|
|
157
|
+
# @return [Integer] the variant's tax category ID
|
158
|
+
#
|
159
|
+
# This returns the product's tax category ID if the tax category ID on the variant is nil. It looks
|
160
|
+
# like an association, but really is an override.
|
161
|
+
#
|
162
|
+
def tax_category_id
|
163
|
+
super || product_tax_category_id
|
164
|
+
end
|
165
|
+
|
153
166
|
# @return [Spree::ShippingCategory] the variant's shipping category
|
154
167
|
#
|
155
168
|
# This returns the product's shipping category if the shipping category ID on the variant is nil. It looks
|
data/config/locales/en.yml
CHANGED
@@ -166,11 +166,13 @@ en:
|
|
166
166
|
variant: Variant
|
167
167
|
spree/product:
|
168
168
|
available_on: Available On
|
169
|
+
condition: Master Condition
|
169
170
|
cost_currency: Cost Currency
|
170
171
|
cost_price: Cost Price
|
171
172
|
depth: Depth
|
172
173
|
description: Description
|
173
174
|
discontinue_on: Discontinue on
|
175
|
+
gtin: Master GTIN
|
174
176
|
height: Height
|
175
177
|
master_price: Master Price
|
176
178
|
meta_description: Meta Description
|
@@ -179,6 +181,8 @@ en:
|
|
179
181
|
name: Name
|
180
182
|
on_hand: On Hand
|
181
183
|
price: Master Price
|
184
|
+
primary_taxon: Primary Taxon
|
185
|
+
primary_taxon_id: Primary Taxon
|
182
186
|
promotionable: Promotable
|
183
187
|
shipping_category: Shipping Category
|
184
188
|
sku: Master SKU
|
@@ -416,9 +420,11 @@ en:
|
|
416
420
|
password_confirmation: Password Confirmation
|
417
421
|
spree_roles: Roles
|
418
422
|
spree/variant:
|
423
|
+
condition: Condition
|
419
424
|
cost_currency: Cost Currency
|
420
425
|
cost_price: Cost Price
|
421
426
|
depth: Depth
|
427
|
+
gtin: GTIN
|
422
428
|
height: Height
|
423
429
|
price: Price
|
424
430
|
shipping_category: Variant Shipping Category
|
@@ -1075,6 +1081,8 @@ en:
|
|
1075
1081
|
billing: Billing
|
1076
1082
|
billing_address: Billing Address
|
1077
1083
|
both: Both
|
1084
|
+
brand: Brand
|
1085
|
+
brands: Brands
|
1078
1086
|
calculated_reimbursements: Calculated Reimbursements
|
1079
1087
|
calculator: Calculator
|
1080
1088
|
calculator_settings_warning: If you are changing the calculator type or preference source, you must save first before you can edit the calculator settings
|
@@ -1130,6 +1138,11 @@ en:
|
|
1130
1138
|
company: Company
|
1131
1139
|
complete: complete
|
1132
1140
|
complete_order: Complete Order
|
1141
|
+
condition:
|
1142
|
+
damaged: Damaged
|
1143
|
+
new: New
|
1144
|
+
refurbished: Refurbished
|
1145
|
+
used: Used
|
1133
1146
|
configuration: Configuration
|
1134
1147
|
configurations: Configurations
|
1135
1148
|
confirm: Confirm
|
@@ -2311,6 +2324,7 @@ en:
|
|
2311
2324
|
unfinalize_all_adjustments: Unfinalize All Adjustments
|
2312
2325
|
unlock: Unlock
|
2313
2326
|
unrecognized_card_type: Unrecognized Card Type
|
2327
|
+
unset: Unset
|
2314
2328
|
unshippable_items: Unshippable Items
|
2315
2329
|
update: Update
|
2316
2330
|
updated_successfully: Updated Successfully
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class RemoveArchivedUserAddresses < ActiveRecord::Migration[5.2]
|
4
|
+
def up
|
5
|
+
Spree::UserAddress.where(archived: true).delete_all
|
6
|
+
remove_column :spree_user_addresses, :archived, :boolean, default: false
|
7
|
+
end
|
8
|
+
|
9
|
+
def down
|
10
|
+
add_column :spree_user_addresses, :archived, :boolean, default: false
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class AddMetadataToSpreeResources < ActiveRecord::Migration[7.2]
|
4
|
+
def change
|
5
|
+
# List of Resources to add metadata columns to
|
6
|
+
%i[
|
7
|
+
spree_orders
|
8
|
+
spree_line_items
|
9
|
+
spree_shipments
|
10
|
+
spree_payments
|
11
|
+
spree_refunds
|
12
|
+
spree_customer_returns
|
13
|
+
spree_store_credit_events
|
14
|
+
spree_users
|
15
|
+
spree_return_authorizations
|
16
|
+
].each do |table_name|
|
17
|
+
change_table table_name do |t|
|
18
|
+
# Check if the database supports jsonb for efficient querying
|
19
|
+
if t.respond_to?(:jsonb)
|
20
|
+
add_column table_name, :customer_metadata, :jsonb, default: {}
|
21
|
+
add_column table_name, :admin_metadata, :jsonb, default: {}
|
22
|
+
else
|
23
|
+
add_column table_name, :customer_metadata, :json
|
24
|
+
add_column table_name, :admin_metadata, :json
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -9,11 +9,6 @@ initializer 'spree_authentication.rb', <<~RUBY
|
|
9
9
|
nil
|
10
10
|
end
|
11
11
|
end
|
12
|
-
|
13
|
-
# Re-raise the original authorization error on anauthorized access
|
14
|
-
Rails.application.config.to_prepare do
|
15
|
-
Spree::BaseController.unauthorized_redirect = -> { raise "Define the behavior for unauthorized access in \#{__FILE__}." }
|
16
|
-
end
|
17
12
|
RUBY
|
18
13
|
|
19
14
|
create_file 'app/views/spree/admin/shared/_navigation_footer.html.erb', <<~ERB
|