spree_core 3.6.6 → 3.7.0.rc1
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 +60 -0
- data/app/finders/spree/countries/find.rb +31 -0
- data/app/finders/spree/credit_cards/find.rb +12 -0
- data/app/finders/spree/line_items/find_by_variant.rb +13 -0
- data/app/finders/spree/orders/find_current.rb +34 -0
- data/app/finders/spree/products/find.rb +93 -0
- data/app/finders/spree/taxons/find.rb +79 -0
- data/app/helpers/spree/base_helper.rb +7 -3
- data/app/helpers/spree/products_helper.rb +2 -1
- data/app/models/concerns/spree/adjustment_source.rb +11 -6
- data/app/models/concerns/spree/user_address.rb +2 -2
- data/app/models/concerns/spree/vat_price_calculation.rb +2 -1
- data/app/models/spree/ability.rb +2 -2
- data/app/models/spree/address.rb +23 -14
- data/app/models/spree/adjustable/adjustments_updater.rb +1 -1
- data/app/models/spree/adjustable/promotion_accumulator.rb +2 -1
- data/app/models/spree/adjustment.rb +18 -3
- data/app/models/spree/asset/support/active_storage.rb +1 -1
- data/app/models/spree/calculator.rb +1 -4
- data/app/models/spree/calculator/flexi_rate.rb +8 -11
- data/app/models/spree/calculator/returns/default_refund_amount.rb +3 -1
- data/app/models/spree/calculator/shipping/flexi_rate.rb +13 -13
- data/app/models/spree/country.rb +4 -0
- data/app/models/spree/credit_card.rb +8 -2
- data/app/models/spree/customer_return.rb +1 -0
- data/app/models/spree/fulfilment_changer.rb +117 -0
- data/app/models/spree/gateway.rb +1 -0
- data/app/models/spree/gateway/bogus.rb +3 -2
- data/app/models/spree/image.rb +13 -0
- data/app/models/spree/image/configuration/active_storage.rb +3 -3
- data/app/models/spree/inventory_unit.rb +1 -1
- data/app/models/spree/line_item.rb +3 -2
- data/app/models/spree/order.rb +72 -28
- data/app/models/spree/order/checkout.rb +10 -0
- data/app/models/spree/order/store_credit.rb +14 -35
- data/app/models/spree/order_contents.rb +22 -118
- data/app/models/spree/order_inventory.rb +6 -2
- data/app/models/spree/order_merger.rb +1 -3
- data/app/models/spree/order_promotion.rb +10 -0
- data/app/models/spree/order_updater.rb +11 -8
- data/app/models/spree/payment.rb +9 -3
- data/app/models/spree/payment/processing.rb +4 -4
- data/app/models/spree/preferences/store.rb +3 -3
- data/app/models/spree/product.rb +32 -0
- data/app/models/spree/product/scopes.rb +13 -34
- data/app/models/spree/product_property.rb +1 -1
- data/app/models/spree/promotion.rb +2 -0
- data/app/models/spree/promotion/actions/create_adjustment.rb +6 -1
- data/app/models/spree/promotion/actions/create_item_adjustments.rb +10 -2
- data/app/models/spree/promotion/actions/create_line_items.rb +3 -2
- data/app/models/spree/promotion/actions/free_shipping.rb +1 -0
- data/app/models/spree/promotion/rules/item_total.rb +2 -2
- data/app/models/spree/promotion_handler/coupon.rb +10 -6
- data/app/models/spree/promotion_handler/page.rb +1 -1
- data/app/models/spree/promotion_handler/promotion_duplicator.rb +4 -4
- data/app/models/spree/refund.rb +1 -1
- data/app/models/spree/reimbursement/reimbursement_type_engine.rb +1 -0
- data/app/models/spree/reimbursement_tax_calculator.rb +2 -2
- data/app/models/spree/return_item.rb +7 -4
- data/app/models/spree/return_item/eligibility_validator/default.rb +6 -6
- data/app/models/spree/return_item/exchange_variant_eligibility/same_product.rb +1 -1
- data/app/models/spree/shipment.rb +27 -34
- data/app/models/spree/shipping_method.rb +2 -0
- data/app/models/spree/shipping_rate.rb +31 -16
- data/app/models/spree/stock/adjuster.rb +1 -0
- data/app/models/spree/stock/estimator.rb +2 -0
- data/app/models/spree/stock/inventory_unit_builder.rb +5 -5
- data/app/models/spree/stock/packer.rb +1 -0
- data/app/models/spree/stock/quantifier.rb +16 -4
- data/app/models/spree/stock_item.rb +1 -0
- data/app/models/spree/stock_location.rb +1 -1
- data/app/models/spree/stock_movement.rb +1 -0
- data/app/models/spree/stock_transfer.rb +1 -1
- data/app/models/spree/store_credit.rb +5 -10
- data/app/models/spree/tax_rate.rb +3 -0
- data/app/models/spree/taxon.rb +2 -2
- data/app/models/spree/taxon_image.rb +18 -0
- data/app/models/spree/{taxon_icon → taxon_image}/configuration/active_storage.rb +2 -2
- data/app/models/spree/{taxon_icon → taxon_image}/configuration/paperclip.rb +1 -1
- data/app/models/spree/variant.rb +28 -2
- data/app/models/spree/zone.rb +5 -5
- data/app/paginators/spree/shared/paginate.rb +19 -0
- data/app/services/spree/cart/add_item.rb +43 -0
- data/app/services/spree/cart/create.rb +21 -0
- data/app/services/spree/cart/recalculate.rb +32 -0
- data/app/services/spree/cart/remove_item.rb +37 -0
- data/app/services/spree/cart/remove_line_item.rb +16 -0
- data/app/services/spree/cart/set_quantity.rb +22 -0
- data/app/services/spree/cart/update.rb +37 -0
- data/app/services/spree/checkout/add_store_credit.rb +51 -0
- data/app/services/spree/checkout/advance.rb +18 -0
- data/app/services/spree/checkout/complete.rb +23 -0
- data/app/services/spree/checkout/get_shipping_rates.rb +48 -0
- data/app/services/spree/checkout/next.rb +13 -0
- data/app/services/spree/checkout/remove_store_credit.rb +17 -0
- data/app/services/spree/checkout/update.rb +13 -0
- data/app/services/spree/compare_line_items.rb +21 -0
- data/app/services/spree/generate_token.rb +20 -0
- data/app/sorters/spree/products/sort.rb +58 -0
- data/config/locales/en.yml +20 -1
- data/db/default/spree/countries.rb +1 -1
- data/db/default/spree/default_reimbursement_type.rb +1 -1
- data/db/default/spree/roles.rb +2 -2
- data/db/default/spree/states.rb +2 -1
- data/db/default/spree/stores.rb +1 -1
- data/db/default/spree/zones.rb +5 -6
- data/db/migrate/20120831092320_spree_one_two.rb +36 -36
- data/db/migrate/20120831092359_spree_promo_one_two.rb +1 -1
- data/db/migrate/20130211190146_create_spree_stock_items.rb +1 -1
- data/db/migrate/20130211191120_create_spree_stock_locations.rb +1 -1
- data/db/migrate/20130301162924_create_shipping_method_categories.rb +1 -1
- data/db/migrate/20130304162240_create_spree_shipping_rates.rb +1 -1
- data/db/migrate/20130305143310_create_stock_movements.rb +1 -1
- data/db/migrate/20130418125341_create_spree_stock_transfers.rb +1 -1
- data/db/migrate/20140205120320_create_spree_payment_capture_events.rb +1 -1
- data/db/migrate/20140309023735_migrate_old_preferences.rb +5 -1
- data/db/migrate/20140309024355_create_spree_stores.rb +1 -1
- data/db/migrate/20140625214618_create_spree_refunds.rb +1 -1
- data/db/migrate/20140702140656_create_spree_return_authorization_inventory_unit.rb +1 -1
- data/db/migrate/20140713140455_create_spree_return_authorization_reasons.rb +1 -1
- data/db/migrate/20140713140527_create_spree_refund_reasons.rb +1 -1
- data/db/migrate/20140715182625_create_spree_promotion_categories.rb +1 -1
- data/db/migrate/20140718133010_create_spree_customer_returns.rb +1 -1
- data/db/migrate/20140725131539_create_spree_reimbursements.rb +1 -1
- data/db/migrate/20140731150017_create_spree_reimbursement_types.rb +1 -1
- data/db/migrate/20150118210639_create_spree_store_credits.rb +1 -1
- data/db/migrate/20150118211500_create_spree_store_credit_categories.rb +1 -1
- data/db/migrate/20150118212051_create_spree_store_credit_events.rb +1 -1
- data/db/migrate/20150118212101_create_spree_store_credit_types.rb +1 -1
- data/db/migrate/20150309161154_ensure_payments_have_numbers.rb +6 -2
- data/db/migrate/20180613080857_rename_guest_token_to_token_in_orders.rb +5 -0
- data/db/migrate/20180915160001_add_timestamps_to_spree_prices.rb +12 -0
- data/db/migrate/20181024100754_add_deleted_at_to_spree_credit_cards.rb +6 -0
- data/lib/generators/spree/custom_user/custom_user_generator.rb +1 -3
- data/lib/generators/spree/dummy/dummy_generator.rb +30 -33
- data/lib/generators/spree/dummy/templates/rails/database.yml +6 -1
- data/lib/generators/spree/dummy/templates/rails/test.rb +2 -0
- data/lib/generators/spree/dummy_model/dummy_model_generator.rb +1 -1
- data/lib/generators/spree/install/install_generator.rb +2 -1
- data/lib/spree/core.rb +2 -4
- data/lib/spree/core/controller_helpers/auth.rb +15 -5
- data/lib/spree/core/controller_helpers/common.rb +0 -11
- data/lib/spree/core/controller_helpers/order.rb +6 -6
- data/lib/spree/core/controller_helpers/respond_with.rb +3 -1
- data/lib/spree/core/controller_helpers/strong_parameters.rb +1 -0
- data/lib/spree/core/engine.rb +9 -3
- data/lib/spree/core/importer/order.rb +8 -12
- data/lib/spree/core/product_duplicator.rb +6 -1
- data/lib/spree/core/product_filters.rb +15 -14
- data/lib/spree/core/query_filters.rb +11 -0
- data/lib/spree/core/query_filters/comparable.rb +46 -0
- data/lib/spree/core/query_filters/date.rb +8 -0
- data/lib/spree/core/query_filters/number.rb +8 -0
- data/lib/spree/core/query_filters/text.rb +32 -0
- data/lib/spree/core/token_generator.rb +2 -2
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/i18n.rb +1 -1
- data/lib/spree/migrations.rb +2 -0
- data/lib/spree/money.rb +12 -12
- data/lib/spree/permitted_attributes.rb +11 -6
- data/lib/spree/service_module.rb +98 -0
- data/lib/spree/testing_support/capybara_config.rb +20 -0
- data/lib/spree/testing_support/capybara_ext.rb +6 -3
- data/lib/spree/testing_support/factories.rb +1 -1
- data/lib/spree/testing_support/factories/address_factory.rb +10 -9
- data/lib/spree/testing_support/factories/adjustment_factory.rb +8 -6
- data/lib/spree/testing_support/factories/country_factory.rb +4 -4
- data/lib/spree/testing_support/factories/credit_card_factory.rb +7 -5
- data/lib/spree/testing_support/factories/customer_return_factory.rb +1 -1
- data/lib/spree/testing_support/factories/image_factory.rb +7 -1
- data/lib/spree/testing_support/factories/inventory_unit_factory.rb +5 -4
- data/lib/spree/testing_support/factories/line_item_factory.rb +3 -2
- data/lib/spree/testing_support/factories/options_factory.rb +2 -3
- data/lib/spree/testing_support/factories/order_factory.rb +16 -12
- data/lib/spree/testing_support/factories/order_promotion_factory.rb +6 -0
- data/lib/spree/testing_support/factories/payment_factory.rb +9 -7
- data/lib/spree/testing_support/factories/payment_method_factory.rb +8 -8
- data/lib/spree/testing_support/factories/price_factory.rb +2 -2
- data/lib/spree/testing_support/factories/product_factory.rb +10 -10
- data/lib/spree/testing_support/factories/promotion_category_factory.rb +1 -1
- data/lib/spree/testing_support/factories/promotion_factory.rb +14 -4
- data/lib/spree/testing_support/factories/property_factory.rb +2 -2
- data/lib/spree/testing_support/factories/prototype_factory.rb +3 -3
- data/lib/spree/testing_support/factories/refund_factory.rb +6 -6
- data/lib/spree/testing_support/factories/reimbursement_factory.rb +1 -1
- data/lib/spree/testing_support/factories/reimbursement_type_factory.rb +2 -2
- data/lib/spree/testing_support/factories/return_authorization_factory.rb +4 -3
- data/lib/spree/testing_support/factories/role_factory.rb +1 -1
- data/lib/spree/testing_support/factories/shipment_factory.rb +3 -3
- data/lib/spree/testing_support/factories/shipping_method_factory.rb +4 -4
- data/lib/spree/testing_support/factories/state_factory.rb +2 -5
- data/lib/spree/testing_support/factories/stock_factory.rb +3 -3
- data/lib/spree/testing_support/factories/stock_item_factory.rb +1 -1
- data/lib/spree/testing_support/factories/stock_location_factory.rb +7 -7
- data/lib/spree/testing_support/factories/stock_movement_factory.rb +3 -3
- data/lib/spree/testing_support/factories/store_credit_category_factory.rb +2 -2
- data/lib/spree/testing_support/factories/store_credit_type_factory.rb +1 -1
- data/lib/spree/testing_support/factories/store_factory.rb +5 -4
- data/lib/spree/testing_support/factories/tax_rate_factory.rb +2 -1
- data/lib/spree/testing_support/factories/user_factory.rb +4 -4
- data/lib/spree/testing_support/factories/variant_factory.rb +15 -15
- data/lib/spree/testing_support/factories/zone_factory.rb +3 -3
- data/lib/spree/testing_support/image_helpers.rb +19 -0
- data/lib/tasks/core.rake +21 -4
- data/lib/tasks/exchanges.rake +4 -4
- data/spree_core.gemspec +3 -3
- data/vendor/assets/javascripts/fetch.umd.js +531 -0
- data/vendor/assets/javascripts/polyfill.min.js +1 -0
- metadata +50 -17
- data/app/assets/javascripts/spree.js.coffee +0 -59
- data/app/models/spree/taxon_icon.rb +0 -5
- data/lib/generators/spree/dummy/templates/initializers/custom_user.rb +0 -1
- data/lib/spree/core/environment.rb +0 -15
- data/lib/spree/core/environment/calculators.rb +0 -11
- data/lib/spree/core/environment_extension.rb +0 -28
- data/lib/spree/core/validators/email.rb +0 -8
- data/lib/spree/promo/environment.rb +0 -9
data/app/models/spree/ability.rb
CHANGED
@@ -44,10 +44,10 @@ module Spree
|
|
44
44
|
can :display, OptionValue
|
45
45
|
can :create, Order
|
46
46
|
can :read, Order do |order, token|
|
47
|
-
order.user == user || order.
|
47
|
+
order.user == user || order.token && token == order.token
|
48
48
|
end
|
49
49
|
can :update, Order do |order, token|
|
50
|
-
!order.completed? && (order.user == user || order.
|
50
|
+
!order.completed? && (order.user == user || order.token && token == order.token)
|
51
51
|
end
|
52
52
|
can :display, CreditCard, user_id: user.id
|
53
53
|
can :display, Product
|
data/app/models/spree/address.rb
CHANGED
@@ -29,6 +29,9 @@ module Spree
|
|
29
29
|
|
30
30
|
validate :state_validate, :postal_code_validate
|
31
31
|
|
32
|
+
delegate :name, :iso3, to: :country, prefix: true
|
33
|
+
delegate :abbr, to: :state, prefix: true, allow_nil: true
|
34
|
+
|
32
35
|
alias_attribute :first_name, :firstname
|
33
36
|
alias_attribute :last_name, :lastname
|
34
37
|
|
@@ -55,27 +58,37 @@ module Spree
|
|
55
58
|
end
|
56
59
|
|
57
60
|
def same_as?(other)
|
58
|
-
|
59
|
-
|
61
|
+
ActiveSupport::Deprecation.warn(<<-EOS, caller)
|
62
|
+
Address#same_as? is deprecated and will be removed in Spree 4.0. Please use Address#== instead"
|
63
|
+
EOS
|
64
|
+
|
65
|
+
self == other
|
60
66
|
end
|
61
67
|
|
62
|
-
|
68
|
+
def same_as(other)
|
69
|
+
ActiveSupport::Deprecation.warn(<<-EOS, caller)
|
70
|
+
Address#same_as is deprecated and will be removed in Spree 4.0. Please use Address#== instead"
|
71
|
+
EOS
|
72
|
+
|
73
|
+
self == other
|
74
|
+
end
|
63
75
|
|
64
76
|
def to_s
|
65
77
|
"#{full_name}: #{address1}"
|
66
78
|
end
|
67
79
|
|
68
80
|
def clone
|
69
|
-
self.class.new(
|
81
|
+
self.class.new(value_attributes)
|
70
82
|
end
|
71
83
|
|
72
|
-
def ==(
|
73
|
-
|
74
|
-
other_attrs = other_address.respond_to?(:attributes) ? other_address.attributes : {}
|
84
|
+
def ==(other)
|
85
|
+
return false unless other&.respond_to?(:value_attributes)
|
75
86
|
|
76
|
-
|
87
|
+
value_attributes == other.value_attributes
|
88
|
+
end
|
77
89
|
|
78
|
-
|
90
|
+
def value_attributes
|
91
|
+
attributes.except(*EXCLUDED_KEYS_FOR_COMPARISION)
|
79
92
|
end
|
80
93
|
|
81
94
|
def empty?
|
@@ -106,11 +119,6 @@ module Spree
|
|
106
119
|
|
107
120
|
private
|
108
121
|
|
109
|
-
def clear_state_entities
|
110
|
-
clear_state
|
111
|
-
clear_state_name
|
112
|
-
end
|
113
|
-
|
114
122
|
def clear_state
|
115
123
|
self.state = nil
|
116
124
|
end
|
@@ -132,6 +140,7 @@ module Spree
|
|
132
140
|
# or when disabled by preference
|
133
141
|
return if country.blank? || !Spree::Config[:address_requires_state]
|
134
142
|
return unless country.states_required
|
143
|
+
|
135
144
|
# ensure associated state belongs to country
|
136
145
|
if state.present?
|
137
146
|
if state.country == country
|
@@ -24,6 +24,7 @@ module Spree
|
|
24
24
|
|
25
25
|
def add_adjustment(adjustment, opts = {})
|
26
26
|
return unless adjustment.promotion?
|
27
|
+
|
27
28
|
source = opts[:source] || adjustment.source
|
28
29
|
promotion = opts[:promotion] || source.promotion
|
29
30
|
|
@@ -32,7 +33,7 @@ module Spree
|
|
32
33
|
add(promotions, promotion, source.promotion_id)
|
33
34
|
end
|
34
35
|
|
35
|
-
def promotions_adjustments(promotion_id, adjustments = adjustments)
|
36
|
+
def promotions_adjustments(promotion_id, adjustments = self.adjustments)
|
36
37
|
where(sources, promotion_id: promotion_id).map do |source|
|
37
38
|
where(adjustments, source_id: source.id)
|
38
39
|
end.flatten
|
@@ -48,8 +48,18 @@ module Spree
|
|
48
48
|
|
49
49
|
self.competing_promos_source_types = ['Spree::PromotionAction']
|
50
50
|
|
51
|
-
scope :open, -> {
|
52
|
-
|
51
|
+
scope :open, -> {
|
52
|
+
ActiveSupport::Deprecation.warn 'Adjustment.open is deprecated. Please use Adjustment.not_finalized instead', caller
|
53
|
+
not_finalized
|
54
|
+
}
|
55
|
+
|
56
|
+
scope :closed, -> {
|
57
|
+
ActiveSupport::Deprecation.warn 'Adjustment.closed is deprecated. Please use Adjustment.finalized instead', caller
|
58
|
+
finalized
|
59
|
+
}
|
60
|
+
|
61
|
+
scope :not_finalized, -> { where(state: 'open') }
|
62
|
+
scope :finalized, -> { where(state: 'closed') }
|
53
63
|
scope :tax, -> { where(source_type: 'Spree::TaxRate') }
|
54
64
|
scope :non_tax, -> do
|
55
65
|
source_type = arel_table[:source_type]
|
@@ -73,8 +83,12 @@ module Spree
|
|
73
83
|
extend DisplayMoney
|
74
84
|
money_methods :amount
|
75
85
|
|
86
|
+
def amount=(amount)
|
87
|
+
self[:amount] = Spree::LocalizedNumber.parse(amount)
|
88
|
+
end
|
89
|
+
|
76
90
|
def currency
|
77
|
-
adjustable ? adjustable.currency :
|
91
|
+
adjustable ? adjustable.currency : order.currency
|
78
92
|
end
|
79
93
|
|
80
94
|
def promotion?
|
@@ -86,6 +100,7 @@ module Spree
|
|
86
100
|
# the specific object amount passed here.
|
87
101
|
def update!(target = adjustable)
|
88
102
|
return amount if closed? || source.blank?
|
103
|
+
|
89
104
|
amount = source.compute_amount(target)
|
90
105
|
attributes = { amount: amount, updated_at: Time.current }
|
91
106
|
attributes[:eligible] = source.promotion.eligible?(target) if promotion?
|
@@ -1,9 +1,6 @@
|
|
1
1
|
module Spree
|
2
2
|
class Calculator < Spree::Base
|
3
|
-
|
4
|
-
if ActiveRecord::Base.connected? && connection.data_source_exists?(:spree_calculators) && connection.column_exists?(:spree_calculators, :deleted_at)
|
5
|
-
acts_as_paranoid
|
6
|
-
end
|
3
|
+
acts_as_paranoid
|
7
4
|
|
8
5
|
belongs_to :calculable, polymorphic: true, optional: true
|
9
6
|
|
@@ -16,18 +16,15 @@ module Spree
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def compute(object)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
sum += preferred_additional_item.to_f
|
27
|
-
end
|
28
|
-
end
|
19
|
+
compute_from_quantity(object.quantity)
|
20
|
+
end
|
21
|
+
|
22
|
+
def compute_from_quantity(quantity)
|
23
|
+
count = [quantity, preferred_max_items].reject(&:zero?).min
|
24
|
+
|
25
|
+
return BigDecimal(0) if count.zero?
|
29
26
|
|
30
|
-
|
27
|
+
preferred_first_item + (count - 1) * preferred_additional_item
|
31
28
|
end
|
32
29
|
end
|
33
30
|
end
|
@@ -11,6 +11,7 @@ module Spree
|
|
11
11
|
|
12
12
|
def compute(return_item)
|
13
13
|
return 0.0.to_d if return_item.exchange_requested?
|
14
|
+
|
14
15
|
@inventory_unit = return_item.inventory_unit
|
15
16
|
weighted_order_adjustment_amount(return_item) + weighted_line_item_pre_tax_amount(return_item)
|
16
17
|
end
|
@@ -23,6 +24,7 @@ module Spree
|
|
23
24
|
|
24
25
|
def percentage_of_order_total(return_item)
|
25
26
|
return 0.0 if inventory_unit.order.pre_tax_item_amount.zero?
|
27
|
+
|
26
28
|
weighted_line_item_pre_tax_amount(return_item) / inventory_unit.order.pre_tax_item_amount
|
27
29
|
end
|
28
30
|
|
@@ -31,7 +33,7 @@ module Spree
|
|
31
33
|
end
|
32
34
|
|
33
35
|
def percentage_of_line_item(return_item)
|
34
|
-
return_item.return_quantity / BigDecimal
|
36
|
+
return_item.return_quantity / BigDecimal(inventory_unit.line_item.quantity)
|
35
37
|
end
|
36
38
|
end
|
37
39
|
end
|
@@ -13,22 +13,22 @@ module Spree
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def compute_package(package)
|
16
|
-
|
16
|
+
quantity = package.contents.sum(&:quantity)
|
17
|
+
|
18
|
+
compute_from_quantity(quantity)
|
17
19
|
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
quantity.times do |i|
|
23
|
-
# check max value to avoid divide by 0 errors
|
24
|
-
sum += if (max == 0 && i == 0) || (max > 0) && (i % max == 0)
|
25
|
-
preferred_first_item.to_f
|
26
|
-
else
|
27
|
-
preferred_additional_item.to_f
|
28
|
-
end
|
29
|
-
end
|
21
|
+
delegate :compute_from_quantity, to: :flexi_rate_calculator
|
22
|
+
|
23
|
+
private
|
30
24
|
|
31
|
-
|
25
|
+
def flexi_rate_calculator
|
26
|
+
::Spree::Calculator::FlexiRate.new(
|
27
|
+
preferred_additional_item: preferred_additional_item,
|
28
|
+
preferred_first_item: preferred_first_item,
|
29
|
+
preferred_max_items: preferred_max_items,
|
30
|
+
preferred_currency: preferred_currency
|
31
|
+
)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
data/app/models/spree/country.rb
CHANGED
@@ -2,6 +2,12 @@ module Spree
|
|
2
2
|
class CreditCard < Spree::Base
|
3
3
|
include ActiveMerchant::Billing::CreditCardMethods
|
4
4
|
|
5
|
+
if !ENV['SPREE_DISABLE_DB_CONNECTION'] &&
|
6
|
+
connection.data_source_exists?(:spree_credit_cards) &&
|
7
|
+
connection.column_exists?(:spree_credit_cards, :deleted_at)
|
8
|
+
acts_as_paranoid
|
9
|
+
end
|
10
|
+
|
5
11
|
belongs_to :payment_method
|
6
12
|
belongs_to :user, class_name: Spree.user_class.to_s, foreign_key: 'user_id',
|
7
13
|
optional: true
|
@@ -75,7 +81,7 @@ module Spree
|
|
75
81
|
def number=(num)
|
76
82
|
@number = begin
|
77
83
|
num.gsub(/[^0-9]/, '')
|
78
|
-
rescue
|
84
|
+
rescue StandardError
|
79
85
|
nil
|
80
86
|
end
|
81
87
|
end
|
@@ -89,7 +95,7 @@ module Spree
|
|
89
95
|
when 'dinersclub' then 'diners_club'
|
90
96
|
when '' then try_type_from_number
|
91
97
|
else type
|
92
|
-
|
98
|
+
end
|
93
99
|
end
|
94
100
|
|
95
101
|
def set_last_digits
|
@@ -0,0 +1,117 @@
|
|
1
|
+
module Spree
|
2
|
+
class FulfilmentChanger
|
3
|
+
include ActiveModel::Validations
|
4
|
+
|
5
|
+
validates :quantity, numericality: { greater_than: 0 }
|
6
|
+
validates :desired_stock_location, presence: true
|
7
|
+
validate :current_shipment_not_already_shipped
|
8
|
+
validate :desired_shipment_different_from_current
|
9
|
+
validate :enough_stock_at_desired_location, if: :handle_stock_counts?
|
10
|
+
|
11
|
+
def initialize(params = {})
|
12
|
+
@current_stock_location = params[:current_stock_location]
|
13
|
+
@desired_stock_location = params[:desired_stock_location]
|
14
|
+
@current_shipment = params[:current_shipment]
|
15
|
+
@desired_shipment = params[:desired_shipment]
|
16
|
+
@variant = params[:variant]
|
17
|
+
@quantity = params[:quantity]
|
18
|
+
@available_quantity = [
|
19
|
+
desired_stock_location.try(:count_on_hand, variant).to_i,
|
20
|
+
current_quantity
|
21
|
+
].max
|
22
|
+
end
|
23
|
+
|
24
|
+
def run!
|
25
|
+
return false if invalid?
|
26
|
+
|
27
|
+
desired_shipment.save! if desired_shipment.new_record?
|
28
|
+
|
29
|
+
handle_stock
|
30
|
+
reload_shipment_inventory_units
|
31
|
+
after_process_shipments
|
32
|
+
|
33
|
+
true
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
attr_reader :variant, :quantity, :current_stock_location, :desired_stock_location,
|
39
|
+
:current_shipment, :desired_shipment, :available_quantity
|
40
|
+
|
41
|
+
def handle_stock
|
42
|
+
ActiveRecord::Base.transaction do
|
43
|
+
if handle_stock_counts?
|
44
|
+
current_stock_location.restock(variant, current_on_hand_quantity, current_shipment)
|
45
|
+
desired_stock_location.unstock(variant, unstock_quantity, desired_shipment)
|
46
|
+
end
|
47
|
+
|
48
|
+
update_current_shipment_inventory_units(new_on_hand_quantity, :on_hand)
|
49
|
+
update_current_shipment_inventory_units(quantity - new_on_hand_quantity, :backordered)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def after_process_shipments
|
54
|
+
if current_shipment.inventory_units.length.zero?
|
55
|
+
current_shipment.destroy!
|
56
|
+
else
|
57
|
+
current_shipment.refresh_rates
|
58
|
+
end
|
59
|
+
|
60
|
+
desired_shipment.refresh_rates
|
61
|
+
|
62
|
+
desired_shipment.order.reload
|
63
|
+
desired_shipment.order.update_with_updater!
|
64
|
+
end
|
65
|
+
|
66
|
+
def new_on_hand_quantity
|
67
|
+
[available_quantity, quantity].min
|
68
|
+
end
|
69
|
+
|
70
|
+
def unstock_quantity
|
71
|
+
desired_stock_location.backorderable?(variant) ? quantity : new_on_hand_quantity
|
72
|
+
end
|
73
|
+
|
74
|
+
def current_on_hand_quantity
|
75
|
+
[current_shipment.inventory_units.on_hand_or_backordered.size, quantity].min
|
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)
|
85
|
+
end
|
86
|
+
|
87
|
+
def reload_shipment_inventory_units
|
88
|
+
[current_shipment, desired_shipment].each { |shipment| shipment.inventory_units.reload }
|
89
|
+
end
|
90
|
+
|
91
|
+
def current_quantity
|
92
|
+
desired_stock_location == current_stock_location ? quantity : 0
|
93
|
+
end
|
94
|
+
|
95
|
+
def handle_stock_counts?
|
96
|
+
current_shipment.order.completed? && current_stock_location != desired_stock_location
|
97
|
+
end
|
98
|
+
|
99
|
+
def current_shipment_not_already_shipped
|
100
|
+
return unless current_shipment.shipped?
|
101
|
+
|
102
|
+
errors.add(:current_shipment, :has_already_been_shipped)
|
103
|
+
end
|
104
|
+
|
105
|
+
def enough_stock_at_desired_location
|
106
|
+
return if Spree::Stock::Quantifier.new(variant, desired_stock_location).can_supply?(quantity)
|
107
|
+
|
108
|
+
errors.add(:desired_shipment, :not_enough_stock_at_desired_location)
|
109
|
+
end
|
110
|
+
|
111
|
+
def desired_shipment_different_from_current
|
112
|
+
return unless desired_shipment.id == current_shipment.id
|
113
|
+
|
114
|
+
errors.add(:desired_shipment, :can_not_transfer_within_same_shipment)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|