spree_core 3.3.6 → 3.4.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/helpers/spree/base_helper.rb +17 -18
- data/app/helpers/spree/products_helper.rb +5 -5
- data/app/models/concerns/spree/calculated_adjustments.rb +4 -3
- data/app/models/concerns/spree/default_price.rb +4 -5
- data/app/models/concerns/spree/display_money.rb +1 -1
- data/app/models/concerns/spree/named_type.rb +1 -1
- data/app/models/concerns/spree/ransackable_attributes.rb +5 -6
- data/app/models/concerns/spree/user_address.rb +6 -6
- data/app/models/concerns/spree/user_methods.rb +3 -3
- data/app/models/concerns/spree/user_payment_source.rb +4 -2
- data/app/models/concerns/spree/user_reporting.rb +1 -1
- data/app/models/spree/ability.rb +3 -3
- data/app/models/spree/address.rb +13 -9
- data/app/models/spree/adjustable/adjuster/promotion.rb +1 -1
- data/app/models/spree/adjustable/adjustments_updater.rb +2 -2
- data/app/models/spree/adjustable/promotion_accumulator.rb +6 -4
- data/app/models/spree/adjustment.rb +2 -3
- data/app/models/spree/app_configuration.rb +5 -6
- data/app/models/spree/base.rb +1 -1
- data/app/models/spree/calculator/default_tax.rb +4 -5
- data/app/models/spree/calculator/flat_percent_item_total.rb +1 -1
- data/app/models/spree/calculator/flat_rate.rb +3 -3
- data/app/models/spree/calculator/flexi_rate.rb +5 -5
- data/app/models/spree/calculator/price_sack.rb +9 -9
- data/app/models/spree/calculator/shipping/flat_percent_item_total.rb +1 -1
- data/app/models/spree/calculator/shipping/flat_rate.rb +3 -3
- data/app/models/spree/calculator/shipping/flexi_rate.rb +7 -7
- data/app/models/spree/calculator/shipping/per_item.rb +2 -2
- data/app/models/spree/calculator/shipping/price_sack.rb +4 -4
- data/app/models/spree/calculator/tiered_flat_rate.rb +3 -2
- data/app/models/spree/calculator/tiered_percent.rb +4 -3
- data/app/models/spree/calculator.rb +4 -4
- data/app/models/spree/classification.rb +2 -2
- data/app/models/spree/credit_card.rb +1 -1
- data/app/models/spree/exchange.rb +4 -5
- data/app/models/spree/gateway/bogus.rb +20 -20
- data/app/models/spree/gateway/bogus_simple.rb +2 -4
- data/app/models/spree/gateway.rb +4 -4
- data/app/models/spree/image.rb +3 -3
- data/app/models/spree/inventory_unit.rb +30 -30
- data/app/models/spree/line_item.rb +7 -9
- data/app/models/spree/option_type.rb +1 -1
- data/app/models/spree/order/checkout.rb +5 -5
- data/app/models/spree/order/currency_updater.rb +1 -4
- data/app/models/spree/order/payments.rb +4 -4
- data/app/models/spree/order/store_credit.rb +2 -2
- data/app/models/spree/order.rb +11 -29
- data/app/models/spree/order_contents.rb +6 -5
- data/app/models/spree/order_inventory.rb +3 -4
- data/app/models/spree/order_updater.rb +13 -14
- data/app/models/spree/payment/processing.rb +25 -26
- data/app/models/spree/payment.rb +72 -79
- data/app/models/spree/payment_capture_event.rb +1 -1
- data/app/models/spree/payment_method/check.rb +1 -1
- data/app/models/spree/payment_method/store_credit.rb +5 -5
- data/app/models/spree/payment_method.rb +7 -7
- data/app/models/spree/preferences/configuration.rb +6 -9
- data/app/models/spree/preferences/preferable.rb +11 -11
- data/app/models/spree/preferences/preferable_class_methods.rb +2 -3
- data/app/models/spree/preferences/scoped_store.rb +6 -5
- data/app/models/spree/preferences/store.rb +9 -14
- data/app/models/spree/price.rb +1 -1
- data/app/models/spree/product/scopes.rb +49 -49
- data/app/models/spree/product.rb +16 -16
- data/app/models/spree/promotion/actions/create_item_adjustments.rb +2 -1
- data/app/models/spree/promotion/actions/free_shipping.rb +1 -1
- data/app/models/spree/promotion/rules/first_order.rb +7 -6
- data/app/models/spree/promotion/rules/item_total.rb +3 -5
- data/app/models/spree/promotion/rules/one_use_per_user.rb +1 -2
- data/app/models/spree/promotion/rules/option_value.rb +14 -6
- data/app/models/spree/promotion/rules/product.rb +4 -4
- data/app/models/spree/promotion/rules/taxon.rb +6 -6
- data/app/models/spree/promotion/rules/user.rb +3 -3
- data/app/models/spree/promotion/rules/user_logged_in.rb +1 -1
- data/app/models/spree/promotion.rb +15 -16
- data/app/models/spree/promotion_action.rb +1 -1
- data/app/models/spree/promotion_handler/cart.rb +3 -2
- data/app/models/spree/promotion_handler/free_shipping.rb +1 -3
- data/app/models/spree/promotion_handler/page.rb +3 -3
- data/app/models/spree/promotion_rule.rb +5 -4
- data/app/models/spree/refund.rb +8 -8
- data/app/models/spree/reimbursement/credit.rb +1 -1
- data/app/models/spree/reimbursement/reimbursement_type_engine.rb +1 -3
- data/app/models/spree/reimbursement.rb +4 -8
- data/app/models/spree/reimbursement_performer.rb +0 -5
- data/app/models/spree/reimbursement_tax_calculator.rb +5 -12
- data/app/models/spree/reimbursement_type.rb +2 -2
- data/app/models/spree/return_authorization.rb +22 -26
- data/app/models/spree/return_item/eligibility_validator/default.rb +3 -3
- data/app/models/spree/return_item/eligibility_validator/inventory_shipped.rb +2 -2
- data/app/models/spree/return_item/eligibility_validator/no_reimbursements.rb +2 -2
- data/app/models/spree/return_item/eligibility_validator/order_completed.rb +2 -2
- data/app/models/spree/return_item/eligibility_validator/rma_required.rb +2 -3
- data/app/models/spree/return_item/eligibility_validator/time_since_purchase.rb +2 -2
- data/app/models/spree/return_item.rb +15 -19
- data/app/models/spree/returns_calculator.rb +1 -2
- data/app/models/spree/shipment.rb +14 -35
- data/app/models/spree/shipment_handler.rb +10 -12
- data/app/models/spree/shipping_calculator.rb +5 -6
- data/app/models/spree/shipping_method.rb +3 -3
- data/app/models/spree/shipping_rate.rb +2 -2
- data/app/models/spree/state.rb +2 -2
- data/app/models/spree/stock/availability_validator.rb +1 -1
- data/app/models/spree/stock/content_item.rb +2 -3
- data/app/models/spree/stock/coordinator.rb +3 -2
- data/app/models/spree/stock/differentiator.rb +3 -2
- data/app/models/spree/stock/estimator.rb +7 -5
- data/app/models/spree/stock/package.rb +5 -5
- data/app/models/spree/stock/packer.rb +1 -1
- data/app/models/spree/stock/prioritizer.rb +5 -7
- data/app/models/spree/stock/quantifier.rb +0 -1
- data/app/models/spree/stock/splitter/backordered.rb +2 -4
- data/app/models/spree/stock/splitter/base.rb +3 -2
- data/app/models/spree/stock/splitter/shipping_category.rb +2 -1
- data/app/models/spree/stock_item.rb +1 -1
- data/app/models/spree/stock_location.rb +12 -11
- data/app/models/spree/stock_movement.rb +1 -3
- data/app/models/spree/stock_transfer.rb +1 -1
- data/app/models/spree/store.rb +4 -4
- data/app/models/spree/store_credit.rb +3 -3
- data/app/models/spree/tax_category.rb +1 -1
- data/app/models/spree/tax_rate.rb +10 -10
- data/app/models/spree/taxon.rb +13 -13
- data/app/models/spree/taxonomy.rb +9 -8
- data/app/models/spree/validations/db_maximum_length_validator.rb +2 -3
- data/app/models/spree/variant.rb +30 -41
- data/app/models/spree/zone.rb +10 -10
- data/app/validators/db_maximum_length_validator.rb +5 -5
- data/config/initializers/acts_as_taggable_on.rb +3 -3
- data/config/initializers/assets.rb +1 -1
- data/config/initializers/friendly_id.rb +1 -1
- data/config/initializers/premailer_assets.rb +1 -1
- data/config/locales/en.yml +8 -2
- data/db/default/spree/states.rb +1 -0
- data/lib/generators/spree/custom_user/custom_user_generator.rb +12 -15
- data/lib/generators/spree/install/install_generator.rb +45 -32
- data/lib/spree/core/components.rb +3 -3
- data/lib/spree/core/controller_helpers/auth.rb +5 -10
- data/lib/spree/core/controller_helpers/common.rb +2 -3
- data/lib/spree/core/controller_helpers/order.rb +3 -7
- data/lib/spree/core/controller_helpers/respond_with.rb +4 -4
- data/lib/spree/core/engine.rb +3 -3
- data/lib/spree/core/environment/calculators.rb +0 -1
- data/lib/spree/core/environment_extension.rb +8 -8
- data/lib/spree/core/importer/order.rb +64 -67
- data/lib/spree/core/importer/product.rb +10 -9
- data/lib/spree/core/product_filters.rb +17 -18
- data/lib/spree/core/routes.rb +2 -6
- data/lib/spree/core/search/base.rb +62 -59
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/core.rb +4 -6
- data/lib/spree/i18n.rb +3 -5
- data/lib/spree/localized_number.rb +0 -2
- data/lib/spree/migrations.rb +8 -7
- data/lib/spree/money.rb +3 -7
- data/lib/spree/permitted_attributes.rb +2 -2
- data/lib/spree/responder.rb +4 -5
- data/lib/spree/testing_support/authorization_helpers.rb +3 -3
- data/lib/spree/testing_support/caching.rb +5 -5
- data/lib/spree/testing_support/capybara_ext.rb +16 -18
- data/lib/spree/testing_support/common_rake.rb +8 -9
- data/lib/spree/testing_support/controller_requests.rb +6 -6
- data/lib/spree/testing_support/extension_rake.rb +2 -3
- data/lib/spree/testing_support/factories/address_factory.rb +1 -1
- data/lib/spree/testing_support/factories/adjustment_factory.rb +1 -1
- data/lib/spree/testing_support/factories/calculator_factory.rb +1 -1
- data/lib/spree/testing_support/factories/country_factory.rb +1 -1
- data/lib/spree/testing_support/factories/credit_card_factory.rb +1 -1
- data/lib/spree/testing_support/factories/customer_return_factory.rb +1 -3
- data/lib/spree/testing_support/factories/image_factory.rb +2 -2
- data/lib/spree/testing_support/factories/inventory_unit_factory.rb +1 -1
- data/lib/spree/testing_support/factories/line_item_factory.rb +2 -2
- data/lib/spree/testing_support/factories/options_factory.rb +1 -1
- data/lib/spree/testing_support/factories/order_factory.rb +1 -1
- data/lib/spree/testing_support/factories/payment_factory.rb +1 -1
- data/lib/spree/testing_support/factories/payment_method_factory.rb +4 -4
- data/lib/spree/testing_support/factories/price_factory.rb +1 -1
- data/lib/spree/testing_support/factories/product_factory.rb +1 -1
- data/lib/spree/testing_support/factories/product_option_type_factory.rb +1 -1
- data/lib/spree/testing_support/factories/product_property_factory.rb +1 -1
- data/lib/spree/testing_support/factories/promotion_category_factory.rb +1 -2
- data/lib/spree/testing_support/factories/promotion_factory.rb +1 -2
- data/lib/spree/testing_support/factories/promotion_rule_factory.rb +1 -1
- data/lib/spree/testing_support/factories/property_factory.rb +1 -1
- data/lib/spree/testing_support/factories/prototype_factory.rb +1 -1
- data/lib/spree/testing_support/factories/refund_factory.rb +1 -1
- data/lib/spree/testing_support/factories/reimbursement_factory.rb +2 -2
- data/lib/spree/testing_support/factories/reimbursement_type_factory.rb +1 -1
- data/lib/spree/testing_support/factories/return_authorization_factory.rb +1 -1
- data/lib/spree/testing_support/factories/return_item_factory.rb +1 -1
- data/lib/spree/testing_support/factories/role_factory.rb +1 -1
- data/lib/spree/testing_support/factories/shipment_factory.rb +2 -2
- data/lib/spree/testing_support/factories/shipping_category_factory.rb +1 -1
- data/lib/spree/testing_support/factories/shipping_method_factory.rb +3 -3
- data/lib/spree/testing_support/factories/state_factory.rb +1 -1
- data/lib/spree/testing_support/factories/stock_factory.rb +1 -1
- data/lib/spree/testing_support/factories/stock_item_factory.rb +1 -1
- data/lib/spree/testing_support/factories/stock_location_factory.rb +2 -2
- data/lib/spree/testing_support/factories/stock_movement_factory.rb +1 -1
- data/lib/spree/testing_support/factories/store_credit_category_factory.rb +2 -2
- data/lib/spree/testing_support/factories/store_credit_event_factory.rb +1 -1
- data/lib/spree/testing_support/factories/store_credit_factory.rb +1 -1
- data/lib/spree/testing_support/factories/store_credit_type_factory.rb +1 -1
- data/lib/spree/testing_support/factories/store_factory.rb +1 -1
- data/lib/spree/testing_support/factories/tag_factory.rb +1 -1
- data/lib/spree/testing_support/factories/tax_category_factory.rb +2 -2
- data/lib/spree/testing_support/factories/tax_rate_factory.rb +1 -1
- data/lib/spree/testing_support/factories/taxon_factory.rb +1 -1
- data/lib/spree/testing_support/factories/taxonomy_factory.rb +1 -1
- data/lib/spree/testing_support/factories/tracker_factory.rb +1 -1
- data/lib/spree/testing_support/factories/user_factory.rb +1 -1
- data/lib/spree/testing_support/factories/variant_factory.rb +1 -2
- data/lib/spree/testing_support/factories/zone_factory.rb +1 -1
- data/lib/spree/testing_support/factories/zone_member_factory.rb +1 -1
- data/lib/spree/testing_support/factories.rb +3 -3
- data/lib/spree/testing_support/flash.rb +1 -3
- data/lib/spree/testing_support/i18n.rb +5 -6
- data/lib/spree/testing_support/kernel.rb +1 -2
- data/lib/spree/testing_support/order_walkthrough.rb +12 -15
- data/lib/spree/testing_support/preferences.rb +0 -1
- data/lib/tasks/core.rake +47 -56
- data/lib/tasks/email.rake +2 -2
- data/lib/tasks/exchanges.rake +5 -5
- data/spree_core.gemspec +1 -1
- metadata +5 -9
- data/app/models/spree/calculator/percent_per_item.rb +0 -51
- data/config/initializers/premailer_rails.rb +0 -3
- data/lib/spree/core/delegate_belongs_to.rb +0 -99
- data/lib/spree/testing_support/microdata.rb +0 -192
@@ -2,54 +2,52 @@ module Spree
|
|
2
2
|
module Core
|
3
3
|
module Importer
|
4
4
|
class Order
|
5
|
-
|
6
5
|
def self.import(user, params)
|
7
|
-
begin
|
8
|
-
ensure_country_id_from_params params[:ship_address_attributes]
|
9
|
-
ensure_state_id_from_params params[:ship_address_attributes]
|
10
|
-
ensure_country_id_from_params params[:bill_address_attributes]
|
11
|
-
ensure_state_id_from_params params[:bill_address_attributes]
|
12
6
|
|
13
|
-
|
14
|
-
|
15
|
-
|
7
|
+
ensure_country_id_from_params params[:ship_address_attributes]
|
8
|
+
ensure_state_id_from_params params[:ship_address_attributes]
|
9
|
+
ensure_country_id_from_params params[:bill_address_attributes]
|
10
|
+
ensure_state_id_from_params params[:bill_address_attributes]
|
16
11
|
|
17
|
-
|
12
|
+
create_params = params.slice :currency
|
13
|
+
order = Spree::Order.create! create_params
|
14
|
+
order.associate_user!(user)
|
18
15
|
|
19
|
-
|
20
|
-
create_shipments_from_params(shipments_attrs, order)
|
21
|
-
create_adjustments_from_params(params.delete(:adjustments_attributes), order)
|
22
|
-
create_payments_from_params(params.delete(:payments_attributes), order)
|
16
|
+
shipments_attrs = params.delete(:shipments_attributes)
|
23
17
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
18
|
+
create_line_items_from_params(params.delete(:line_items_attributes), order)
|
19
|
+
create_shipments_from_params(shipments_attrs, order)
|
20
|
+
create_adjustments_from_params(params.delete(:adjustments_attributes), order)
|
21
|
+
create_payments_from_params(params.delete(:payments_attributes), order)
|
28
22
|
|
29
|
-
|
23
|
+
if completed_at = params.delete(:completed_at)
|
24
|
+
order.completed_at = completed_at
|
25
|
+
order.state = 'complete'
|
26
|
+
end
|
30
27
|
|
31
|
-
|
28
|
+
params.delete(:user_id) unless user.try(:has_spree_role?, 'admin') && params.key?(:user_id)
|
32
29
|
|
33
|
-
|
30
|
+
order.update_attributes!(params)
|
34
31
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
32
|
+
order.create_proposed_shipments unless shipments_attrs.present?
|
33
|
+
|
34
|
+
# Really ensure that the order totals & states are correct
|
35
|
+
order.updater.update
|
36
|
+
if shipments_attrs.present?
|
37
|
+
order.shipments.each_with_index do |shipment, index|
|
38
|
+
shipment.update_columns(cost: shipments_attrs[index][:cost].to_f) if shipments_attrs[index][:cost].present?
|
41
39
|
end
|
42
|
-
order.reload
|
43
|
-
rescue Exception => e
|
44
|
-
order.destroy if order && order.persisted?
|
45
|
-
raise e.message
|
46
40
|
end
|
41
|
+
order.reload
|
42
|
+
rescue Exception => e
|
43
|
+
order.destroy if order && order.persisted?
|
44
|
+
raise e.message
|
45
|
+
|
47
46
|
end
|
48
47
|
|
49
48
|
def self.create_shipments_from_params(shipments_hash, order)
|
50
49
|
return [] unless shipments_hash
|
51
50
|
|
52
|
-
|
53
51
|
shipments_hash.each do |s|
|
54
52
|
begin
|
55
53
|
shipment = order.shipments.build
|
@@ -90,7 +88,7 @@ module Spree
|
|
90
88
|
end
|
91
89
|
|
92
90
|
def self.create_inventory_units_from_order_and_params(order, inventory_unit_params)
|
93
|
-
inventory_unit_params.
|
91
|
+
inventory_unit_params.each_with_object([]) do |inventory_unit_param, inventory_units|
|
94
92
|
ensure_variant_id_from_params(inventory_unit_param)
|
95
93
|
existing = inventory_units.detect { |unit| unit.variant_id == inventory_unit_param[:variant_id] }
|
96
94
|
if existing
|
@@ -99,15 +97,15 @@ module Spree
|
|
99
97
|
line_item = order.line_items.detect { |ln| ln.variant_id = inventory_unit_param[:variant_id] }
|
100
98
|
inventory_units << InventoryUnit.new(line_item: line_item, order_id: order.id, variant: line_item.variant, quantity: 1)
|
101
99
|
end
|
102
|
-
|
100
|
+
|
103
101
|
end
|
104
102
|
end
|
105
103
|
|
106
104
|
def self.create_line_items_from_params(line_items, order)
|
107
105
|
return {} unless line_items
|
108
106
|
iterator = case line_items
|
109
|
-
|
110
|
-
|
107
|
+
when Hash
|
108
|
+
ActiveSupport::Deprecation.warn(<<-EOS, caller)
|
111
109
|
Passing a hash is now deprecated and will be removed in Spree 4.0.
|
112
110
|
It is recommended that you pass it as an array instead.
|
113
111
|
|
@@ -133,9 +131,9 @@ module Spree
|
|
133
131
|
}
|
134
132
|
}
|
135
133
|
EOS
|
136
|
-
|
137
|
-
|
138
|
-
|
134
|
+
:each_value
|
135
|
+
when Array
|
136
|
+
:each
|
139
137
|
end
|
140
138
|
|
141
139
|
line_items.send(iterator) do |line_item|
|
@@ -197,39 +195,39 @@ module Spree
|
|
197
195
|
end
|
198
196
|
|
199
197
|
def self.create_source_payment_from_params(source_hash, payment)
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
198
|
+
|
199
|
+
Spree::CreditCard.create(
|
200
|
+
month: source_hash[:month],
|
201
|
+
year: source_hash[:year],
|
202
|
+
cc_type: source_hash[:cc_type],
|
203
|
+
last_digits: source_hash[:last_digits],
|
204
|
+
name: source_hash[:name],
|
205
|
+
payment_method: payment.payment_method,
|
206
|
+
gateway_customer_profile_id: source_hash[:gateway_customer_profile_id],
|
207
|
+
gateway_payment_profile_id: source_hash[:gateway_payment_profile_id],
|
208
|
+
imported: true
|
209
|
+
)
|
210
|
+
rescue Exception => e
|
211
|
+
raise "Order import source payments: #{e.message} #{source_hash}"
|
212
|
+
|
215
213
|
end
|
216
214
|
|
217
215
|
def self.ensure_variant_id_from_params(hash)
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
end
|
223
|
-
hash
|
224
|
-
rescue ActiveRecord::RecordNotFound => e
|
225
|
-
raise "Ensure order import variant: Variant w/SKU #{sku} not found."
|
226
|
-
rescue Exception => e
|
227
|
-
raise "Ensure order import variant: #{e.message} #{hash}"
|
216
|
+
|
217
|
+
sku = hash.delete(:sku)
|
218
|
+
unless hash[:variant_id].present?
|
219
|
+
hash[:variant_id] = Spree::Variant.active.find_by!(sku: sku).id
|
228
220
|
end
|
221
|
+
hash
|
222
|
+
rescue ActiveRecord::RecordNotFound => e
|
223
|
+
raise "Ensure order import variant: Variant w/SKU #{sku} not found."
|
224
|
+
rescue Exception => e
|
225
|
+
raise "Ensure order import variant: #{e.message} #{hash}"
|
226
|
+
|
229
227
|
end
|
230
228
|
|
231
229
|
def self.ensure_country_id_from_params(address)
|
232
|
-
return if address.nil?
|
230
|
+
return if address.nil? || address[:country_id].present? || address[:country].nil?
|
233
231
|
|
234
232
|
begin
|
235
233
|
search = {}
|
@@ -245,14 +243,13 @@ module Spree
|
|
245
243
|
|
246
244
|
address.delete(:country)
|
247
245
|
address[:country_id] = Spree::Country.where(search).first!.id
|
248
|
-
|
249
246
|
rescue Exception => e
|
250
247
|
raise "Ensure order import address country: #{e.message} #{search}"
|
251
248
|
end
|
252
249
|
end
|
253
250
|
|
254
251
|
def self.ensure_state_id_from_params(address)
|
255
|
-
return if address.nil?
|
252
|
+
return if address.nil? || address[:state_id].present? || address[:state].nil?
|
256
253
|
|
257
254
|
begin
|
258
255
|
search = {}
|
@@ -44,18 +44,19 @@ module Spree
|
|
44
44
|
end
|
45
45
|
|
46
46
|
private
|
47
|
-
def set_up_options
|
48
|
-
options_attrs.each do |name|
|
49
|
-
option_type = Spree::OptionType.where(name: name).first_or_initialize do |option_type|
|
50
|
-
option_type.presentation = name
|
51
|
-
option_type.save!
|
52
|
-
end
|
53
47
|
|
54
|
-
|
55
|
-
|
56
|
-
|
48
|
+
def set_up_options
|
49
|
+
options_attrs.each do |name|
|
50
|
+
option_type = Spree::OptionType.where(name: name).first_or_initialize do |option_type|
|
51
|
+
option_type.presentation = name
|
52
|
+
option_type.save!
|
53
|
+
end
|
54
|
+
|
55
|
+
unless product.option_types.include?(option_type)
|
56
|
+
product.option_types << option_type
|
57
57
|
end
|
58
58
|
end
|
59
|
+
end
|
59
60
|
end
|
60
61
|
end
|
61
62
|
end
|
@@ -53,7 +53,7 @@ module Spree
|
|
53
53
|
# below scope would be something like ["$10 - $15", "$15 - $18", "$18 - $20"]
|
54
54
|
#
|
55
55
|
Spree::Product.add_search_scope :price_range_any do |*opts|
|
56
|
-
conds = opts.map {|o| Spree::Core::ProductFilters.price_filter[:conds][o]}.reject
|
56
|
+
conds = opts.map { |o| Spree::Core::ProductFilters.price_filter[:conds][o] }.reject(&:nil?)
|
57
57
|
scope = conds.shift
|
58
58
|
conds.each do |new_scope|
|
59
59
|
scope = scope.or(new_scope)
|
@@ -61,26 +61,25 @@ module Spree
|
|
61
61
|
Spree::Product.joins(master: :default_price).where(scope)
|
62
62
|
end
|
63
63
|
|
64
|
-
def
|
64
|
+
def self.format_price(amount)
|
65
65
|
Spree::Money.new(amount)
|
66
66
|
end
|
67
67
|
|
68
|
-
def
|
68
|
+
def self.price_filter
|
69
69
|
v = Spree::Price.arel_table
|
70
|
-
conds = [
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
70
|
+
conds = [[Spree.t(:under_price, price: format_price(10)), v[:amount].lteq(10)],
|
71
|
+
["#{format_price(10)} - #{format_price(15)}", v[:amount].in(10..15)],
|
72
|
+
["#{format_price(15)} - #{format_price(18)}", v[:amount].in(15..18)],
|
73
|
+
["#{format_price(18)} - #{format_price(20)}", v[:amount].in(18..20)],
|
74
|
+
[Spree.t(:or_over_price, price: format_price(20)), v[:amount].gteq(20)]]
|
75
75
|
{
|
76
76
|
name: Spree.t(:price_range),
|
77
77
|
scope: :price_range_any,
|
78
78
|
conds: Hash[*conds.flatten],
|
79
|
-
labels: conds.map { |k,
|
79
|
+
labels: conds.map { |k, _v| [k, k] }
|
80
80
|
}
|
81
81
|
end
|
82
82
|
|
83
|
-
|
84
83
|
# Example: filtering by possible brands
|
85
84
|
#
|
86
85
|
# First, we define the scope. Two interesting points here: (a) we run our conditions
|
@@ -94,7 +93,7 @@ module Spree
|
|
94
93
|
# being blank: note that this relies on with_property doing a left outer join
|
95
94
|
# rather than an inner join.
|
96
95
|
Spree::Product.add_search_scope :brand_any do |*opts|
|
97
|
-
conds = opts.map {|o| ProductFilters.brand_filter[:conds][o]}.reject
|
96
|
+
conds = opts.map { |o| ProductFilters.brand_filter[:conds][o] }.reject(&:nil?)
|
98
97
|
scope = conds.shift
|
99
98
|
conds.each do |new_scope|
|
100
99
|
scope = scope.or(new_scope)
|
@@ -102,7 +101,7 @@ module Spree
|
|
102
101
|
Spree::Product.with_property('brand').where(scope)
|
103
102
|
end
|
104
103
|
|
105
|
-
def
|
104
|
+
def self.brand_filter
|
106
105
|
brand_property = Spree::Property.find_by(name: 'brand')
|
107
106
|
brands = brand_property ? Spree::ProductProperty.where(property_id: brand_property.id).pluck(:value).uniq.map(&:to_s) : []
|
108
107
|
pp = Spree::ProductProperty.arel_table
|
@@ -111,7 +110,7 @@ module Spree
|
|
111
110
|
name: I18n.t('spree.taxonomy_brands_name'),
|
112
111
|
scope: :brand_any,
|
113
112
|
conds: conds,
|
114
|
-
labels:
|
113
|
+
labels: brands.sort.map { |k| [k, k] }
|
115
114
|
}
|
116
115
|
end
|
117
116
|
|
@@ -138,12 +137,12 @@ module Spree
|
|
138
137
|
Spree::Product.brand_any(*opts)
|
139
138
|
end
|
140
139
|
|
141
|
-
def
|
140
|
+
def self.selective_brand_filter(taxon = nil)
|
142
141
|
taxon ||= Spree::Taxonomy.first.root
|
143
142
|
brand_property = Spree::Property.find_by(name: 'brand')
|
144
143
|
scope = Spree::ProductProperty.where(property: brand_property).
|
145
|
-
|
146
|
-
|
144
|
+
joins(product: :taxons).
|
145
|
+
where("#{Spree::Taxon.table_name}.id" => [taxon] + taxon.descendants)
|
147
146
|
brands = scope.pluck(:value).uniq
|
148
147
|
{
|
149
148
|
name: 'Applicable Brands',
|
@@ -164,7 +163,7 @@ module Spree
|
|
164
163
|
#
|
165
164
|
# This scope selects products in any of the active taxons or their children.
|
166
165
|
#
|
167
|
-
def
|
166
|
+
def self.taxons_below(taxon)
|
168
167
|
return Spree::Core::ProductFilters.all_taxons if taxon.nil?
|
169
168
|
{
|
170
169
|
name: 'Taxons under ' + taxon.name,
|
@@ -180,7 +179,7 @@ module Spree
|
|
180
179
|
# it uses one of the auto-generated scopes from Ransack.
|
181
180
|
#
|
182
181
|
# idea: expand the format to allow nesting of labels?
|
183
|
-
def
|
182
|
+
def self.all_taxons
|
184
183
|
taxons = Spree::Taxonomy.all.map { |t| [t.root] + t.root.descendants }.flatten
|
185
184
|
{
|
186
185
|
name: 'All taxons',
|
data/lib/spree/core/routes.rb
CHANGED
@@ -14,17 +14,13 @@ module Spree
|
|
14
14
|
# This is mainly why this whole file exists in the first place.
|
15
15
|
#
|
16
16
|
# Thus we need to make sure that the routes aren't drawn twice.
|
17
|
-
unless @spree_routes.include?(block)
|
18
|
-
@spree_routes << block
|
19
|
-
end
|
17
|
+
@spree_routes << block unless @spree_routes.include?(block)
|
20
18
|
end
|
21
19
|
|
22
20
|
def self.append_routes(&block)
|
23
21
|
@append_routes ||= []
|
24
22
|
# See comment in add_routes.
|
25
|
-
unless @append_routes.include?(block)
|
26
|
-
@append_routes << block
|
27
|
-
end
|
23
|
+
@append_routes << block unless @append_routes.include?(block)
|
28
24
|
end
|
29
25
|
|
30
26
|
def self.draw_routes(&block)
|
@@ -17,14 +17,14 @@ module Spree
|
|
17
17
|
curr_page = page || 1
|
18
18
|
|
19
19
|
unless Spree::Config.show_products_without_price
|
20
|
-
@products = @products.where(
|
21
|
-
|
20
|
+
@products = @products.where('spree_prices.amount IS NOT NULL').
|
21
|
+
where('spree_prices.currency' => current_currency)
|
22
22
|
end
|
23
23
|
@products = @products.page(curr_page).per(per_page)
|
24
24
|
end
|
25
25
|
|
26
26
|
def method_missing(name)
|
27
|
-
if @properties.
|
27
|
+
if @properties.key? name
|
28
28
|
@properties[name]
|
29
29
|
else
|
30
30
|
super
|
@@ -32,71 +32,74 @@ module Spree
|
|
32
32
|
end
|
33
33
|
|
34
34
|
protected
|
35
|
-
def get_base_scope
|
36
|
-
base_scope = Spree::Product.spree_base_scopes.active
|
37
|
-
base_scope = base_scope.in_taxon(taxon) unless taxon.blank?
|
38
|
-
base_scope = get_products_conditions_for(base_scope, keywords)
|
39
|
-
base_scope = add_search_scopes(base_scope)
|
40
|
-
base_scope = add_eagerload_scopes(base_scope)
|
41
|
-
base_scope
|
42
|
-
end
|
43
35
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
# or multiple independent queries. However as of Rails 4.1.8 any `order`
|
53
|
-
# defined on `has_many` associations are ignored when Rails builds a join
|
54
|
-
# query.
|
55
|
-
#
|
56
|
-
# Would we use `includes` in this particular case, Rails would do
|
57
|
-
# separate queries most of the time but opt for a join as soon as any
|
58
|
-
# `where` constraints affecting joined tables are added to the search;
|
59
|
-
# which is the case as soon as a taxon is added to the base scope.
|
60
|
-
scope = scope.preload(:tax_category)
|
61
|
-
scope = scope.preload(master: :prices)
|
62
|
-
scope = scope.preload(master: :images) if include_images
|
63
|
-
scope
|
64
|
-
end
|
36
|
+
def get_base_scope
|
37
|
+
base_scope = Spree::Product.spree_base_scopes.active
|
38
|
+
base_scope = base_scope.in_taxon(taxon) unless taxon.blank?
|
39
|
+
base_scope = get_products_conditions_for(base_scope, keywords)
|
40
|
+
base_scope = add_search_scopes(base_scope)
|
41
|
+
base_scope = add_eagerload_scopes(base_scope)
|
42
|
+
base_scope
|
43
|
+
end
|
65
44
|
|
66
|
-
|
45
|
+
def add_eagerload_scopes(scope)
|
46
|
+
# TL;DR Switch from `preload` to `includes` as soon as Rails starts honoring
|
47
|
+
# `order` clauses on `has_many` associations when a `where` constraint
|
48
|
+
# affecting a joined table is present (see
|
49
|
+
# https://github.com/rails/rails/issues/6769).
|
50
|
+
#
|
51
|
+
# Ideally this would use `includes` instead of `preload` calls, leaving it
|
52
|
+
# up to Rails whether associated objects should be fetched in one big join
|
53
|
+
# or multiple independent queries. However as of Rails 4.1.8 any `order`
|
54
|
+
# defined on `has_many` associations are ignored when Rails builds a join
|
55
|
+
# query.
|
56
|
+
#
|
57
|
+
# Would we use `includes` in this particular case, Rails would do
|
58
|
+
# separate queries most of the time but opt for a join as soon as any
|
59
|
+
# `where` constraints affecting joined tables are added to the search;
|
60
|
+
# which is the case as soon as a taxon is added to the base scope.
|
61
|
+
scope = scope.preload(:tax_category)
|
62
|
+
scope = scope.preload(master: :prices)
|
63
|
+
scope = scope.preload(master: :images) if include_images
|
64
|
+
scope
|
65
|
+
end
|
66
|
+
|
67
|
+
def add_search_scopes(base_scope)
|
68
|
+
if search.is_a?(ActionController::Parameters)
|
67
69
|
search.each do |name, scope_attribute|
|
68
70
|
scope_name = name.to_sym
|
69
|
-
if base_scope.respond_to?(:search_scopes) && base_scope.search_scopes.include?(scope_name.to_sym)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end
|
75
|
-
base_scope
|
71
|
+
base_scope = if base_scope.respond_to?(:search_scopes) && base_scope.search_scopes.include?(scope_name.to_sym)
|
72
|
+
base_scope.send(scope_name, *scope_attribute)
|
73
|
+
else
|
74
|
+
base_scope.merge(Spree::Product.ransack(scope_name => scope_attribute).result)
|
75
|
+
end
|
76
|
+
end
|
76
77
|
end
|
78
|
+
base_scope
|
79
|
+
end
|
77
80
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
end
|
83
|
-
base_scope
|
81
|
+
# method should return new scope based on base_scope
|
82
|
+
def get_products_conditions_for(base_scope, query)
|
83
|
+
unless query.blank?
|
84
|
+
base_scope = base_scope.like_any([:name, :description], query.split)
|
84
85
|
end
|
86
|
+
base_scope
|
87
|
+
end
|
85
88
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
89
|
+
def prepare(params)
|
90
|
+
@properties[:taxon] = params[:taxon].blank? ? nil : Spree::Taxon.find(params[:taxon])
|
91
|
+
@properties[:keywords] = params[:keywords]
|
92
|
+
@properties[:search] = params[:search]
|
93
|
+
@properties[:include_images] = params[:include_images]
|
91
94
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
95
|
+
per_page = params[:per_page].to_i
|
96
|
+
@properties[:per_page] = per_page > 0 ? per_page : Spree::Config[:products_per_page]
|
97
|
+
@properties[:page] = if params[:page].respond_to?(:to_i)
|
98
|
+
params[:page].to_i <= 0 ? 1 : params[:page].to_i
|
99
|
+
else
|
100
|
+
1
|
101
|
+
end
|
102
|
+
end
|
100
103
|
end
|
101
104
|
end
|
102
105
|
end
|
data/lib/spree/core/version.rb
CHANGED
data/lib/spree/core.rb
CHANGED
@@ -19,12 +19,11 @@ require 'state_machines-activerecord'
|
|
19
19
|
StateMachines::Machine.ignore_method_conflicts = true
|
20
20
|
|
21
21
|
module Spree
|
22
|
-
|
23
22
|
mattr_accessor :user_class
|
24
23
|
|
25
24
|
def self.user_class
|
26
25
|
if @@user_class.is_a?(Class)
|
27
|
-
raise
|
26
|
+
raise 'Spree.user_class MUST be a String or Symbol object, not a Class object.'
|
28
27
|
elsif @@user_class.is_a?(String) || @@user_class.is_a?(Symbol)
|
29
28
|
@@user_class.to_s.constantize
|
30
29
|
end
|
@@ -55,13 +54,13 @@ module Spree
|
|
55
54
|
#
|
56
55
|
# This method is defined within the core gem on purpose.
|
57
56
|
# Some people may only wish to use the Core part of Spree.
|
58
|
-
def self.config
|
57
|
+
def self.config
|
59
58
|
yield(Spree::Config)
|
60
59
|
end
|
61
60
|
|
62
61
|
module Core
|
63
|
-
autoload :ProductFilters,
|
64
|
-
autoload :TokenGenerator,
|
62
|
+
autoload :ProductFilters, 'spree/core/product_filters'
|
63
|
+
autoload :TokenGenerator, 'spree/core/token_generator'
|
65
64
|
|
66
65
|
class GatewayError < RuntimeError; end
|
67
66
|
class DestroyWithOrdersError < StandardError; end
|
@@ -83,7 +82,6 @@ require 'spree/localized_number'
|
|
83
82
|
require 'spree/money'
|
84
83
|
require 'spree/permitted_attributes'
|
85
84
|
|
86
|
-
require 'spree/core/delegate_belongs_to'
|
87
85
|
require 'spree/core/importer'
|
88
86
|
require 'spree/core/product_duplicator'
|
89
87
|
require 'spree/core/controller_helpers/auth'
|
data/lib/spree/i18n.rb
CHANGED
@@ -18,7 +18,7 @@ module Spree
|
|
18
18
|
super(*args)
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
alias t translate
|
22
22
|
|
23
23
|
def context
|
24
24
|
Spree::ViewContext.context
|
@@ -26,11 +26,9 @@ module Spree
|
|
26
26
|
|
27
27
|
def virtual_path
|
28
28
|
if context
|
29
|
-
path = context.instance_variable_get(
|
29
|
+
path = context.instance_variable_get('@virtual_path')
|
30
30
|
|
31
|
-
if path
|
32
|
-
path.gsub(/spree/, '')
|
33
|
-
end
|
31
|
+
path.gsub(/spree/, '') if path
|
34
32
|
end
|
35
33
|
end
|
36
34
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module Spree
|
2
2
|
class LocalizedNumber
|
3
|
-
|
4
3
|
# Strips all non-price-like characters from the number, taking into account locale settings.
|
5
4
|
def self.parse(number)
|
6
5
|
return number unless number.is_a?(String)
|
@@ -20,6 +19,5 @@ module Spree
|
|
20
19
|
|
21
20
|
number.to_d
|
22
21
|
end
|
23
|
-
|
24
22
|
end
|
25
23
|
end
|
data/lib/spree/migrations.rb
CHANGED
@@ -4,7 +4,8 @@ module Spree
|
|
4
4
|
|
5
5
|
# Takes the engine config block and engine name
|
6
6
|
def initialize(config, engine_name)
|
7
|
-
@config
|
7
|
+
@config = config
|
8
|
+
@engine_name = engine_name
|
8
9
|
end
|
9
10
|
|
10
11
|
# Puts warning when any engine migration is not present on the Rails app
|
@@ -23,7 +24,7 @@ module Spree
|
|
23
24
|
def check
|
24
25
|
if File.directory?(app_dir)
|
25
26
|
engine_in_app = app_migrations.map do |file_name|
|
26
|
-
name, engine = file_name.split(
|
27
|
+
name, engine = file_name.split('.', 2)
|
27
28
|
next unless match_engine?(engine)
|
28
29
|
name
|
29
30
|
end.compact
|
@@ -44,15 +45,15 @@ module Spree
|
|
44
45
|
|
45
46
|
def engine_migrations
|
46
47
|
Dir.entries(engine_dir).map do |file_name|
|
47
|
-
name = file_name.split(
|
48
|
+
name = file_name.split('_', 2).last.split('.', 2).first
|
48
49
|
name.empty? ? next : name
|
49
50
|
end.compact! || []
|
50
51
|
end
|
51
52
|
|
52
53
|
def app_migrations
|
53
54
|
Dir.entries(app_dir).map do |file_name|
|
54
|
-
next if [
|
55
|
-
name = file_name.split(
|
55
|
+
next if ['.', '..'].include? file_name
|
56
|
+
name = file_name.split('_', 2).last
|
56
57
|
name.empty? ? next : name
|
57
58
|
end.compact! || []
|
58
59
|
end
|
@@ -66,9 +67,9 @@ module Spree
|
|
66
67
|
end
|
67
68
|
|
68
69
|
def match_engine?(engine)
|
69
|
-
if engine_name ==
|
70
|
+
if engine_name == 'spree'
|
70
71
|
# Avoid stores upgrading from 1.3 getting wrong warnings
|
71
|
-
[
|
72
|
+
['spree.rb', 'spree_promo.rb'].include? engine
|
72
73
|
else
|
73
74
|
engine == "#{engine_name}.rb"
|
74
75
|
end
|