spree_core 2.2.14 → 2.3.0
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.coffee → spree.js.coffee.erb} +11 -2
- data/app/controllers/spree/base_controller.rb +1 -0
- data/app/helpers/spree/base_helper.rb +5 -6
- data/app/helpers/spree/orders_helper.rb +4 -0
- data/app/helpers/spree/products_helper.rb +8 -7
- data/app/mailers/spree/base_mailer.rb +2 -2
- data/app/mailers/spree/order_mailer.rb +2 -2
- data/app/mailers/spree/shipment_mailer.rb +1 -1
- data/app/mailers/spree/test_mailer.rb +1 -1
- data/app/models/spree/ability.rb +15 -16
- data/app/models/spree/address.rb +3 -6
- data/app/models/spree/adjustment.rb +2 -2
- data/app/models/spree/alert.rb +1 -1
- data/app/models/spree/app_configuration.rb +17 -20
- data/app/models/spree/asset.rb +2 -2
- data/app/models/spree/base.rb +9 -0
- data/app/models/spree/calculator.rb +1 -1
- data/app/models/spree/calculator/flat_rate.rb +1 -1
- data/app/models/spree/calculator/flexi_rate.rb +1 -1
- data/app/models/spree/calculator/price_sack.rb +1 -3
- data/app/models/spree/calculator/shipping/flat_rate.rb +1 -1
- data/app/models/spree/calculator/shipping/flexi_rate.rb +1 -1
- data/app/models/spree/calculator/shipping/per_item.rb +1 -1
- data/app/models/spree/calculator/shipping/price_sack.rb +1 -3
- data/app/models/spree/classification.rb +1 -1
- data/app/models/spree/configuration.rb +1 -1
- data/app/models/spree/country.rb +1 -1
- data/app/models/spree/credit_card.rb +8 -12
- data/app/models/spree/gateway.rb +0 -3
- data/app/models/spree/gateway/bogus.rb +2 -3
- data/app/models/spree/image.rb +3 -1
- data/app/models/spree/inventory_unit.rb +5 -6
- data/app/models/spree/item_adjustments.rb +3 -4
- data/app/models/spree/legacy_user.rb +1 -1
- data/app/models/spree/line_item.rb +6 -13
- data/app/models/spree/log_entry.rb +1 -1
- data/app/models/spree/option_type.rb +1 -1
- data/app/models/spree/option_value.rb +1 -3
- data/app/models/spree/order.rb +52 -70
- data/app/models/spree/order/checkout.rb +17 -10
- data/app/models/spree/order/currency_updater.rb +1 -1
- data/app/models/spree/order_contents.rb +7 -4
- data/app/models/spree/order_populator.rb +1 -1
- data/app/models/spree/order_updater.rb +8 -21
- data/app/models/spree/payment.rb +26 -12
- data/app/models/spree/payment/processing.rb +5 -16
- data/app/models/spree/payment_capture_event.rb +1 -1
- data/app/models/spree/payment_method.rb +2 -2
- data/app/models/spree/payment_method/check.rb +0 -2
- data/app/models/spree/preference.rb +1 -31
- data/app/models/spree/preferences/configuration.rb +2 -6
- data/app/models/spree/preferences/preferable.rb +46 -74
- data/app/models/spree/preferences/preferable_class_methods.rb +11 -46
- data/app/models/spree/preferences/scoped_store.rb +33 -0
- data/app/models/spree/preferences/store.rb +8 -7
- data/app/models/spree/price.rb +1 -3
- data/app/models/spree/product.rb +59 -87
- data/app/models/spree/product/scopes.rb +22 -13
- data/app/models/spree/product_option_type.rb +1 -1
- data/app/models/spree/product_property.rb +1 -3
- data/app/models/spree/product_scope/scopes.rb +1 -1
- data/app/models/spree/promotion.rb +4 -5
- data/app/models/spree/promotion/actions/create_adjustment.rb +11 -2
- data/app/models/spree/promotion/actions/create_item_adjustments.rb +19 -2
- data/app/models/spree/promotion/actions/create_line_items.rb +2 -12
- data/app/models/spree/promotion/rules/user.rb +5 -1
- data/app/models/spree/promotion_action.rb +1 -1
- data/app/models/spree/promotion_action_line_item.rb +1 -1
- data/app/models/spree/promotion_handler/cart.rb +2 -14
- data/app/models/spree/promotion_handler/coupon.rb +3 -13
- data/app/models/spree/promotion_rule.rb +1 -1
- data/app/models/spree/property.rb +1 -3
- data/app/models/spree/prototype.rb +1 -1
- data/app/models/spree/return_authorization.rb +4 -10
- data/app/models/spree/role.rb +1 -1
- data/app/models/spree/shipment.rb +1 -9
- data/app/models/spree/shipping_category.rb +3 -3
- data/app/models/spree/shipping_method.rb +1 -1
- data/app/models/spree/shipping_method_category.rb +2 -2
- data/app/models/spree/shipping_rate.rb +3 -3
- data/app/models/spree/state.rb +1 -1
- data/app/models/spree/state_change.rb +1 -1
- data/app/models/spree/stock/availability_validator.rb +7 -3
- data/app/models/spree/stock/package.rb +0 -23
- data/app/models/spree/stock/splitter/backordered.rb +1 -1
- data/app/models/spree/stock/splitter/shipping_category.rb +1 -1
- data/app/models/spree/stock/splitter/weight.rb +1 -1
- data/app/models/spree/stock_item.rb +7 -10
- data/app/models/spree/stock_location.rb +2 -6
- data/app/models/spree/stock_movement.rb +1 -3
- data/app/models/spree/stock_transfer.rb +1 -3
- data/app/models/spree/store.rb +33 -0
- data/app/models/spree/tax_category.rb +2 -2
- data/app/models/spree/tax_rate.rb +21 -52
- data/app/models/spree/taxon.rb +9 -8
- data/app/models/spree/taxonomy.rb +1 -1
- data/app/models/spree/tracker.rb +1 -1
- data/app/models/spree/variant.rb +13 -15
- data/app/models/spree/variant/scopes.rb +1 -1
- data/app/models/spree/zone.rb +22 -22
- data/app/models/spree/zone_member.rb +2 -2
- data/config/initializers/user_class_extensions.rb +0 -8
- data/config/locales/en.yml +7 -42
- data/db/default/spree/countries.rb +2 -3
- data/db/default/spree/stores.rb +9 -0
- data/db/migrate/20130611054351_rename_shipping_methods_zones_to_spree_shipping_methods_zones.rb +0 -5
- data/db/migrate/20130807024301_upgrade_adjustments.rb +4 -5
- data/db/migrate/20130807024302_rename_adjustment_fields.rb +5 -2
- data/db/migrate/20131118183431_add_line_item_id_to_spree_inventory_units.rb +1 -1
- data/db/migrate/20140106065820_remove_value_type_from_spree_preferences.rb +8 -0
- data/db/migrate/20140227112348_add_preference_store_to_everything.rb +8 -0
- data/db/migrate/20140309023735_migrate_old_preferences.rb +23 -0
- data/db/migrate/20140309024355_create_spree_stores.rb +25 -0
- data/db/migrate/20140309033438_create_store_from_preferences.rb +30 -0
- data/db/migrate/20140315053743_add_timestamps_to_spree_assets.rb +6 -0
- data/db/migrate/20140331100557_add_additional_store_fields.rb +8 -0
- data/db/migrate/20140410141842_add_many_missing_indexes.rb +18 -0
- data/db/migrate/20140410150358_correct_some_polymorphic_index_and_add_more_missing.rb +66 -0
- data/db/migrate/20140508151342_change_spree_price_amount_precision.rb +1 -1
- data/db/migrate/20140518174634_add_token_to_spree_orders.rb +5 -0
- data/db/migrate/20140530024945_move_order_token_from_tokenized_permission.rb +29 -0
- data/db/migrate/20140601011216_set_shipment_total_for_users_upgrading.rb +5 -3
- data/db/migrate/20140604135309_drop_credit_card_first_name_and_last_name.rb +6 -0
- data/lib/generators/spree/dummy/dummy_generator.rb +1 -0
- data/lib/generators/spree/dummy/templates/initializers/devise.rb +3 -0
- data/lib/generators/spree/dummy/templates/rails/routes.rb +0 -1
- data/lib/generators/spree/install/install_generator.rb +8 -17
- data/lib/generators/spree/install/templates/config/initializers/spree.rb +2 -2
- data/lib/spree/core.rb +13 -9
- data/lib/spree/core/calculated_adjustments.rb +1 -1
- data/lib/spree/core/controller_helpers/auth.rb +27 -18
- data/lib/spree/core/controller_helpers/common.rb +2 -2
- data/lib/spree/core/controller_helpers/order.rb +15 -24
- data/lib/spree/core/controller_helpers/store.rb +19 -0
- data/lib/spree/core/delegate_belongs_to.rb +2 -2
- data/lib/spree/core/engine.rb +0 -10
- data/lib/spree/core/importer.rb +1 -0
- data/lib/spree/core/importer/order.rb +16 -44
- data/lib/spree/core/importer/product.rb +62 -0
- data/lib/spree/core/product_filters.rb +0 -4
- data/lib/spree/core/routes.rb +4 -6
- data/lib/spree/core/validators/email.rb +23 -1
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/money.rb +1 -169
- data/lib/spree/permitted_attributes.rb +6 -4
- data/lib/spree/testing_support/authorization_helpers.rb +23 -21
- data/lib/spree/testing_support/capybara_ext.rb +11 -21
- data/lib/spree/testing_support/common_rake.rb +3 -1
- data/lib/spree/testing_support/controller_requests.rb +0 -2
- data/lib/spree/testing_support/factories/credit_card_factory.rb +1 -1
- data/lib/spree/testing_support/factories/line_item_factory.rb +4 -1
- data/lib/spree/testing_support/factories/order_factory.rb +5 -4
- data/lib/spree/testing_support/factories/product_factory.rb +0 -4
- data/lib/spree/testing_support/factories/promotion_factory.rb +5 -7
- data/lib/spree/testing_support/factories/shipment_factory.rb +0 -1
- data/lib/spree/testing_support/factories/stock_factory.rb +2 -2
- data/lib/spree/testing_support/factories/store_factory.rb +8 -0
- data/lib/spree/testing_support/preferences.rb +3 -3
- data/lib/tasks/core.rake +2 -2
- metadata +48 -39
- data/app/models/spree/stock/order_counter.rb +0 -55
- data/app/models/spree/tokenized_permission.rb +0 -6
- data/app/views/spree/shared/_routes.html.erb +0 -13
- data/db/migrate/20140804185157_add_default_to_shipment_cost.rb +0 -10
- data/db/migrate/20141021194502_add_state_lock_version_to_order.rb +0 -5
- data/lib/spree/core/adjustment_source.rb +0 -26
- data/lib/spree/core/mail_interceptor.rb +0 -22
- data/lib/spree/core/mail_method.rb +0 -27
- data/lib/spree/core/mail_settings.rb +0 -55
- data/lib/spree/core/ransackable_attributes.rb +0 -15
- data/lib/spree/core/token_resource.rb +0 -27
@@ -1,5 +1,5 @@
|
|
1
1
|
module Spree
|
2
|
-
class ProductOptionType <
|
2
|
+
class ProductOptionType < Spree::Base
|
3
3
|
belongs_to :product, class_name: 'Spree::Product', inverse_of: :product_option_types
|
4
4
|
belongs_to :option_type, class_name: 'Spree::OptionType', inverse_of: :product_option_types
|
5
5
|
acts_as_list scope: :product
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Spree
|
2
|
-
class ProductProperty <
|
2
|
+
class ProductProperty < Spree::Base
|
3
3
|
belongs_to :product, touch: true, class_name: 'Spree::Product', inverse_of: :product_properties
|
4
4
|
belongs_to :property, class_name: 'Spree::Property', inverse_of: :product_properties
|
5
5
|
|
@@ -8,8 +8,6 @@ module Spree
|
|
8
8
|
|
9
9
|
default_scope -> { order("#{self.table_name}.position") }
|
10
10
|
|
11
|
-
self.whitelisted_ransackable_attributes = ['value']
|
12
|
-
|
13
11
|
# virtual attributes for use with AJAX completion stuff
|
14
12
|
def property_name
|
15
13
|
property.name if property
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Spree
|
2
|
-
class ProductScope <
|
2
|
+
class ProductScope < Spree::Base
|
3
3
|
before_validation(:on => :create) do
|
4
4
|
# Add default empty arguments so scope validates and errors aren't caused when previewing it
|
5
5
|
if name && args = self.class.arguments_for_scope_name(name)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Spree
|
2
|
-
class Promotion <
|
2
|
+
class Promotion < Spree::Base
|
3
3
|
MATCH_POLICIES = %w(all any)
|
4
4
|
UNACTIVATABLE_ORDER_STATES = ["complete", "awaiting_return", "returned"]
|
5
5
|
|
@@ -22,14 +22,14 @@ module Spree
|
|
22
22
|
|
23
23
|
before_save :normalize_blank_values
|
24
24
|
|
25
|
-
|
25
|
+
scope :coupons, ->{ where("#{table_name}.code IS NOT NULL") }
|
26
26
|
|
27
27
|
def self.advertised
|
28
28
|
where(advertise: true)
|
29
29
|
end
|
30
30
|
|
31
31
|
def self.with_coupon_code(coupon_code)
|
32
|
-
where("lower(
|
32
|
+
where("lower(code) = ?", coupon_code.strip.downcase).first
|
33
33
|
end
|
34
34
|
|
35
35
|
def self.active
|
@@ -107,8 +107,7 @@ module Spree
|
|
107
107
|
end
|
108
108
|
|
109
109
|
def adjusted_credits_count(promotable)
|
110
|
-
|
111
|
-
credits_count - adjustments.promotion.where(:source_id => actions.pluck(:id)).count
|
110
|
+
credits_count - promotable.adjustments.promotion.where(:source_id => actions.pluck(:id)).count
|
112
111
|
end
|
113
112
|
|
114
113
|
def credits
|
@@ -3,14 +3,13 @@ module Spree
|
|
3
3
|
module Actions
|
4
4
|
class CreateAdjustment < PromotionAction
|
5
5
|
include Spree::Core::CalculatedAdjustments
|
6
|
-
include Spree::Core::AdjustmentSource
|
7
6
|
|
8
7
|
has_many :adjustments, as: :source
|
9
8
|
|
10
9
|
delegate :eligible?, to: :promotion
|
11
10
|
|
12
11
|
before_validation :ensure_action_has_calculator
|
13
|
-
before_destroy :
|
12
|
+
before_destroy :deals_with_adjustments
|
14
13
|
|
15
14
|
# Creates the adjustment related to a promotion for the order passed
|
16
15
|
# through options hash
|
@@ -56,6 +55,16 @@ module Spree
|
|
56
55
|
self.calculator = Calculator::FlatPercentItemTotal.new
|
57
56
|
end
|
58
57
|
|
58
|
+
def deals_with_adjustments
|
59
|
+
adjustment_scope = self.adjustments.joins("LEFT OUTER JOIN spree_orders ON spree_orders.id = spree_adjustments.adjustable_id")
|
60
|
+
# For incomplete orders, remove the adjustment completely.
|
61
|
+
adjustment_scope.where("spree_orders.completed_at IS NULL").readonly(false).destroy_all
|
62
|
+
|
63
|
+
# For complete orders, the source will be invalid.
|
64
|
+
# Therefore we nullify the source_id, leaving the adjustment in place.
|
65
|
+
# This would mean that the order's total is not altered at all.
|
66
|
+
adjustment_scope.where("spree_orders.completed_at IS NOT NULL").update_all("source_id = NULL")
|
67
|
+
end
|
59
68
|
end
|
60
69
|
end
|
61
70
|
end
|
@@ -3,14 +3,13 @@ module Spree
|
|
3
3
|
module Actions
|
4
4
|
class CreateItemAdjustments < PromotionAction
|
5
5
|
include Spree::Core::CalculatedAdjustments
|
6
|
-
include Spree::Core::AdjustmentSource
|
7
6
|
|
8
7
|
has_many :adjustments, as: :source
|
9
8
|
|
10
9
|
delegate :eligible?, to: :promotion
|
11
10
|
|
12
11
|
before_validation :ensure_action_has_calculator
|
13
|
-
before_destroy :
|
12
|
+
before_destroy :deals_with_adjustments
|
14
13
|
|
15
14
|
def perform(payload = {})
|
16
15
|
order = payload[:order]
|
@@ -63,6 +62,24 @@ module Spree
|
|
63
62
|
self.calculator = Calculator::PercentOnLineItem.new
|
64
63
|
end
|
65
64
|
|
65
|
+
def deals_with_adjustments
|
66
|
+
adjustment_scope = self.adjustments.includes(:order).references(:spree_orders)
|
67
|
+
|
68
|
+
# For incomplete orders, remove the adjustment completely.
|
69
|
+
adjustment_scope.where("spree_orders.completed_at IS NULL").each do |adjustment|
|
70
|
+
adjustment.destroy
|
71
|
+
end
|
72
|
+
|
73
|
+
# For complete orders, the source will be invalid.
|
74
|
+
# Therefore we nullify the source_id, leaving the adjustment in place.
|
75
|
+
# This would mean that the order's total is not altered at all.
|
76
|
+
adjustment_scope.where("spree_orders.completed_at IS NOT NULL").each do |adjustment|
|
77
|
+
adjustment.update_columns(
|
78
|
+
source_id: nil,
|
79
|
+
updated_at: Time.now,
|
80
|
+
)
|
81
|
+
end
|
82
|
+
end
|
66
83
|
end
|
67
84
|
end
|
68
85
|
end
|
@@ -39,23 +39,13 @@ module Spree
|
|
39
39
|
order = options[:order]
|
40
40
|
return unless self.eligible? order
|
41
41
|
|
42
|
-
action_taken = false
|
43
42
|
promotion_action_line_items.each do |item|
|
44
43
|
current_quantity = order.quantity_of(item.variant)
|
45
|
-
if current_quantity < item.quantity
|
46
|
-
|
47
|
-
action_taken = true if line_item.try(:valid?)
|
44
|
+
if current_quantity < item.quantity
|
45
|
+
order.contents.add(item.variant, item.quantity - current_quantity)
|
48
46
|
end
|
49
47
|
end
|
50
|
-
action_taken
|
51
48
|
end
|
52
|
-
|
53
|
-
# Checks that there's enough stock to add the line item to the order
|
54
|
-
def item_available?(item)
|
55
|
-
quantifier = Spree::Stock::Quantifier.new(item.variant)
|
56
|
-
quantifier.can_supply? item.quantity
|
57
|
-
end
|
58
|
-
|
59
49
|
end
|
60
50
|
end
|
61
51
|
end
|
@@ -3,8 +3,12 @@ module Spree
|
|
3
3
|
module Rules
|
4
4
|
class User < PromotionRule
|
5
5
|
belongs_to :user, class_name: "::#{Spree.user_class.to_s}"
|
6
|
-
has_and_belongs_to_many :users, class_name: "::#{Spree.user_class.to_s}", join_table: 'spree_promotion_rules_users', foreign_key: 'promotion_rule_id'
|
7
6
|
|
7
|
+
has_and_belongs_to_many :users, class_name: "::#{Spree.user_class.to_s}",
|
8
|
+
join_table: 'spree_promotion_rules_users',
|
9
|
+
foreign_key: 'promotion_rule_id',
|
10
|
+
association_foreign_key: :user_id
|
11
|
+
|
8
12
|
def applicable?(promotable)
|
9
13
|
promotable.is_a?(Spree::Order)
|
10
14
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# Base class for all types of promotion action.
|
2
2
|
# PromotionActions perform the necessary tasks when a promotion is activated by an event and determined to be eligible.
|
3
3
|
module Spree
|
4
|
-
class PromotionAction <
|
4
|
+
class PromotionAction < Spree::Base
|
5
5
|
acts_as_paranoid
|
6
6
|
|
7
7
|
belongs_to :promotion, class_name: 'Spree::Promotion'
|
@@ -29,21 +29,9 @@ module Spree
|
|
29
29
|
end
|
30
30
|
|
31
31
|
private
|
32
|
-
def promotions
|
33
|
-
promo_table = Promotion.arel_table
|
34
|
-
join_table = Arel::Table.new(:spree_orders_promotions)
|
35
|
-
|
36
|
-
join_condition = promo_table.join(join_table, Arel::Nodes::OuterJoin).on(
|
37
|
-
promo_table[:id].eq(join_table[:promotion_id])
|
38
|
-
).join_sources
|
39
32
|
|
40
|
-
|
41
|
-
|
42
|
-
where(
|
43
|
-
promo_table[:code].eq(nil).and(
|
44
|
-
promo_table[:path].eq(nil)
|
45
|
-
).or(join_table[:order_id].eq(order.id))
|
46
|
-
).distinct
|
33
|
+
def promotions
|
34
|
+
Promotion.active.includes(:promotion_rules).where(:code => nil, :path => nil)
|
47
35
|
end
|
48
36
|
end
|
49
37
|
end
|
@@ -72,27 +72,17 @@ module Spree
|
|
72
72
|
end
|
73
73
|
}
|
74
74
|
|
75
|
-
# Check for applied adjustments.
|
76
75
|
discount = order.line_item_adjustments.promotion.detect(&detector)
|
77
76
|
discount ||= order.shipment_adjustments.promotion.detect(&detector)
|
78
77
|
discount ||= order.adjustments.promotion.detect(&detector)
|
79
78
|
|
80
|
-
|
81
|
-
created_line_items = promotion.actions.detect { |a| a.type == 'Spree::Promotion::Actions::CreateLineItems' }
|
82
|
-
|
83
|
-
if (discount && discount.eligible) || created_line_items
|
79
|
+
if discount.eligible
|
84
80
|
order.update_totals
|
85
81
|
order.persist_totals
|
86
82
|
self.success = Spree.t(:coupon_code_applied)
|
87
83
|
else
|
88
|
-
# if the promotion
|
89
|
-
|
90
|
-
if order.promotions.with_coupon_code(order.coupon_code)
|
91
|
-
self.error = Spree.t(:coupon_code_better_exists)
|
92
|
-
else
|
93
|
-
# if the promotion was created after the order
|
94
|
-
self.error = Spree.t(:coupon_code_not_found)
|
95
|
-
end
|
84
|
+
# if the promotion was created after the order
|
85
|
+
self.error = Spree.t(:coupon_code_not_found)
|
96
86
|
end
|
97
87
|
end
|
98
88
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Spree
|
2
|
-
class Property <
|
2
|
+
class Property < Spree::Base
|
3
3
|
has_and_belongs_to_many :prototypes, join_table: 'spree_properties_prototypes'
|
4
4
|
|
5
5
|
has_many :product_properties, dependent: :delete_all, inverse_of: :property
|
@@ -11,8 +11,6 @@ module Spree
|
|
11
11
|
|
12
12
|
after_touch :touch_all_products
|
13
13
|
|
14
|
-
self.whitelisted_ransackable_attributes = ['presentation']
|
15
|
-
|
16
14
|
def self.find_all_by_prototype(prototype)
|
17
15
|
id = prototype
|
18
16
|
id = prototype.id if prototype.class == Prototype
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Spree
|
2
|
-
class ReturnAuthorization <
|
3
|
-
belongs_to :order, class_name: 'Spree::Order'
|
2
|
+
class ReturnAuthorization < Spree::Base
|
3
|
+
belongs_to :order, class_name: 'Spree::Order'
|
4
4
|
|
5
|
-
has_many :inventory_units
|
5
|
+
has_many :inventory_units
|
6
6
|
belongs_to :stock_location
|
7
7
|
before_create :generate_number
|
8
8
|
before_save :force_positive_amount
|
@@ -22,12 +22,6 @@ module Spree
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
self.whitelisted_ransackable_attributes = ['reason']
|
26
|
-
|
27
|
-
def pre_tax_total
|
28
|
-
return_items.sum(:pre_tax_amount)
|
29
|
-
end
|
30
|
-
|
31
25
|
def currency
|
32
26
|
order.nil? ? Spree::Config[:currency] : order.currency
|
33
27
|
end
|
@@ -68,7 +62,7 @@ module Spree
|
|
68
62
|
order.shipped_shipments.collect{|s| s.inventory_units.to_a}.flatten
|
69
63
|
end
|
70
64
|
|
71
|
-
# Used when Adjustment#update! wants to update the related
|
65
|
+
# Used when Adjustment#update! wants to update the related adjustmenrt
|
72
66
|
def compute_amount(*args)
|
73
67
|
amount.abs * -1
|
74
68
|
end
|
data/app/models/spree/role.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'ostruct'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
class Shipment <
|
4
|
+
class Shipment < Spree::Base
|
5
5
|
belongs_to :order, class_name: 'Spree::Order', touch: true, inverse_of: :shipments
|
6
6
|
belongs_to :address, class_name: 'Spree::Address', inverse_of: :shipments
|
7
7
|
belongs_to :stock_location, class_name: 'Spree::StockLocation'
|
@@ -93,8 +93,6 @@ module Spree
|
|
93
93
|
selected_shipping_rate.try(:shipping_method) || shipping_rates.first.try(:shipping_method)
|
94
94
|
end
|
95
95
|
|
96
|
-
self.whitelisted_ransackable_attributes = ['number']
|
97
|
-
|
98
96
|
def add_shipping_method(shipping_method, selected = false)
|
99
97
|
shipping_rates.create(shipping_method: shipping_method, selected: selected, cost: cost)
|
100
98
|
end
|
@@ -339,12 +337,6 @@ module Spree
|
|
339
337
|
"#{Spree.t(:shipping)} (#{shipping_method.name})"
|
340
338
|
end
|
341
339
|
|
342
|
-
def validate_shipping_method
|
343
|
-
unless shipping_method.nil?
|
344
|
-
errors.add :shipping_method, Spree.t(:is_not_available_to_shipment_address) unless shipping_method.include?(address)
|
345
|
-
end
|
346
|
-
end
|
347
|
-
|
348
340
|
def after_ship
|
349
341
|
inventory_units.each &:ship!
|
350
342
|
send_shipped_email
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Spree
|
2
|
-
class ShippingCategory <
|
2
|
+
class ShippingCategory < Spree::Base
|
3
3
|
validates :name, presence: true
|
4
4
|
has_many :products, inverse_of: :shipping_category
|
5
|
-
has_many :shipping_method_categories
|
5
|
+
has_many :shipping_method_categories
|
6
6
|
has_many :shipping_methods, through: :shipping_method_categories
|
7
7
|
end
|
8
|
-
end
|
8
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Spree
|
2
|
-
class ShippingMethodCategory <
|
2
|
+
class ShippingMethodCategory < Spree::Base
|
3
3
|
belongs_to :shipping_method, class_name: 'Spree::ShippingMethod'
|
4
|
-
belongs_to :shipping_category, class_name: 'Spree::ShippingCategory'
|
4
|
+
belongs_to :shipping_category, class_name: 'Spree::ShippingCategory'
|
5
5
|
end
|
6
6
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Spree
|
2
|
-
class ShippingRate <
|
2
|
+
class ShippingRate < Spree::Base
|
3
3
|
belongs_to :shipment, class_name: 'Spree::Shipment'
|
4
4
|
belongs_to :shipping_method, class_name: 'Spree::ShippingMethod', inverse_of: :shipping_rates
|
5
5
|
belongs_to :tax_rate, class_name: 'Spree::TaxRate'
|
@@ -23,10 +23,10 @@ module Spree
|
|
23
23
|
if tax_rate.included_in_price?
|
24
24
|
if tax_amount > 0
|
25
25
|
amount = "#{display_tax_amount(tax_amount)} #{tax_rate.name}"
|
26
|
-
price += " (
|
26
|
+
price += " (incl. #{amount})"
|
27
27
|
else
|
28
28
|
amount = "#{display_tax_amount(tax_amount*-1)} #{tax_rate.name}"
|
29
|
-
price += " (
|
29
|
+
price += " (excl. #{amount})"
|
30
30
|
end
|
31
31
|
else
|
32
32
|
amount = "#{display_tax_amount(tax_amount)} #{tax_rate.name}"
|
data/app/models/spree/state.rb
CHANGED
@@ -2,9 +2,13 @@ module Spree
|
|
2
2
|
module Stock
|
3
3
|
class AvailabilityValidator < ActiveModel::Validator
|
4
4
|
def validate(line_item)
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
if shipment = line_item.target_shipment
|
6
|
+
units = shipment.inventory_units_for(line_item.variant)
|
7
|
+
return if units.count > line_item.quantity
|
8
|
+
quantity = line_item.quantity - units.count
|
9
|
+
else
|
10
|
+
quantity = line_item.quantity
|
11
|
+
end
|
8
12
|
|
9
13
|
quantifier = Stock::Quantifier.new(line_item.variant)
|
10
14
|
|