spree_core 4.2.0.rc2 → 4.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/spree.js +20 -0
- data/app/controllers/spree/base_controller.rb +2 -3
- data/app/controllers/spree/errors_controller.rb +11 -0
- data/app/finders/spree/addresses/find.rb +1 -12
- data/app/finders/spree/base_finder.rb +14 -0
- data/app/finders/spree/countries/find.rb +11 -3
- data/app/finders/spree/credit_cards/find.rb +2 -2
- data/app/finders/spree/orders/find_current.rb +2 -2
- data/app/finders/spree/products/find.rb +14 -3
- data/app/helpers/spree/base_helper.rb +3 -8
- data/app/helpers/spree/currency_helper.rb +34 -0
- data/app/helpers/spree/locale_helper.rb +31 -0
- data/app/helpers/spree/products_helper.rb +37 -12
- data/app/mailers/spree/base_mailer.rb +4 -4
- data/app/mailers/spree/order_mailer.rb +3 -3
- data/app/mailers/spree/reimbursement_mailer.rb +1 -1
- data/app/mailers/spree/shipment_mailer.rb +1 -1
- data/app/models/concerns/spree/default_price.rb +1 -5
- data/app/models/concerns/spree/product_scopes.rb +1 -1
- data/app/models/concerns/spree/user_methods.rb +2 -2
- data/app/models/concerns/spree/user_payment_source.rb +1 -1
- data/app/models/spree/ability.rb +45 -34
- data/app/models/spree/address.rb +4 -0
- data/app/models/spree/app_configuration.rb +2 -2
- data/app/models/spree/app_dependencies.rb +6 -2
- data/app/models/spree/base.rb +5 -0
- data/app/models/spree/credit_card.rb +4 -0
- data/app/models/spree/fulfilment_changer.rb +58 -16
- data/app/models/spree/image.rb +14 -14
- data/app/models/spree/inventory_unit.rb +2 -7
- data/app/models/spree/line_item.rb +7 -15
- data/app/models/spree/order.rb +1 -0
- data/app/models/spree/payment.rb +18 -4
- data/app/models/spree/payment/processing.rb +2 -2
- data/app/models/spree/payment_method.rb +3 -3
- data/app/models/spree/price.rb +2 -7
- data/app/models/spree/product.rb +41 -17
- data/app/models/spree/promotion/rules/option_value.rb +1 -1
- data/app/models/spree/promotion/rules/product.rb +2 -1
- data/app/models/spree/promotion/rules/user.rb +2 -1
- data/app/models/spree/refund.rb +2 -2
- data/app/models/spree/return_item/eligibility_validator/default.rb +0 -2
- data/app/models/spree/return_item/eligibility_validator/{r_m_a_required.rb → rma_required.rb} +0 -0
- data/app/models/spree/shipment.rb +1 -1
- data/app/models/spree/shipping_method.rb +1 -5
- data/app/models/spree/shipping_rate.rb +2 -11
- data/app/models/spree/stock/availability_validator.rb +3 -4
- data/app/models/spree/stock_item.rb +1 -5
- data/app/models/spree/store.rb +55 -2
- data/app/models/spree/store_credit.rb +1 -1
- data/app/models/spree/variant.rb +9 -16
- data/app/models/spree/zone.rb +13 -4
- data/app/paginators/spree/shared/paginate.rb +8 -1
- data/app/presenters/spree/variant_presenter.rb +2 -5
- data/app/services/spree/account/addresses/create.rb +6 -1
- data/app/services/spree/account/addresses/{base.rb → helper.rb} +1 -3
- data/app/services/spree/account/addresses/update.rb +6 -1
- data/app/services/spree/build_localized_redirect_url.rb +101 -0
- data/app/services/spree/cart/estimate_shipping_rates.rb +1 -1
- data/app/services/spree/compare_line_items.rb +4 -2
- data/app/sorters/spree/base_sorter.rb +35 -0
- data/app/sorters/spree/orders/sort.rb +1 -37
- data/app/sorters/spree/products/sort.rb +9 -32
- data/app/validators/email_validator.rb +1 -1
- data/app/views/spree/errors/forbidden.html.erb +0 -0
- data/app/views/spree/errors/unauthorized.html.erb +0 -0
- data/app/views/spree/shared/_base_mailer_stylesheets.html.erb +13 -2
- data/app/views/spree/shared/_purchased_items_table.html.erb +15 -6
- data/app/views/spree/shared/purchased_items_table/_adjustment.html.erb +2 -2
- data/app/views/spree/shared/purchased_items_table/_line_item.html.erb +2 -2
- data/config/initializers/inflections.rb +3 -0
- data/config/initializers/rails61_fixes.rb +3 -0
- data/config/locales/en.yml +31 -60
- data/config/routes.rb +2 -1
- data/db/default/spree/stores.rb +1 -0
- data/db/default/spree/zones.rb +4 -1
- data/db/migrate/20130326175857_add_stock_location_to_rma.rb +1 -1
- data/db/migrate/20191017121054_add_supported_currencies_to_store.rb +1 -0
- data/db/migrate/20201012091259_add_filterable_column_to_spree_option_types.rb +6 -2
- data/db/migrate/20201127084048_add_default_country_kind_to_spree_zones.rb +5 -0
- data/db/migrate/20210112193440_remove_contact_email_from_spree_stores.rb +5 -0
- data/db/migrate/20210114182625_create_spree_payment_methods_stores.rb +10 -0
- data/db/migrate/20210114220232_migrate_data_payment_methods_stores.rb +15 -0
- data/db/migrate/20210117112551_remove_store_id_from_spree_payment_methods.rb +5 -0
- data/db/migrate/20210120142527_ensure_default_locale_in_spree_stores.rb +5 -0
- data/db/migrate/20210205211040_add_supported_locales_to_spree_stores.rb +11 -0
- data/db/migrate/20210215202602_migrate_spree_i18n_globalize_config.rb +22 -0
- data/lib/generators/spree/install/install_generator.rb +9 -6
- data/lib/spree/core.rb +2 -1
- data/lib/spree/core/controller_helpers/auth.rb +3 -1
- data/lib/spree/core/controller_helpers/common.rb +6 -8
- data/lib/spree/core/controller_helpers/currency.rb +54 -0
- data/lib/spree/core/controller_helpers/locale.rb +58 -0
- data/lib/spree/core/controller_helpers/search.rb +1 -1
- data/lib/spree/core/controller_helpers/store.rb +4 -16
- data/lib/spree/core/product_filters.rb +3 -3
- data/lib/spree/core/version.rb +3 -1
- data/lib/spree/i18n.rb +17 -19
- data/lib/spree/permitted_attributes.rb +2 -2
- data/lib/spree/service_module.rb +8 -4
- data/lib/spree/testing_support/capybara_config.rb +1 -1
- data/lib/spree/testing_support/common_rake.rb +1 -1
- data/lib/spree/testing_support/controller_requests.rb +10 -10
- data/lib/spree/testing_support/factories/shipment_factory.rb +7 -9
- data/lib/spree/testing_support/factories/stock_location_factory.rb +2 -2
- data/lib/spree/testing_support/factories/store_factory.rb +1 -0
- data/lib/spree/testing_support/factories/zone_factory.rb +16 -13
- data/lib/spree/testing_support/flatpickr_capybara.rb +101 -0
- data/lib/spree/testing_support/locale_helpers.rb +78 -0
- data/lib/spree/testing_support/next_instance_of.rb +38 -0
- data/lib/spree/testing_support/order_walkthrough.rb +8 -3
- data/lib/spree/testing_support/rspec_retry_config.rb +10 -0
- data/spree_core.gemspec +5 -4
- metadata +71 -26
- data/lib/generators/spree/install/templates/config/initializers/spree_storefront.rb +0 -1
- data/lib/generators/spree/install/templates/config/spree_storefront.yml +0 -67
- data/lib/spree/core/controller_helpers/currency_helpers.rb +0 -15
- data/lib/spree/i18n/base.rb +0 -17
- data/lib/spree/i18n/initializer.rb +0 -1
@@ -4,7 +4,7 @@ module Spree
|
|
4
4
|
|
5
5
|
included do
|
6
6
|
has_one :default_price,
|
7
|
-
-> { where
|
7
|
+
-> { with_deleted.where(currency: Spree::Config[:currency]) },
|
8
8
|
class_name: 'Spree::Price',
|
9
9
|
dependent: :destroy
|
10
10
|
|
@@ -14,10 +14,6 @@ module Spree
|
|
14
14
|
|
15
15
|
after_save :save_default_price
|
16
16
|
|
17
|
-
def default_price
|
18
|
-
Spree::Price.unscoped { super }
|
19
|
-
end
|
20
|
-
|
21
17
|
def has_default_price?
|
22
18
|
!default_price.nil?
|
23
19
|
end
|
@@ -31,7 +31,7 @@ module Spree
|
|
31
31
|
self.whitelisted_ransackable_attributes = %w[id email]
|
32
32
|
|
33
33
|
def self.with_email(query)
|
34
|
-
where(
|
34
|
+
where("#{table_name}.email LIKE ?", "%#{query}%")
|
35
35
|
end
|
36
36
|
|
37
37
|
def self.with_address(query, address = :ship_address)
|
@@ -42,7 +42,7 @@ module Spree
|
|
42
42
|
|
43
43
|
def self.with_email_or_address(email, address)
|
44
44
|
left_outer_joins(:addresses).
|
45
|
-
where("#{Spree::Address.table_name}.firstname LIKE ? or #{Spree::Address.table_name}.lastname LIKE ? or email LIKE ?",
|
45
|
+
where("#{Spree::Address.table_name}.firstname LIKE ? or #{Spree::Address.table_name}.lastname LIKE ? or #{table_name}.email LIKE ?",
|
46
46
|
"%#{address}%", "%#{address}%", "%#{email}%")
|
47
47
|
end
|
48
48
|
end
|
data/app/models/spree/ability.rb
CHANGED
@@ -23,59 +23,70 @@ module Spree
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def initialize(user)
|
26
|
-
|
27
|
-
alias_action :delete, to: :destroy
|
28
|
-
alias_action :create, :update, :destroy, to: :modify
|
26
|
+
alias_cancan_delete_action
|
29
27
|
|
30
28
|
user ||= Spree.user_class.new
|
31
29
|
|
32
30
|
if user.respond_to?(:has_spree_role?) && user.has_spree_role?('admin')
|
33
|
-
|
31
|
+
apply_admin_permissions(user)
|
34
32
|
else
|
35
|
-
|
36
|
-
can :read, OptionType
|
37
|
-
can :read, OptionValue
|
38
|
-
can :create, Order
|
39
|
-
can :show, Order do |order, token|
|
40
|
-
order.user == user || order.token && token == order.token
|
41
|
-
end
|
42
|
-
can :update, Order do |order, token|
|
43
|
-
!order.completed? && (order.user == user || order.token && token == order.token)
|
44
|
-
end
|
45
|
-
can :manage, Spree::Address do |address|
|
46
|
-
address.user == user
|
47
|
-
end
|
48
|
-
can :create, Spree::Address do |_address|
|
49
|
-
user.id.present?
|
50
|
-
end
|
51
|
-
can :read, CreditCard, user_id: user.id
|
52
|
-
can :read, Product
|
53
|
-
can :read, ProductProperty
|
54
|
-
can :read, Property
|
55
|
-
can :create, Spree.user_class
|
56
|
-
can [:show, :update, :destroy], Spree.user_class, id: user.id
|
57
|
-
can :read, State
|
58
|
-
can :read, Taxon
|
59
|
-
can :read, Taxonomy
|
60
|
-
can :read, Variant
|
61
|
-
can :read, Zone
|
33
|
+
apply_user_permissions(user)
|
62
34
|
end
|
63
35
|
|
64
36
|
# Include any abilities registered by extensions, etc.
|
37
|
+
# this is legacy behaviour and should be removed in Spree 5.0
|
65
38
|
Ability.abilities.merge(abilities_to_register).each do |clazz|
|
66
39
|
merge clazz.new(user)
|
67
40
|
end
|
68
41
|
|
69
|
-
|
70
|
-
cannot [:update, :destroy], Role, name: ['admin']
|
42
|
+
protect_admin_role
|
71
43
|
end
|
72
44
|
|
73
|
-
|
45
|
+
protected
|
74
46
|
|
75
47
|
# you can override this method to register your abilities
|
76
48
|
# this method has to return array of classes
|
77
49
|
def abilities_to_register
|
78
50
|
[]
|
79
51
|
end
|
52
|
+
|
53
|
+
def alias_cancan_delete_action
|
54
|
+
alias_action :delete, to: :destroy
|
55
|
+
alias_action :create, :update, :destroy, to: :modify
|
56
|
+
end
|
57
|
+
|
58
|
+
def apply_admin_permissions(user)
|
59
|
+
can :manage, :all
|
60
|
+
end
|
61
|
+
|
62
|
+
def apply_user_permissions(user)
|
63
|
+
can :read, ::Spree::Country
|
64
|
+
can :read, ::Spree::OptionType
|
65
|
+
can :read, ::Spree::OptionValue
|
66
|
+
can :create, ::Spree::Order
|
67
|
+
can :show, ::Spree::Order do |order, token|
|
68
|
+
order.user == user || order.token && token == order.token
|
69
|
+
end
|
70
|
+
can :update, ::Spree::Order do |order, token|
|
71
|
+
!order.completed? && (order.user == user || order.token && token == order.token)
|
72
|
+
end
|
73
|
+
can :manage, ::Spree::Address, user_id: user.id
|
74
|
+
can :read, ::Spree::CreditCard, user_id: user.id
|
75
|
+
can :read, ::Spree::Product
|
76
|
+
can :read, ::Spree::ProductProperty
|
77
|
+
can :read, ::Spree::Property
|
78
|
+
can :create, ::Spree.user_class
|
79
|
+
can [:show, :update, :destroy], ::Spree.user_class, id: user.id
|
80
|
+
can :read, ::Spree::State
|
81
|
+
can :read, ::Spree::Store
|
82
|
+
can :read, ::Spree::Taxon
|
83
|
+
can :read, ::Spree::Taxonomy
|
84
|
+
can :read, ::Spree::Variant
|
85
|
+
can :read, ::Spree::Zone
|
86
|
+
end
|
87
|
+
|
88
|
+
def protect_admin_role
|
89
|
+
cannot [:update, :destroy], ::Spree::Role, name: ['admin']
|
90
|
+
end
|
80
91
|
end
|
81
92
|
end
|
data/app/models/spree/address.rb
CHANGED
@@ -2,6 +2,10 @@ module Spree
|
|
2
2
|
class Address < Spree::Base
|
3
3
|
require 'twitter_cldr'
|
4
4
|
|
5
|
+
if Rails::VERSION::STRING >= '6.1'
|
6
|
+
serialize :preferences, Hash, default: {}
|
7
|
+
end
|
8
|
+
|
5
9
|
NO_ZIPCODE_ISO_CODES ||= [
|
6
10
|
'AO', 'AG', 'AW', 'BS', 'BZ', 'BJ', 'BM', 'BO', 'BW', 'BF', 'BI', 'CM', 'CF', 'KM', 'CG',
|
7
11
|
'CD', 'CK', 'CUW', 'CI', 'DJ', 'DM', 'GQ', 'ER', 'FJ', 'TF', 'GAB', 'GM', 'GH', 'GD', 'GN',
|
@@ -68,8 +68,8 @@ module Spree
|
|
68
68
|
preference :non_expiring_credit_types, :array, default: []
|
69
69
|
preference :credit_to_new_allocation, :boolean, default: false
|
70
70
|
|
71
|
-
# Multi
|
72
|
-
preference :
|
71
|
+
# Multi store configurations
|
72
|
+
preference :show_store_selector, :boolean, default: false
|
73
73
|
|
74
74
|
# searcher_class allows spree extension writers to provide their own Search class
|
75
75
|
def searcher_class
|
@@ -12,7 +12,8 @@ module Spree
|
|
12
12
|
:coupon_handler, :country_finder, :current_order_finder, :credit_card_finder,
|
13
13
|
:completed_order_finder, :order_sorter, :cart_compare_line_items_service, :collection_paginator, :products_sorter,
|
14
14
|
:products_finder, :taxon_finder, :line_item_by_variant_finder, :cart_estimate_shipping_rates_service,
|
15
|
-
:account_create_address_service, :account_update_address_service, :address_finder
|
15
|
+
:account_create_address_service, :account_update_address_service, :address_finder,
|
16
|
+
:collection_sorter, :error_handler
|
16
17
|
].freeze
|
17
18
|
|
18
19
|
attr_accessor *INJECTION_POINTS
|
@@ -51,7 +52,8 @@ module Spree
|
|
51
52
|
@checkout_get_shipping_rates_service = 'Spree::Checkout::GetShippingRates'
|
52
53
|
|
53
54
|
# sorter
|
54
|
-
@
|
55
|
+
@collection_sorter = 'Spree::BaseSorter'
|
56
|
+
@order_sorter = 'Spree::BaseSorter'
|
55
57
|
@products_sorter = 'Spree::Products::Sort'
|
56
58
|
|
57
59
|
# paginator
|
@@ -64,6 +66,8 @@ module Spree
|
|
64
66
|
# account
|
65
67
|
@account_create_address_service = 'Spree::Account::Addresses::Create'
|
66
68
|
@account_update_address_service = 'Spree::Account::Addresses::Update'
|
69
|
+
|
70
|
+
@error_handler = 'Spree::ErrorReporter'
|
67
71
|
end
|
68
72
|
|
69
73
|
def set_default_finders
|
data/app/models/spree/base.rb
CHANGED
@@ -36,7 +36,7 @@ module Spree
|
|
36
36
|
private
|
37
37
|
|
38
38
|
attr_reader :variant, :quantity, :current_stock_location, :desired_stock_location,
|
39
|
-
|
39
|
+
:current_shipment, :desired_shipment, :available_quantity
|
40
40
|
|
41
41
|
def handle_stock
|
42
42
|
ActiveRecord::Base.transaction do
|
@@ -45,13 +45,64 @@ module Spree
|
|
45
45
|
desired_stock_location.unstock(variant, unstock_quantity, desired_shipment)
|
46
46
|
end
|
47
47
|
|
48
|
-
|
49
|
-
|
48
|
+
move_inventory_units_between_shipments
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def move_inventory_units_between_shipments
|
53
|
+
update_desired_shipment_inventory_units
|
54
|
+
update_current_shipment_inventory_units
|
55
|
+
end
|
56
|
+
|
57
|
+
def current_shipment_units
|
58
|
+
@current_shipment_units ||= current_shipment.inventory_units.on_hand_or_backordered.where(variant_id: variant.id)
|
59
|
+
end
|
60
|
+
|
61
|
+
def update_desired_shipment_inventory_units
|
62
|
+
on_hand_unit = get_desired_shipment_inventory_unit(:on_hand)
|
63
|
+
on_hand_unit.update(quantity: on_hand_unit.quantity + new_on_hand_quantity)
|
64
|
+
|
65
|
+
new_backorder_quantity = current_on_hand_quantity - new_on_hand_quantity
|
66
|
+
if new_backorder_quantity > 0
|
67
|
+
backordered_unit = get_desired_shipment_inventory_unit(:backordered)
|
68
|
+
backordered_unit.update(quantity: backordered_unit.quantity + new_backorder_quantity)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def update_current_shipment_inventory_units
|
73
|
+
reduced_quantity = current_on_hand_quantity
|
74
|
+
|
75
|
+
# Reduce quantities from all backordered units first in case there is more than one.
|
76
|
+
backorder_units = current_shipment_units.backordered
|
77
|
+
reduced_quantity = reduce_units_quantities(reduced_quantity, backorder_units) if backorder_units.any?
|
78
|
+
|
79
|
+
# Reduce quantities from all on_hand units in case there is more than one.
|
80
|
+
if reduced_quantity > 0
|
81
|
+
on_hand_units = current_shipment_units.on_hand
|
82
|
+
reduce_units_quantities(reduced_quantity, on_hand_units) if on_hand_units.any?
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def reduce_units_quantities(reduced_quantity, units)
|
87
|
+
units.each do |unit|
|
88
|
+
unit.quantity > reduced_quantity ? unit.update(quantity: unit.quantity - reduced_quantity) : unit.destroy!
|
89
|
+
reduced_quantity -= unit.quantity
|
90
|
+
end
|
91
|
+
reduced_quantity
|
92
|
+
end
|
93
|
+
|
94
|
+
def get_desired_shipment_inventory_unit(state)
|
95
|
+
desired_shipment.inventory_units.find_or_create_by(state: state) do |unit|
|
96
|
+
current_shipment_unit = current_shipment_units.first
|
97
|
+
unit.variant_id = current_shipment_unit.variant_id
|
98
|
+
unit.order_id = current_shipment_unit.order_id
|
99
|
+
unit.line_item_id = current_shipment_unit.line_item_id
|
100
|
+
unit.quantity = 0
|
50
101
|
end
|
51
102
|
end
|
52
103
|
|
53
104
|
def after_process_shipments
|
54
|
-
if current_shipment.inventory_units.
|
105
|
+
if current_shipment.inventory_units.sum(:quantity).zero?
|
55
106
|
current_shipment.destroy!
|
56
107
|
else
|
57
108
|
current_shipment.refresh_rates
|
@@ -64,7 +115,7 @@ module Spree
|
|
64
115
|
end
|
65
116
|
|
66
117
|
def new_on_hand_quantity
|
67
|
-
[available_quantity,
|
118
|
+
[available_quantity, current_on_hand_quantity].min
|
68
119
|
end
|
69
120
|
|
70
121
|
def unstock_quantity
|
@@ -72,16 +123,7 @@ module Spree
|
|
72
123
|
end
|
73
124
|
|
74
125
|
def current_on_hand_quantity
|
75
|
-
[current_shipment.inventory_units.on_hand_or_backordered.
|
76
|
-
end
|
77
|
-
|
78
|
-
def update_current_shipment_inventory_units(quantity, state)
|
79
|
-
current_shipment.
|
80
|
-
inventory_units.
|
81
|
-
where(variant: variant).
|
82
|
-
order(state: :asc).
|
83
|
-
limit(quantity).
|
84
|
-
update_all(shipment_id: desired_shipment.id, state: state)
|
126
|
+
[current_shipment.inventory_units.on_hand_or_backordered.sum(:quantity), quantity].min
|
85
127
|
end
|
86
128
|
|
87
129
|
def reload_shipment_inventory_units
|
@@ -105,7 +147,7 @@ module Spree
|
|
105
147
|
def enough_stock_at_desired_location
|
106
148
|
return if Spree::Stock::Quantifier.new(variant, desired_stock_location).can_supply?(quantity)
|
107
149
|
|
108
|
-
errors.add(:desired_shipment, :
|
150
|
+
errors.add(:desired_shipment, :has_not_enough_stock_at_desired_location)
|
109
151
|
end
|
110
152
|
|
111
153
|
def desired_shipment_different_from_current
|
data/app/models/spree/image.rb
CHANGED
@@ -15,13 +15,13 @@ module Spree
|
|
15
15
|
width, height = size.chop.split('x')
|
16
16
|
|
17
17
|
{
|
18
|
-
url: polymorphic_path(attachment.variant(
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
url: polymorphic_path(attachment.variant(
|
19
|
+
gravity: 'center',
|
20
|
+
resize: size,
|
21
|
+
extent: size,
|
22
|
+
background: 'snow2',
|
23
|
+
quality: 80
|
24
|
+
), only_path: true),
|
25
25
|
width: width,
|
26
26
|
height: height
|
27
27
|
}
|
@@ -35,13 +35,13 @@ module Spree
|
|
35
35
|
width, height = size.chop.split('x')
|
36
36
|
|
37
37
|
{
|
38
|
-
url: polymorphic_path(attachment.variant(
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
38
|
+
url: polymorphic_path(attachment.variant(
|
39
|
+
gravity: 'center',
|
40
|
+
resize: size,
|
41
|
+
extent: size,
|
42
|
+
background: 'snow2',
|
43
|
+
quality: 80
|
44
|
+
), only_path: true),
|
45
45
|
size: size,
|
46
46
|
width: width,
|
47
47
|
height: height
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module Spree
|
2
2
|
class InventoryUnit < Spree::Base
|
3
3
|
with_options inverse_of: :inventory_units do
|
4
|
-
belongs_to :variant, class_name: 'Spree::Variant'
|
4
|
+
belongs_to :variant, -> { with_deleted }, class_name: 'Spree::Variant'
|
5
5
|
belongs_to :order, class_name: 'Spree::Order'
|
6
6
|
belongs_to :shipment, class_name: 'Spree::Shipment', touch: true, optional: true
|
7
|
-
has_many :return_items
|
7
|
+
has_many :return_items, inverse_of: :inventory_unit
|
8
8
|
has_many :return_authorizations, class_name: 'Spree::ReturnAuthorization', through: :return_items
|
9
9
|
belongs_to :line_item, class_name: 'Spree::LineItem'
|
10
10
|
end
|
@@ -84,11 +84,6 @@ module Spree
|
|
84
84
|
split_inventory!(1)
|
85
85
|
end
|
86
86
|
|
87
|
-
# Remove variant default_scope `deleted_at: nil`
|
88
|
-
def variant
|
89
|
-
Spree::Variant.unscoped { super }
|
90
|
-
end
|
91
|
-
|
92
87
|
def current_or_new_return_item
|
93
88
|
Spree::ReturnItem.from_inventory_unit(self)
|
94
89
|
end
|
@@ -4,7 +4,7 @@ module Spree
|
|
4
4
|
|
5
5
|
with_options inverse_of: :line_items do
|
6
6
|
belongs_to :order, class_name: 'Spree::Order', touch: true
|
7
|
-
belongs_to :variant, class_name: 'Spree::Variant'
|
7
|
+
belongs_to :variant, -> { with_deleted }, class_name: 'Spree::Variant'
|
8
8
|
end
|
9
9
|
belongs_to :tax_category, class_name: 'Spree::TaxCategory'
|
10
10
|
|
@@ -57,16 +57,13 @@ module Spree
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def update_price
|
60
|
-
|
61
|
-
currency_price = Spree::Price.where(
|
62
|
-
currency: order.currency,
|
63
|
-
variant_id: variant_id
|
64
|
-
).first
|
60
|
+
currency_price = variant.price_in(order.currency)
|
65
61
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
62
|
+
self.price = if currency_price.amount.present?
|
63
|
+
currency_price.price_including_vat_for(tax_zone: tax_zone)
|
64
|
+
else
|
65
|
+
0
|
66
|
+
end
|
70
67
|
end
|
71
68
|
|
72
69
|
def copy_tax_category
|
@@ -120,11 +117,6 @@ module Spree
|
|
120
117
|
assign_attributes opts
|
121
118
|
end
|
122
119
|
|
123
|
-
# Remove variant default_scope `deleted_at: nil`
|
124
|
-
def variant
|
125
|
-
Spree::Variant.unscoped { super }
|
126
|
-
end
|
127
|
-
|
128
120
|
private
|
129
121
|
|
130
122
|
def ensure_valid_quantity
|