solidus_core 4.6.5 → 4.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +13 -13
- data/app/controllers/spree/base_controller.rb +2 -2
- data/app/helpers/spree/base_helper.rb +24 -24
- data/app/helpers/spree/checkout_helper.rb +7 -7
- data/app/helpers/spree/core/controller_helpers/auth.rb +1 -1
- data/app/helpers/spree/core/controller_helpers/common.rb +3 -2
- data/app/helpers/spree/core/controller_helpers/order.rb +3 -5
- data/app/helpers/spree/core/controller_helpers/payment_parameters.rb +1 -2
- data/app/helpers/spree/core/controller_helpers/strong_parameters.rb +10 -12
- data/app/helpers/spree/products_helper.rb +6 -6
- data/app/helpers/spree/store_helper.rb +1 -1
- data/app/mailers/spree/carton_mailer.rb +3 -3
- data/app/mailers/spree/order_mailer.rb +4 -4
- data/app/mailers/spree/reimbursement_mailer.rb +2 -2
- data/app/models/concerns/spree/active_storage_adapter/attachment.rb +5 -5
- data/app/models/concerns/spree/active_storage_adapter/normalization.rb +5 -5
- data/app/models/concerns/spree/active_storage_adapter.rb +2 -2
- data/app/models/concerns/spree/adjustment_source.rb +4 -4
- data/app/models/concerns/spree/display_money.rb +2 -2
- data/app/models/concerns/spree/named_type.rb +1 -1
- data/app/models/concerns/spree/ordered_property_value_list.rb +2 -2
- data/app/models/concerns/spree/preferences/persistable.rb +1 -1
- data/app/models/concerns/spree/ransackable_attributes.rb +1 -0
- data/app/models/concerns/spree/soft_deletable.rb +2 -1
- data/app/models/concerns/spree/state_change_tracking.rb +1 -1
- data/app/models/concerns/spree/user_address_book.rb +12 -12
- data/app/models/concerns/spree/user_methods.rb +13 -13
- data/app/models/concerns/spree/user_reporting.rb +1 -0
- data/app/models/spree/ability.rb +1 -1
- data/app/models/spree/address/name.rb +1 -1
- data/app/models/spree/address.rb +7 -7
- data/app/models/spree/adjustment.rb +11 -10
- data/app/models/spree/adjustment_reason.rb +2 -2
- data/app/models/spree/billing_integration.rb +2 -2
- data/app/models/spree/calculator/default_tax.rb +2 -2
- data/app/models/spree/calculator/flat_fee.rb +1 -1
- data/app/models/spree/calculator/flat_rate.rb +2 -2
- data/app/models/spree/calculator/returns/default_refund_amount.rb +3 -3
- data/app/models/spree/calculator/shipping/flat_percent_item_total.rb +2 -2
- data/app/models/spree/calculator/shipping/flat_rate.rb +3 -3
- data/app/models/spree/calculator/shipping/flexi_rate.rb +8 -8
- data/app/models/spree/calculator/shipping/per_item.rb +3 -3
- data/app/models/spree/calculator/shipping/price_sack.rb +3 -3
- data/app/models/spree/calculator.rb +31 -6
- data/app/models/spree/carton.rb +4 -4
- data/app/models/spree/classification.rb +2 -2
- data/app/models/spree/core/state_machines/order/class_methods.rb +3 -3
- data/app/models/spree/core/state_machines/return_item/acceptance_status.rb +1 -1
- data/app/models/spree/country.rb +1 -1
- data/app/models/spree/credit_card.rb +27 -27
- data/app/models/spree/customer_return.rb +5 -4
- data/app/models/spree/distributed_amounts_handler.rb +1 -1
- data/app/models/spree/fulfilment_changer.rb +22 -22
- data/app/models/spree/image/active_storage_attachment.rb +2 -2
- data/app/models/spree/image/paperclip_attachment.rb +8 -8
- data/app/models/spree/in_memory_order_updater.rb +262 -0
- data/app/models/spree/inventory_unit.rb +11 -11
- data/app/models/spree/item_total.rb +1 -1
- data/app/models/spree/legacy_user.rb +2 -2
- data/app/models/spree/line_item.rb +21 -11
- data/app/models/spree/log_entry.rb +3 -3
- data/app/models/spree/mergeable_orders_finder.rb +44 -0
- data/app/models/spree/money.rb +2 -1
- data/app/models/spree/null_promotion_adjuster.rb +1 -1
- data/app/models/spree/option_type.rb +1 -1
- data/app/models/spree/option_value.rb +2 -2
- data/app/models/spree/order/number_generator.rb +1 -1
- data/app/models/spree/order.rb +66 -71
- data/app/models/spree/order_cancellations.rb +1 -3
- data/app/models/spree/order_inventory.rb +5 -8
- data/app/models/spree/order_mutex.rb +1 -1
- data/app/models/spree/order_shipping.rb +1 -1
- data/app/models/spree/order_updater.rb +59 -37
- data/app/models/spree/payment/cancellation.rb +2 -2
- data/app/models/spree/payment/processing.rb +22 -22
- data/app/models/spree/payment.rb +25 -25
- data/app/models/spree/payment_capture_event.rb +2 -2
- data/app/models/spree/payment_create.rb +1 -26
- data/app/models/spree/payment_method/bogus_credit_card.rb +18 -18
- data/app/models/spree/payment_method/check.rb +3 -3
- data/app/models/spree/payment_method/credit_card.rb +1 -1
- data/app/models/spree/payment_method/simple_bogus_credit_card.rb +3 -3
- data/app/models/spree/payment_method/store_credit.rb +13 -13
- data/app/models/spree/payment_method.rb +12 -11
- data/app/models/spree/payment_source.rb +2 -2
- data/app/models/spree/permission_sets/dashboard_display.rb +3 -3
- data/app/models/spree/permission_sets/default_customer.rb +4 -4
- data/app/models/spree/preference.rb +1 -1
- data/app/models/spree/price.rb +7 -6
- data/app/models/spree/product/scopes.rb +23 -23
- data/app/models/spree/product.rb +38 -50
- data/app/models/spree/product_option_type.rb +2 -2
- data/app/models/spree/product_property.rb +3 -3
- data/app/models/spree/refund.rb +10 -10
- data/app/models/spree/refund_reason.rb +2 -2
- data/app/models/spree/reimbursement/credit.rb +1 -1
- data/app/models/spree/reimbursement.rb +8 -8
- data/app/models/spree/reimbursement_tax_calculator.rb +1 -1
- data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +1 -1
- data/app/models/spree/reimbursement_type.rb +2 -2
- data/app/models/spree/return_authorization.rb +7 -6
- data/app/models/spree/return_item/eligibility_validator/base_validator.rb +2 -2
- data/app/models/spree/return_item/eligibility_validator/default.rb +1 -1
- data/app/models/spree/return_item/eligibility_validator/inventory_shipped.rb +1 -1
- data/app/models/spree/return_item/eligibility_validator/no_reimbursements.rb +1 -1
- data/app/models/spree/return_item/eligibility_validator/order_completed.rb +1 -1
- data/app/models/spree/return_item/eligibility_validator/rma_required.rb +1 -1
- data/app/models/spree/return_item/eligibility_validator/time_since_purchase.rb +1 -1
- data/app/models/spree/return_item/exchange_variant_eligibility/same_option_value.rb +6 -6
- data/app/models/spree/return_item.rb +26 -34
- data/app/models/spree/return_reason.rb +1 -1
- data/app/models/spree/role.rb +1 -1
- data/app/models/spree/role_user.rb +1 -1
- data/app/models/spree/shipment.rb +37 -29
- data/app/models/spree/shipping_method.rb +9 -9
- data/app/models/spree/shipping_method_category.rb +2 -2
- data/app/models/spree/shipping_rate.rb +12 -10
- data/app/models/spree/shipping_rate_tax.rb +5 -4
- data/app/models/spree/simple_order_contents.rb +2 -2
- data/app/models/spree/state.rb +1 -1
- data/app/models/spree/stock/availability.rb +9 -9
- data/app/models/spree/stock/availability_validator.rb +3 -3
- data/app/models/spree/stock/differentiator.rb +2 -2
- data/app/models/spree/stock/estimator.rb +4 -4
- data/app/models/spree/stock/inventory_validator.rb +1 -1
- data/app/models/spree/stock/package.rb +3 -3
- data/app/models/spree/stock_item.rb +5 -5
- data/app/models/spree/stock_location.rb +6 -6
- data/app/models/spree/stock_movement.rb +2 -2
- data/app/models/spree/stock_quantities.rb +2 -2
- data/app/models/spree/store.rb +4 -5
- data/app/models/spree/store_credit.rb +30 -29
- data/app/models/spree/store_credit_category.rb +2 -2
- data/app/models/spree/store_credit_event.rb +6 -6
- data/app/models/spree/store_credit_reason.rb +1 -1
- data/app/models/spree/store_credit_type.rb +3 -3
- data/app/models/spree/store_selector/by_server_name.rb +1 -1
- data/app/models/spree/store_selector/legacy.rb +1 -1
- data/app/models/spree/tax/item_tax.rb +1 -0
- data/app/models/spree/tax/order_tax.rb +1 -0
- data/app/models/spree/tax_category.rb +3 -3
- data/app/models/spree/tax_rate.rb +5 -5
- data/app/models/spree/tax_rate_tax_category.rb +2 -2
- data/app/models/spree/taxon/active_storage_attachment.rb +2 -2
- data/app/models/spree/taxon/paperclip_attachment.rb +4 -4
- data/app/models/spree/taxon.rb +18 -22
- data/app/models/spree/taxon_brand_selector.rb +3 -3
- data/app/models/spree/unauthorized_redirect_handler.rb +1 -1
- data/app/models/spree/unit_cancel.rb +4 -4
- data/app/models/spree/user_address.rb +3 -3
- data/app/models/spree/user_last_url_storer/rules/authentication_rule.rb +6 -8
- data/app/models/spree/user_last_url_storer.rb +1 -1
- data/app/models/spree/variant/price_selector.rb +1 -1
- data/app/models/spree/variant/scopes.rb +9 -9
- data/app/models/spree/variant/vat_price_generator.rb +0 -1
- data/app/models/spree/variant.rb +25 -25
- data/app/models/spree/variant_property_rule.rb +2 -2
- data/app/models/spree/variant_property_rule_condition.rb +1 -1
- data/app/models/spree/wallet/add_payment_sources_to_wallet.rb +4 -4
- data/app/models/spree/wallet/default_payment_builder.rb +1 -1
- data/app/models/spree/wallet_payment_source.rb +2 -2
- data/app/models/spree/zone.rb +18 -18
- data/app/models/spree/zone_member.rb +1 -1
- data/app/subscribers/spree/carton_shipped_mailer_subscriber.rb +2 -2
- data/app/subscribers/spree/order_cancel_mailer_subscriber.rb +2 -2
- data/app/subscribers/spree/order_confirmation_mailer_subscriber.rb +2 -2
- data/app/subscribers/spree/order_inventory_cancellation_mailer_subscriber.rb +2 -2
- data/app/subscribers/spree/reimbursement_mailer_subscriber.rb +2 -2
- data/app/views/layouts/spree/base_mailer.html.erb +0 -1
- data/config/initializers/assets.rb +1 -1
- data/config/initializers/db_query_matchers.rb +9 -0
- data/config/initializers/friendly_id.rb +2 -2
- data/config/initializers/inflections.rb +1 -1
- data/config/initializers/money.rb +1 -1
- data/config/locales/en.yml +1 -0
- data/db/default/spree/countries.rb +7 -7
- data/db/default/spree/return_reasons.rb +11 -11
- data/db/default/spree/stock_locations.rb +1 -1
- data/db/default/spree/store_credit.rb +3 -4
- data/db/default/spree/stores.rb +1 -1
- data/db/default/spree/zones.rb +5 -5
- data/db/migrate/20160101010000_solidus_one_four.rb +16 -16
- data/db/migrate/20160420044191_create_spree_wallet_payment_sources.rb +3 -3
- data/db/migrate/20160420181916_migrate_credit_cards_to_wallet_payment_sources.rb +7 -6
- data/db/migrate/20161014221052_add_available_to_columns_and_remove_display_on_from_payment_methods.rb +10 -10
- data/db/migrate/20161123154034_add_available_to_users_and_remove_display_on_from_shipping_methods.rb +6 -6
- data/db/migrate/20161129035810_add_index_to_spree_payments_number.rb +1 -1
- data/db/migrate/20170319191942_remove_order_id_from_inventory_units.rb +4 -4
- data/db/migrate/20180322142651_add_amount_remaining_to_store_credit_events.rb +9 -15
- data/db/migrate/20200320144521_add_default_billng_flag_to_user_addresses.rb +1 -0
- data/db/migrate/20210815004823_add_unique_index_to_option_values_variants.rb +3 -3
- data/db/migrate/20250207104016_add_primary_taxon_to_products.rb +1 -1
- data/db/migrate/20250214094207_add_reverse_charge_status_to_store.rb +1 -1
- data/db/migrate/20250225051308_add_vat_id_email_and_reverse_charge_status_to_addresses.rb +1 -1
- data/db/seeds.rb +3 -3
- data/lib/generators/solidus/install/app_templates/authentication/custom.rb +2 -2
- data/lib/generators/solidus/install/app_templates/authentication/devise.rb +3 -3
- data/lib/generators/solidus/install/app_templates/authentication/existing.rb +1 -1
- data/lib/generators/solidus/install/app_templates/frontend/starter.rb +1 -1
- data/lib/generators/solidus/install/app_templates/payment_method/braintree.rb +1 -1
- data/lib/generators/solidus/install/app_templates/payment_method/paypal.rb +1 -1
- data/lib/generators/solidus/install/app_templates/payment_method/stripe.rb +2 -2
- data/lib/generators/solidus/install/install_generator.rb +51 -51
- data/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt +3 -0
- data/lib/generators/solidus/update/update_generator.rb +29 -29
- data/lib/generators/spree/custom_user/custom_user_generator.rb +6 -6
- data/lib/generators/spree/dummy/dummy_generator.rb +22 -24
- data/lib/generators/spree/dummy/templates/rails/boot.rb +3 -3
- data/lib/generators/spree/dummy/templates/rails/test.rb +4 -4
- data/lib/solidus_core.rb +1 -1
- data/lib/spree/app_configuration.rb +59 -47
- data/lib/spree/bus.rb +1 -1
- data/lib/spree/config.rb +1 -1
- data/lib/spree/core/active_merchant_dependencies.rb +8 -8
- data/lib/spree/core/class_constantizer.rb +1 -1
- data/lib/spree/core/engine.rb +15 -15
- data/lib/spree/core/environment.rb +1 -1
- data/lib/spree/core/environment_extension.rb +2 -2
- data/lib/spree/core/importer/order.rb +15 -15
- data/lib/spree/core/importer/product.rb +4 -4
- data/lib/spree/core/importer.rb +2 -2
- data/lib/spree/core/null_promotion_configuration.rb +7 -7
- data/lib/spree/core/permalinks.rb +1 -1
- data/lib/spree/core/product_filters.rb +94 -93
- data/lib/spree/core/role_configuration.rb +3 -3
- data/lib/spree/core/search/base.rb +5 -6
- data/lib/spree/core/search/variant.rb +3 -3
- data/lib/spree/core/stock_configuration.rb +10 -49
- data/lib/spree/core/validators/email.rb +1 -1
- data/lib/spree/core/version.rb +3 -3
- data/lib/spree/core/versioned_value.rb +4 -6
- data/lib/spree/core.rb +49 -49
- data/lib/spree/deprecated_instance_variable_proxy.rb +1 -1
- data/lib/spree/deprecation.rb +1 -1
- data/lib/spree/deprecator.rb +2 -2
- data/lib/spree/i18n.rb +2 -2
- data/lib/spree/localized_number.rb +3 -3
- data/lib/spree/manipulative_query_monitor.rb +19 -0
- data/lib/spree/migrations.rb +2 -2
- data/lib/spree/permitted_attributes.rb +11 -12
- data/lib/spree/preferences/configuration.rb +5 -5
- data/lib/spree/preferences/preferable.rb +8 -10
- data/lib/spree/preferences/preferable_class_methods.rb +16 -20
- data/lib/spree/preferences/preference_differentiator.rb +1 -1
- data/lib/spree/preferences/scoped_store.rb +2 -2
- data/lib/spree/preferences/static_model_preferences.rb +2 -2
- data/lib/spree/preferences/store.rb +6 -6
- data/lib/spree/testing_support/ability_helpers.rb +30 -30
- data/lib/spree/testing_support/authorization_helpers.rb +6 -5
- data/lib/spree/testing_support/blacklist_urls.rb +1 -1
- data/lib/spree/testing_support/bus_helpers.rb +1 -1
- data/lib/spree/testing_support/capybara_driver.rb +1 -1
- data/lib/spree/testing_support/capybara_ext.rb +12 -12
- data/lib/spree/testing_support/common_rake.rb +17 -16
- data/lib/spree/testing_support/dummy_ability.rb +1 -1
- data/lib/spree/testing_support/dummy_app/migrations.rb +1 -1
- data/lib/spree/testing_support/dummy_app/rake_tasks.rb +5 -5
- data/lib/spree/testing_support/dummy_app/routes.rb +1 -1
- data/lib/spree/testing_support/dummy_app.rb +34 -34
- data/lib/spree/testing_support/extension_rake.rb +2 -2
- data/lib/spree/testing_support/factories/address_factory.rb +12 -12
- data/lib/spree/testing_support/factories/adjustment_factory.rb +7 -7
- data/lib/spree/testing_support/factories/adjustment_reason_factory.rb +1 -1
- data/lib/spree/testing_support/factories/calculator_factory.rb +6 -6
- data/lib/spree/testing_support/factories/carton_factory.rb +1 -1
- data/lib/spree/testing_support/factories/country_factory.rb +3 -3
- data/lib/spree/testing_support/factories/credit_card_factory.rb +3 -3
- data/lib/spree/testing_support/factories/customer_return_factory.rb +2 -2
- data/lib/spree/testing_support/factories/image_factory.rb +2 -2
- data/lib/spree/testing_support/factories/inventory_unit_factory.rb +4 -4
- data/lib/spree/testing_support/factories/line_item_factory.rb +2 -2
- data/lib/spree/testing_support/factories/option_type_factory.rb +2 -2
- data/lib/spree/testing_support/factories/option_value_factory.rb +2 -2
- data/lib/spree/testing_support/factories/order_factory.rb +16 -16
- data/lib/spree/testing_support/factories/payment_factory.rb +9 -9
- data/lib/spree/testing_support/factories/payment_method_factory.rb +10 -10
- data/lib/spree/testing_support/factories/price_factory.rb +2 -2
- data/lib/spree/testing_support/factories/product_factory.rb +2 -2
- 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/property_factory.rb +3 -3
- data/lib/spree/testing_support/factories/refund_factory.rb +2 -2
- data/lib/spree/testing_support/factories/refund_reason_factory.rb +1 -1
- data/lib/spree/testing_support/factories/reimbursement_factory.rb +1 -1
- data/lib/spree/testing_support/factories/reimbursement_type_factory.rb +1 -1
- data/lib/spree/testing_support/factories/return_authorization_factory.rb +3 -3
- data/lib/spree/testing_support/factories/return_item_factory.rb +2 -10
- data/lib/spree/testing_support/factories/return_reason_factory.rb +1 -1
- data/lib/spree/testing_support/factories/role_factory.rb +2 -2
- data/lib/spree/testing_support/factories/shipment_factory.rb +3 -3
- data/lib/spree/testing_support/factories/shipping_category_factory.rb +1 -1
- data/lib/spree/testing_support/factories/shipping_method_factory.rb +7 -7
- data/lib/spree/testing_support/factories/shipping_rate_factory.rb +1 -1
- data/lib/spree/testing_support/factories/state_factory.rb +4 -4
- 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/stock_package_factory.rb +3 -3
- data/lib/spree/testing_support/factories/store_credit_category_factory.rb +1 -1
- data/lib/spree/testing_support/factories/store_credit_event_factory.rb +6 -6
- data/lib/spree/testing_support/factories/store_credit_factory.rb +1 -1
- data/lib/spree/testing_support/factories/store_credit_reason_factory.rb +1 -1
- data/lib/spree/testing_support/factories/store_credit_type_factory.rb +6 -6
- data/lib/spree/testing_support/factories/store_factory.rb +2 -2
- data/lib/spree/testing_support/factories/tax_category_factory.rb +1 -1
- data/lib/spree/testing_support/factories/tax_rate_factory.rb +1 -1
- data/lib/spree/testing_support/factories/taxon_factory.rb +3 -3
- data/lib/spree/testing_support/factories/taxonomy_factory.rb +1 -1
- data/lib/spree/testing_support/factories/user_factory.rb +2 -2
- data/lib/spree/testing_support/factories/variant_factory.rb +2 -2
- data/lib/spree/testing_support/factories/variant_property_rule_condition_factory.rb +1 -1
- data/lib/spree/testing_support/factories/variant_property_rule_factory.rb +1 -1
- data/lib/spree/testing_support/factories/variant_property_rule_value_factory.rb +1 -1
- data/lib/spree/testing_support/factories/zone_factory.rb +3 -3
- data/lib/spree/testing_support/factory_bot.rb +1 -1
- data/lib/spree/testing_support/flaky.rb +3 -2
- data/lib/spree/testing_support/flash.rb +2 -2
- data/lib/spree/testing_support/order_walkthrough.rb +6 -6
- data/lib/spree/testing_support/preferences.rb +1 -1
- data/lib/spree/testing_support/rake.rb +1 -1
- data/lib/spree/testing_support/shared_examples/calculator.rb +1 -1
- data/lib/spree/testing_support/shared_examples/gallery.rb +7 -7
- data/lib/spree/testing_support/shared_examples/order_factory.rb +9 -9
- data/lib/spree/testing_support/shared_examples/working_factory.rb +1 -1
- data/lib/spree/testing_support/translations.rb +1 -1
- data/lib/spree_core.rb +1 -1
- data/lib/tasks/payment_method.rake +2 -2
- data/solidus_core.gemspec +49 -49
- metadata +60 -57
- data/app/views/layouts/spree/ink.license.txt +0 -28
- data/vendor/assets/javascripts/jquery.payment.license.txt +0 -25
- data/vendor/assets/javascripts/jsuri.license.txt +0 -12
|
@@ -43,15 +43,15 @@ module Spree
|
|
|
43
43
|
|
|
44
44
|
attr_accessor :target_shipment, :price_currency
|
|
45
45
|
|
|
46
|
-
self.allowed_ransackable_associations = [
|
|
47
|
-
self.allowed_ransackable_attributes = [
|
|
46
|
+
self.allowed_ransackable_associations = ["variant"]
|
|
47
|
+
self.allowed_ransackable_attributes = ["variant_id"]
|
|
48
48
|
|
|
49
49
|
# @return [BigDecimal] the amount of this line item, which is the line
|
|
50
50
|
# item's price multiplied by its quantity.
|
|
51
51
|
def amount
|
|
52
52
|
price * quantity
|
|
53
53
|
end
|
|
54
|
-
|
|
54
|
+
alias_method :subtotal, :amount
|
|
55
55
|
|
|
56
56
|
# @return [BigDecimal] the amount of this line item, taking into
|
|
57
57
|
# consideration all its adjustments.
|
|
@@ -72,17 +72,18 @@ module Spree
|
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
extend Spree::DisplayMoney
|
|
75
|
+
|
|
75
76
|
money_methods :amount, :price,
|
|
76
|
-
|
|
77
|
-
|
|
77
|
+
:included_tax_total, :additional_tax_total,
|
|
78
|
+
:total, :total_before_tax, :total_excluding_vat
|
|
78
79
|
|
|
79
80
|
# @return [Spree::Money] the price of this line item
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
alias_method :money_price, :display_price
|
|
82
|
+
alias_method :single_display_amount, :display_price
|
|
83
|
+
alias_method :single_money, :display_price
|
|
83
84
|
|
|
84
85
|
# @return [Spree::Money] the amount of this line item
|
|
85
|
-
|
|
86
|
+
alias_method :money, :display_amount
|
|
86
87
|
|
|
87
88
|
# Sets price from a `Spree::Money` object
|
|
88
89
|
#
|
|
@@ -99,7 +100,7 @@ module Spree
|
|
|
99
100
|
# @return [Boolean] true when it is possible to supply the required
|
|
100
101
|
# quantity of stock of this line item's variant
|
|
101
102
|
def sufficient_stock?
|
|
102
|
-
|
|
103
|
+
Spree::Config.stock.quantifier_class.new(variant).can_supply? quantity
|
|
103
104
|
end
|
|
104
105
|
|
|
105
106
|
# @return [Boolean] true when it is not possible to supply the required
|
|
@@ -122,11 +123,20 @@ module Spree
|
|
|
122
123
|
# it from the variant. Please note that this always allows to set
|
|
123
124
|
# a price for this line item, even if there is no existing price
|
|
124
125
|
# for the associated line item in the order currency.
|
|
125
|
-
unless options.key?(:price) || options.key?(
|
|
126
|
+
unless options.key?(:price) || options.key?("price")
|
|
126
127
|
self.money_price = variant.price_for_options(pricing_options)&.money
|
|
127
128
|
end
|
|
128
129
|
end
|
|
129
130
|
|
|
131
|
+
# Recalculate the price using the pricing options for this line item.
|
|
132
|
+
# Useful for making sure carts are up-to-date when prices change.
|
|
133
|
+
# Will not make changes to completed orders.
|
|
134
|
+
#
|
|
135
|
+
def recalculate_price
|
|
136
|
+
return if order.completed?
|
|
137
|
+
self.money_price = variant.price_for_options(pricing_options)&.money
|
|
138
|
+
end
|
|
139
|
+
|
|
130
140
|
def pricing_options
|
|
131
141
|
Spree::Config.pricing_options_class.from_line_item(self)
|
|
132
142
|
end
|
|
@@ -69,7 +69,7 @@ module Spree
|
|
|
69
69
|
@details ||= YAML.safe_load(
|
|
70
70
|
details,
|
|
71
71
|
permitted_classes: self.class.permitted_classes,
|
|
72
|
-
aliases: Spree::Config.log_entry_allow_aliases
|
|
72
|
+
aliases: Spree::Config.log_entry_allow_aliases
|
|
73
73
|
)
|
|
74
74
|
end
|
|
75
75
|
end
|
|
@@ -79,7 +79,7 @@ module Spree
|
|
|
79
79
|
self.details = YAML.safe_dump(
|
|
80
80
|
value,
|
|
81
81
|
permitted_classes: self.class.permitted_classes,
|
|
82
|
-
aliases: Spree::Config.log_entry_allow_aliases
|
|
82
|
+
aliases: Spree::Config.log_entry_allow_aliases
|
|
83
83
|
)
|
|
84
84
|
end
|
|
85
85
|
end
|
|
@@ -91,7 +91,7 @@ module Spree
|
|
|
91
91
|
self.parsed_details = ActiveMerchant::Billing::Response.new(
|
|
92
92
|
response.success?,
|
|
93
93
|
"[WARNING: An error occurred while trying to serialize the payment response] #{response.message}",
|
|
94
|
-
{
|
|
94
|
+
{"data" => response.inspect, "error" => e.message.to_s}
|
|
95
95
|
)
|
|
96
96
|
end
|
|
97
97
|
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Spree
|
|
4
|
+
# Finds orders to merge when a user logs in.
|
|
5
|
+
#
|
|
6
|
+
# Configurable via {Spree::Config#mergeable_orders_finder_class}.
|
|
7
|
+
# Default behavior finds all incomplete orders from the same store.
|
|
8
|
+
#
|
|
9
|
+
# @example Custom finder for recent orders only
|
|
10
|
+
# class RecentOrdersFinder
|
|
11
|
+
# def initialize(context:)
|
|
12
|
+
# @user = context.spree_current_user
|
|
13
|
+
# @store = context.current_store
|
|
14
|
+
# @current_order = context.current_order
|
|
15
|
+
# end
|
|
16
|
+
#
|
|
17
|
+
# def call
|
|
18
|
+
# @user.orders.by_store(@store).incomplete
|
|
19
|
+
# .where.not(id: @current_order.id)
|
|
20
|
+
# .where('created_at > ?', 7.days.ago)
|
|
21
|
+
# end
|
|
22
|
+
# end
|
|
23
|
+
#
|
|
24
|
+
# Spree::Config.mergeable_orders_finder_class = RecentOrdersFinder
|
|
25
|
+
class MergeableOrdersFinder
|
|
26
|
+
# @param context [Object] an object that responds to spree_current_user,
|
|
27
|
+
# current_store, and current_order (typically a controller)
|
|
28
|
+
def initialize(context:)
|
|
29
|
+
@user = context.spree_current_user
|
|
30
|
+
@store = context.current_store
|
|
31
|
+
@current_order = context.current_order
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Returns orders that should be merged into the current order
|
|
35
|
+
#
|
|
36
|
+
# @return [ActiveRecord::Relation<Spree::Order>] incomplete orders from the
|
|
37
|
+
# same store
|
|
38
|
+
def call
|
|
39
|
+
return Spree::Order.none unless @user && @current_order
|
|
40
|
+
|
|
41
|
+
@user.orders.by_store(@store).incomplete.where(frontend_viewable: true).where.not(id: @current_order.id)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
data/app/models/spree/money.rb
CHANGED
|
@@ -5,6 +5,7 @@ module Spree
|
|
|
5
5
|
# formatting via Spree::Config.
|
|
6
6
|
class Money
|
|
7
7
|
include Comparable
|
|
8
|
+
|
|
8
9
|
DifferentCurrencyError = Class.new(StandardError)
|
|
9
10
|
|
|
10
11
|
class << self
|
|
@@ -69,7 +70,7 @@ module Spree
|
|
|
69
70
|
# @param options [Hash] additional formatting options
|
|
70
71
|
# @return [String] the value of this money object formatted according to
|
|
71
72
|
# its options and any additional options, by default with html_wrap.
|
|
72
|
-
def to_html(options = {
|
|
73
|
+
def to_html(options = {html_wrap: true})
|
|
73
74
|
output = format(options)
|
|
74
75
|
# Maintain compatibility by checking html option renamed to html_wrap.
|
|
75
76
|
if options[:html_wrap]
|
|
@@ -15,7 +15,7 @@ module Spree
|
|
|
15
15
|
has_many :product_option_types, dependent: :destroy, inverse_of: :option_type
|
|
16
16
|
has_many :products, through: :product_option_types
|
|
17
17
|
|
|
18
|
-
validates :name, presence: true, uniqueness: {
|
|
18
|
+
validates :name, presence: true, uniqueness: {allow_blank: true, case_sensitive: true}
|
|
19
19
|
validates :presentation, presence: true
|
|
20
20
|
|
|
21
21
|
default_scope -> { order(:position) }
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
module Spree
|
|
4
4
|
class OptionValue < Spree::Base
|
|
5
|
-
belongs_to :option_type, class_name:
|
|
5
|
+
belongs_to :option_type, class_name: "Spree::OptionType", inverse_of: :option_values
|
|
6
6
|
acts_as_list scope: :option_type
|
|
7
7
|
|
|
8
8
|
has_many :option_values_variants, dependent: :destroy
|
|
9
9
|
has_many :variants, through: :option_values_variants
|
|
10
10
|
|
|
11
|
-
validates :name, presence: true, uniqueness: {
|
|
11
|
+
validates :name, presence: true, uniqueness: {scope: :option_type_id, allow_blank: true, case_sensitive: true}
|
|
12
12
|
validates :presentation, presence: true
|
|
13
13
|
|
|
14
14
|
after_save :touch, if: :saved_changes?
|
data/app/models/spree/order.rb
CHANGED
|
@@ -19,9 +19,9 @@ module Spree
|
|
|
19
19
|
# `empty!` and `fulfill!`.
|
|
20
20
|
#
|
|
21
21
|
class Order < Spree::Base
|
|
22
|
-
ORDER_NUMBER_LENGTH
|
|
22
|
+
ORDER_NUMBER_LENGTH = 9
|
|
23
23
|
ORDER_NUMBER_LETTERS = false
|
|
24
|
-
ORDER_NUMBER_PREFIX
|
|
24
|
+
ORDER_NUMBER_PREFIX = "R"
|
|
25
25
|
|
|
26
26
|
include ::Spree::Config.state_machines.order
|
|
27
27
|
|
|
@@ -33,12 +33,14 @@ module Spree
|
|
|
33
33
|
|
|
34
34
|
def initialize(message = nil, items: {})
|
|
35
35
|
@items = items
|
|
36
|
-
super
|
|
36
|
+
super(message)
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
|
+
|
|
39
40
|
class CannotRebuildShipments < StandardError; end
|
|
40
41
|
|
|
41
42
|
extend Spree::DisplayMoney
|
|
43
|
+
|
|
42
44
|
money_methods(
|
|
43
45
|
:outstanding_balance,
|
|
44
46
|
:item_total,
|
|
@@ -55,7 +57,7 @@ module Spree
|
|
|
55
57
|
:item_total_excluding_vat,
|
|
56
58
|
:promo_total
|
|
57
59
|
)
|
|
58
|
-
|
|
60
|
+
alias_method :display_ship_total, :display_shipment_total
|
|
59
61
|
|
|
60
62
|
checkout_flow do
|
|
61
63
|
go_to_state :address
|
|
@@ -75,17 +77,17 @@ module Spree
|
|
|
75
77
|
# Customer info
|
|
76
78
|
belongs_to :user, class_name: Spree::UserClassHandle.new, optional: true
|
|
77
79
|
|
|
78
|
-
belongs_to :bill_address, foreign_key: :bill_address_id, class_name:
|
|
80
|
+
belongs_to :bill_address, foreign_key: :bill_address_id, class_name: "Spree::Address", optional: true
|
|
79
81
|
alias_method :billing_address, :bill_address
|
|
80
82
|
alias_method :billing_address=, :bill_address=
|
|
81
83
|
|
|
82
|
-
belongs_to :ship_address, foreign_key: :ship_address_id, class_name:
|
|
84
|
+
belongs_to :ship_address, foreign_key: :ship_address_id, class_name: "Spree::Address", optional: true
|
|
83
85
|
alias_method :shipping_address, :ship_address
|
|
84
86
|
alias_method :shipping_address=, :ship_address=
|
|
85
87
|
|
|
86
88
|
alias_attribute :ship_total, :shipment_total
|
|
87
89
|
|
|
88
|
-
belongs_to :store, class_name:
|
|
90
|
+
belongs_to :store, class_name: "Spree::Store", optional: true
|
|
89
91
|
|
|
90
92
|
# Items
|
|
91
93
|
has_many :line_items, -> { order(:created_at, :id) }, dependent: :destroy, inverse_of: :order
|
|
@@ -106,14 +108,14 @@ module Spree
|
|
|
106
108
|
has_many :line_item_adjustments, through: :line_items, source: :adjustments
|
|
107
109
|
has_many :shipment_adjustments, through: :shipments, source: :adjustments
|
|
108
110
|
has_many :all_adjustments,
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
class_name: "Spree::Adjustment",
|
|
112
|
+
foreign_key: :order_id,
|
|
113
|
+
dependent: :destroy,
|
|
114
|
+
inverse_of: :order
|
|
113
115
|
|
|
114
116
|
# Payments
|
|
115
117
|
has_many :payments, dependent: :destroy, inverse_of: :order
|
|
116
|
-
has_many :valid_store_credit_payments, -> { store_credits.valid }, inverse_of: :order, class_name:
|
|
118
|
+
has_many :valid_store_credit_payments, -> { store_credits.valid }, inverse_of: :order, class_name: "Spree::Payment", foreign_key: :order_id
|
|
117
119
|
|
|
118
120
|
# Returns
|
|
119
121
|
has_many :return_authorizations, dependent: :destroy, inverse_of: :order
|
|
@@ -147,9 +149,9 @@ module Spree
|
|
|
147
149
|
before_create :link_by_email
|
|
148
150
|
|
|
149
151
|
validates :email, presence: true, if: :email_required?
|
|
150
|
-
validates :email,
|
|
151
|
-
validates :guest_token, presence: {
|
|
152
|
-
validates :number, presence: true, uniqueness: {
|
|
152
|
+
validates :email, "spree/email" => true, :allow_blank => true
|
|
153
|
+
validates :guest_token, presence: {allow_nil: true}
|
|
154
|
+
validates :number, presence: true, uniqueness: {allow_blank: true, case_sensitive: true}
|
|
153
155
|
validates :store_id, presence: true
|
|
154
156
|
|
|
155
157
|
def self.find_by_param(value)
|
|
@@ -190,7 +192,7 @@ module Spree
|
|
|
190
192
|
scope :by_store, ->(store) { where(store_id: store.id) }
|
|
191
193
|
|
|
192
194
|
# shows completed orders first, by their completed_at date, then uncompleted orders by their created_at
|
|
193
|
-
scope :reverse_chronological, -> { order(Arel.sql(
|
|
195
|
+
scope :reverse_chronological, -> { order(Arel.sql("spree_orders.completed_at IS NULL"), completed_at: :desc, created_at: :desc) }
|
|
194
196
|
|
|
195
197
|
def self.by_customer(customer)
|
|
196
198
|
joins(:user).where("#{Spree.user_class.table_name}.email" => customer)
|
|
@@ -209,11 +211,11 @@ module Spree
|
|
|
209
211
|
end
|
|
210
212
|
|
|
211
213
|
def self.canceled
|
|
212
|
-
where(state:
|
|
214
|
+
where(state: "canceled")
|
|
213
215
|
end
|
|
214
216
|
|
|
215
217
|
def self.not_canceled
|
|
216
|
-
where.not(state:
|
|
218
|
+
where.not(state: "canceled")
|
|
217
219
|
end
|
|
218
220
|
|
|
219
221
|
# For compatiblity with Calculator::PriceSack
|
|
@@ -293,8 +295,8 @@ module Spree
|
|
|
293
295
|
end
|
|
294
296
|
|
|
295
297
|
def allow_cancel?
|
|
296
|
-
return false unless completed? && state !=
|
|
297
|
-
shipment_state.nil? || %w
|
|
298
|
+
return false unless completed? && state != "canceled"
|
|
299
|
+
shipment_state.nil? || %w[ready backorder pending].include?(shipment_state)
|
|
298
300
|
end
|
|
299
301
|
|
|
300
302
|
def all_inventory_units_returned?
|
|
@@ -319,15 +321,8 @@ module Spree
|
|
|
319
321
|
|
|
320
322
|
# Associates the specified user with the order.
|
|
321
323
|
def associate_user!(user, override_email = true)
|
|
322
|
-
user_changed = user_id != user.try(:id)
|
|
323
324
|
self.user = user
|
|
324
|
-
attrs_to_set = {
|
|
325
|
-
|
|
326
|
-
if user_changed
|
|
327
|
-
self.guest_token = nil
|
|
328
|
-
attrs_to_set[:guest_token] = create_token
|
|
329
|
-
end
|
|
330
|
-
|
|
325
|
+
attrs_to_set = {user_id: user.try(:id)}
|
|
331
326
|
attrs_to_set[:email] = user.try(:email) if override_email
|
|
332
327
|
attrs_to_set[:created_by_id] = user.try(:id) if created_by.blank?
|
|
333
328
|
|
|
@@ -358,8 +353,8 @@ module Spree
|
|
|
358
353
|
|
|
359
354
|
def find_line_item_by_variant(variant, options = {})
|
|
360
355
|
line_items.detect { |line_item|
|
|
361
|
-
|
|
362
|
-
|
|
356
|
+
line_item.variant_id == variant.id &&
|
|
357
|
+
line_item_options_match(line_item, options)
|
|
363
358
|
}
|
|
364
359
|
end
|
|
365
360
|
|
|
@@ -388,7 +383,7 @@ module Spree
|
|
|
388
383
|
# If reimbursement has happened add it back to total to prevent balance_due payment state
|
|
389
384
|
# See: https://github.com/spree/spree/issues/6229
|
|
390
385
|
|
|
391
|
-
if state ==
|
|
386
|
+
if state == "canceled"
|
|
392
387
|
-1 * payment_total
|
|
393
388
|
else
|
|
394
389
|
total - reimbursement_total - payment_total
|
|
@@ -425,13 +420,13 @@ module Spree
|
|
|
425
420
|
|
|
426
421
|
def fulfill!
|
|
427
422
|
shipments.each { |shipment| shipment.update_state if shipment.persisted? }
|
|
428
|
-
recalculator.
|
|
423
|
+
recalculator.recalculate_shipment_state
|
|
429
424
|
save!
|
|
430
425
|
end
|
|
431
426
|
|
|
432
427
|
# Helper methods for checkout steps
|
|
433
428
|
def paid?
|
|
434
|
-
%w
|
|
429
|
+
%w[paid credit_owed].include?(payment_state)
|
|
435
430
|
end
|
|
436
431
|
|
|
437
432
|
def available_payment_methods
|
|
@@ -451,7 +446,7 @@ module Spree
|
|
|
451
446
|
# If so add error and restart checkout.
|
|
452
447
|
def ensure_line_item_variants_are_not_deleted
|
|
453
448
|
if line_items.any? { |li| li.variant.discarded? }
|
|
454
|
-
errors.add(:base, I18n.t(
|
|
449
|
+
errors.add(:base, I18n.t("spree.deleted_variants_present"))
|
|
455
450
|
restart_checkout_flow
|
|
456
451
|
false
|
|
457
452
|
else
|
|
@@ -474,10 +469,10 @@ module Spree
|
|
|
474
469
|
|
|
475
470
|
def coupon_code=(code)
|
|
476
471
|
@coupon_code = begin
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
472
|
+
code.strip.downcase
|
|
473
|
+
rescue
|
|
474
|
+
nil
|
|
475
|
+
end
|
|
481
476
|
end
|
|
482
477
|
|
|
483
478
|
def can_add_coupon?
|
|
@@ -485,12 +480,12 @@ module Spree
|
|
|
485
480
|
end
|
|
486
481
|
|
|
487
482
|
def shipped?
|
|
488
|
-
%w
|
|
483
|
+
%w[partial shipped].include?(shipment_state)
|
|
489
484
|
end
|
|
490
485
|
|
|
491
486
|
def ensure_shipping_address
|
|
492
|
-
unless ship_address
|
|
493
|
-
errors.add(:base, I18n.t(
|
|
487
|
+
unless ship_address&.valid?
|
|
488
|
+
errors.add(:base, I18n.t("spree.ship_address_required")) && (return false)
|
|
494
489
|
end
|
|
495
490
|
end
|
|
496
491
|
|
|
@@ -498,7 +493,7 @@ module Spree
|
|
|
498
493
|
return unless billing_address_required?
|
|
499
494
|
return if bill_address&.valid?
|
|
500
495
|
|
|
501
|
-
errors.add(:base, I18n.t(
|
|
496
|
+
errors.add(:base, I18n.t("spree.bill_address_required"))
|
|
502
497
|
false
|
|
503
498
|
end
|
|
504
499
|
|
|
@@ -508,9 +503,9 @@ module Spree
|
|
|
508
503
|
|
|
509
504
|
def create_proposed_shipments
|
|
510
505
|
if completed?
|
|
511
|
-
raise CannotRebuildShipments.new(I18n.t(
|
|
506
|
+
raise CannotRebuildShipments.new(I18n.t("spree.cannot_rebuild_shipments_order_completed"))
|
|
512
507
|
elsif shipments.any? { |shipment| !shipment.pending? }
|
|
513
|
-
raise CannotRebuildShipments.new(I18n.t(
|
|
508
|
+
raise CannotRebuildShipments.new(I18n.t("spree.cannot_rebuild_shipments_shipments_not_pending"))
|
|
514
509
|
else
|
|
515
510
|
shipments.destroy_all
|
|
516
511
|
shipments.push(*Spree::Config.stock.coordinator_class.new(self).shipments)
|
|
@@ -539,10 +534,10 @@ module Spree
|
|
|
539
534
|
deprecate ensure_updated_shipments: :check_shipments_and_restart_checkout, deprecator: Spree.deprecator
|
|
540
535
|
|
|
541
536
|
def restart_checkout_flow
|
|
542
|
-
return if state ==
|
|
537
|
+
return if state == "cart"
|
|
543
538
|
|
|
544
539
|
update_columns(
|
|
545
|
-
state:
|
|
540
|
+
state: "cart",
|
|
546
541
|
updated_at: Time.current
|
|
547
542
|
)
|
|
548
543
|
self.next if line_items.any?
|
|
@@ -612,10 +607,10 @@ module Spree
|
|
|
612
607
|
|
|
613
608
|
amount_to_take = [credit.amount_remaining, remaining_total].min
|
|
614
609
|
payments.create!(source: credit,
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
610
|
+
payment_method:,
|
|
611
|
+
amount: amount_to_take,
|
|
612
|
+
state: "checkout",
|
|
613
|
+
response_code: credit.generate_authorization_code)
|
|
619
614
|
remaining_total -= amount_to_take
|
|
620
615
|
end
|
|
621
616
|
end
|
|
@@ -629,8 +624,8 @@ module Spree
|
|
|
629
624
|
|
|
630
625
|
payments.reset
|
|
631
626
|
|
|
632
|
-
if payments.where(state: %w
|
|
633
|
-
errors.add(:base, I18n.t(
|
|
627
|
+
if payments.where(state: %w[checkout pending completed]).sum(:amount) != total
|
|
628
|
+
errors.add(:base, I18n.t("spree.store_credit.errors.unable_to_fund")) && (return false)
|
|
634
629
|
end
|
|
635
630
|
end
|
|
636
631
|
|
|
@@ -658,11 +653,11 @@ module Spree
|
|
|
658
653
|
end
|
|
659
654
|
|
|
660
655
|
def display_total_applicable_store_credit
|
|
661
|
-
Spree::Money.new(-total_applicable_store_credit, {
|
|
656
|
+
Spree::Money.new(-total_applicable_store_credit, {currency:})
|
|
662
657
|
end
|
|
663
658
|
|
|
664
659
|
def display_store_credit_remaining_after_capture
|
|
665
|
-
Spree::Money.new(total_available_store_credit - total_applicable_store_credit, {
|
|
660
|
+
Spree::Money.new(total_available_store_credit - total_applicable_store_credit, {currency:})
|
|
666
661
|
end
|
|
667
662
|
|
|
668
663
|
def bill_address_attributes=(attributes)
|
|
@@ -689,27 +684,27 @@ module Spree
|
|
|
689
684
|
end
|
|
690
685
|
|
|
691
686
|
def persist_user_address!
|
|
692
|
-
if !temporary_address && user
|
|
687
|
+
if !temporary_address && user&.respond_to?(:persist_order_address) && bill_address_id
|
|
693
688
|
user.persist_order_address(self)
|
|
694
689
|
end
|
|
695
690
|
end
|
|
696
691
|
|
|
697
692
|
def add_payment_sources_to_wallet
|
|
698
|
-
Spree::Config
|
|
699
|
-
add_payment_sources_to_wallet_class.new(self)
|
|
700
|
-
add_to_wallet
|
|
693
|
+
Spree::Config
|
|
694
|
+
.add_payment_sources_to_wallet_class.new(self)
|
|
695
|
+
.add_to_wallet
|
|
701
696
|
end
|
|
702
697
|
|
|
703
698
|
def add_default_payment_from_wallet
|
|
704
699
|
builder = Spree::Config.default_payment_builder_class.new(self)
|
|
705
700
|
|
|
706
|
-
if payment = builder.build
|
|
701
|
+
if (payment = builder.build)
|
|
707
702
|
payments << payment
|
|
708
703
|
|
|
709
704
|
if bill_address.nil?
|
|
710
705
|
# this is one of 2 places still using User#bill_address
|
|
711
706
|
self.bill_address = payment.source.try(:address) ||
|
|
712
|
-
|
|
707
|
+
user.bill_address
|
|
713
708
|
end
|
|
714
709
|
end
|
|
715
710
|
end
|
|
@@ -724,7 +719,7 @@ module Spree
|
|
|
724
719
|
|
|
725
720
|
def payments_attributes=(attributes)
|
|
726
721
|
validate_payments_attributes(attributes)
|
|
727
|
-
super
|
|
722
|
+
super
|
|
728
723
|
end
|
|
729
724
|
|
|
730
725
|
def validate_payments_attributes(attributes)
|
|
@@ -744,7 +739,7 @@ module Spree
|
|
|
744
739
|
return if !payment_required?
|
|
745
740
|
|
|
746
741
|
if payments.valid.empty?
|
|
747
|
-
errors.add(:base, I18n.t(
|
|
742
|
+
errors.add(:base, I18n.t("spree.no_payment_found"))
|
|
748
743
|
return false
|
|
749
744
|
end
|
|
750
745
|
|
|
@@ -765,13 +760,13 @@ module Spree
|
|
|
765
760
|
all_adjustments.each(&:finalize!)
|
|
766
761
|
|
|
767
762
|
# update payment and shipment(s) states, and save
|
|
768
|
-
recalculator.
|
|
763
|
+
recalculator.recalculate_payment_state
|
|
769
764
|
shipments.each do |shipment|
|
|
770
765
|
shipment.update_state
|
|
771
766
|
shipment.finalize!
|
|
772
767
|
end
|
|
773
768
|
|
|
774
|
-
recalculator.
|
|
769
|
+
recalculator.recalculate_shipment_state
|
|
775
770
|
save!
|
|
776
771
|
|
|
777
772
|
touch :completed_at
|
|
@@ -795,7 +790,7 @@ module Spree
|
|
|
795
790
|
# @return [Boolean] true if the email is required
|
|
796
791
|
# @note This method was called require_email before.
|
|
797
792
|
def email_required?
|
|
798
|
-
true unless new_record? || [
|
|
793
|
+
true unless new_record? || ["cart", "address"].include?(state)
|
|
799
794
|
end
|
|
800
795
|
|
|
801
796
|
def ensure_inventory_units
|
|
@@ -811,12 +806,12 @@ module Spree
|
|
|
811
806
|
end
|
|
812
807
|
|
|
813
808
|
def ensure_promotions_eligible
|
|
814
|
-
Spree::Config.promotions.order_adjuster_class.new(self).call
|
|
809
|
+
Spree::Config.promotions.order_adjuster_class.new(self).call(persist: false)
|
|
815
810
|
|
|
816
811
|
if promo_total_changed?
|
|
817
812
|
restart_checkout_flow
|
|
818
813
|
recalculate
|
|
819
|
-
errors.add(:base, I18n.t(
|
|
814
|
+
errors.add(:base, I18n.t("spree.promotion_total_changed_before_complete"))
|
|
820
815
|
end
|
|
821
816
|
errors.empty?
|
|
822
817
|
end
|
|
@@ -835,7 +830,7 @@ module Spree
|
|
|
835
830
|
|
|
836
831
|
def ensure_line_items_present
|
|
837
832
|
unless line_items.present?
|
|
838
|
-
errors.add(:base, I18n.t(
|
|
833
|
+
errors.add(:base, I18n.t("spree.there_are_no_items_for_this_order")) && (return false)
|
|
839
834
|
end
|
|
840
835
|
end
|
|
841
836
|
|
|
@@ -844,7 +839,7 @@ module Spree
|
|
|
844
839
|
# After this point, order redirects back to 'address' state and asks user to pick a proper address
|
|
845
840
|
# Therefore, shipments are not necessary at this point.
|
|
846
841
|
shipments.destroy_all
|
|
847
|
-
errors.add(:base, I18n.t(
|
|
842
|
+
errors.add(:base, I18n.t("spree.items_cannot_be_shipped")) && (return false)
|
|
848
843
|
end
|
|
849
844
|
end
|
|
850
845
|
|
|
@@ -876,11 +871,11 @@ module Spree
|
|
|
876
871
|
end
|
|
877
872
|
|
|
878
873
|
def use_billing?
|
|
879
|
-
use_billing.in?([true,
|
|
874
|
+
use_billing.in?([true, "true", "1"])
|
|
880
875
|
end
|
|
881
876
|
|
|
882
877
|
def use_shipping?
|
|
883
|
-
use_shipping.in?([true,
|
|
878
|
+
use_shipping.in?([true, "true", "1"])
|
|
884
879
|
end
|
|
885
880
|
|
|
886
881
|
def set_currency
|
|
@@ -55,9 +55,7 @@ class Spree::OrderCancellations
|
|
|
55
55
|
|
|
56
56
|
@order.recalculate
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
short_ship_tax_notifier.call(unit_cancels)
|
|
60
|
-
end
|
|
58
|
+
short_ship_tax_notifier&.call(unit_cancels)
|
|
61
59
|
end
|
|
62
60
|
|
|
63
61
|
Spree::Bus.publish(:order_short_shipped, order: @order, inventory_units:)
|
|
@@ -62,11 +62,8 @@ module Spree
|
|
|
62
62
|
potential_shipments.detect do |shipment|
|
|
63
63
|
shipment.include?(variant)
|
|
64
64
|
end || begin
|
|
65
|
-
stock_items = variant.stock_items.sort_by(&:id) # cache stock items to avoid N+1
|
|
66
|
-
|
|
67
65
|
potential_shipments.detect do |shipment|
|
|
68
|
-
|
|
69
|
-
stock_item.backorderable? || stock_item.count_on_hand >= quantity if stock_item
|
|
66
|
+
Spree::Config.stock.quantifier_class.new(variant, shipment.stock_location).can_supply?(quantity)
|
|
70
67
|
end
|
|
71
68
|
end || potential_shipments.detect do |shipment|
|
|
72
69
|
variant.stock_location_ids.include?(shipment.stock_location_id)
|
|
@@ -78,10 +75,10 @@ module Spree
|
|
|
78
75
|
if variant.should_track_inventory?
|
|
79
76
|
on_hand, back_order = shipment.stock_location.fill_status(variant, quantity)
|
|
80
77
|
|
|
81
|
-
on_hand.times { pending_units << shipment.set_up_inventory(
|
|
82
|
-
back_order.times { pending_units << shipment.set_up_inventory(
|
|
78
|
+
on_hand.times { pending_units << shipment.set_up_inventory("on_hand", variant, order, line_item) }
|
|
79
|
+
back_order.times { pending_units << shipment.set_up_inventory("backordered", variant, order, line_item) }
|
|
83
80
|
else
|
|
84
|
-
quantity.times { pending_units << shipment.set_up_inventory(
|
|
81
|
+
quantity.times { pending_units << shipment.set_up_inventory("on_hand", variant, order, line_item) }
|
|
85
82
|
end
|
|
86
83
|
|
|
87
84
|
# adding to this shipment, and removing from stock_location
|
|
@@ -104,7 +101,7 @@ module Spree
|
|
|
104
101
|
|
|
105
102
|
shipment_units = shipment.inventory_units_for_item(line_item, variant).reject do |variant_unit|
|
|
106
103
|
# TODO: exclude all 'shipped' states
|
|
107
|
-
variant_unit.state ==
|
|
104
|
+
variant_unit.state == "shipped"
|
|
108
105
|
end.sort_by(&:state)
|
|
109
106
|
|
|
110
107
|
removed_quantity = 0
|