solidus_core 4.6.2 → 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 -10
- data/app/helpers/spree/products_helper.rb +5 -5
- 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 +9 -9
- 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 -64
- 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 -1
- 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 +1 -1
- 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 +37 -41
- 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 +31 -30
- 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 +3 -3
- 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 +16 -17
- 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.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/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 -16
- 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 +10 -10
- 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 -16
- 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 +1 -1
- 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 +8 -8
- 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 +7 -7
- 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 -54
|
@@ -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?
|
|
@@ -320,7 +322,7 @@ module Spree
|
|
|
320
322
|
# Associates the specified user with the order.
|
|
321
323
|
def associate_user!(user, override_email = true)
|
|
322
324
|
self.user = user
|
|
323
|
-
attrs_to_set = {
|
|
325
|
+
attrs_to_set = {user_id: user.try(:id)}
|
|
324
326
|
attrs_to_set[:email] = user.try(:email) if override_email
|
|
325
327
|
attrs_to_set[:created_by_id] = user.try(:id) if created_by.blank?
|
|
326
328
|
|
|
@@ -351,8 +353,8 @@ module Spree
|
|
|
351
353
|
|
|
352
354
|
def find_line_item_by_variant(variant, options = {})
|
|
353
355
|
line_items.detect { |line_item|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
+
line_item.variant_id == variant.id &&
|
|
357
|
+
line_item_options_match(line_item, options)
|
|
356
358
|
}
|
|
357
359
|
end
|
|
358
360
|
|
|
@@ -381,7 +383,7 @@ module Spree
|
|
|
381
383
|
# If reimbursement has happened add it back to total to prevent balance_due payment state
|
|
382
384
|
# See: https://github.com/spree/spree/issues/6229
|
|
383
385
|
|
|
384
|
-
if state ==
|
|
386
|
+
if state == "canceled"
|
|
385
387
|
-1 * payment_total
|
|
386
388
|
else
|
|
387
389
|
total - reimbursement_total - payment_total
|
|
@@ -418,13 +420,13 @@ module Spree
|
|
|
418
420
|
|
|
419
421
|
def fulfill!
|
|
420
422
|
shipments.each { |shipment| shipment.update_state if shipment.persisted? }
|
|
421
|
-
recalculator.
|
|
423
|
+
recalculator.recalculate_shipment_state
|
|
422
424
|
save!
|
|
423
425
|
end
|
|
424
426
|
|
|
425
427
|
# Helper methods for checkout steps
|
|
426
428
|
def paid?
|
|
427
|
-
%w
|
|
429
|
+
%w[paid credit_owed].include?(payment_state)
|
|
428
430
|
end
|
|
429
431
|
|
|
430
432
|
def available_payment_methods
|
|
@@ -444,7 +446,7 @@ module Spree
|
|
|
444
446
|
# If so add error and restart checkout.
|
|
445
447
|
def ensure_line_item_variants_are_not_deleted
|
|
446
448
|
if line_items.any? { |li| li.variant.discarded? }
|
|
447
|
-
errors.add(:base, I18n.t(
|
|
449
|
+
errors.add(:base, I18n.t("spree.deleted_variants_present"))
|
|
448
450
|
restart_checkout_flow
|
|
449
451
|
false
|
|
450
452
|
else
|
|
@@ -467,10 +469,10 @@ module Spree
|
|
|
467
469
|
|
|
468
470
|
def coupon_code=(code)
|
|
469
471
|
@coupon_code = begin
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
472
|
+
code.strip.downcase
|
|
473
|
+
rescue
|
|
474
|
+
nil
|
|
475
|
+
end
|
|
474
476
|
end
|
|
475
477
|
|
|
476
478
|
def can_add_coupon?
|
|
@@ -478,12 +480,12 @@ module Spree
|
|
|
478
480
|
end
|
|
479
481
|
|
|
480
482
|
def shipped?
|
|
481
|
-
%w
|
|
483
|
+
%w[partial shipped].include?(shipment_state)
|
|
482
484
|
end
|
|
483
485
|
|
|
484
486
|
def ensure_shipping_address
|
|
485
|
-
unless ship_address
|
|
486
|
-
errors.add(:base, I18n.t(
|
|
487
|
+
unless ship_address&.valid?
|
|
488
|
+
errors.add(:base, I18n.t("spree.ship_address_required")) && (return false)
|
|
487
489
|
end
|
|
488
490
|
end
|
|
489
491
|
|
|
@@ -491,7 +493,7 @@ module Spree
|
|
|
491
493
|
return unless billing_address_required?
|
|
492
494
|
return if bill_address&.valid?
|
|
493
495
|
|
|
494
|
-
errors.add(:base, I18n.t(
|
|
496
|
+
errors.add(:base, I18n.t("spree.bill_address_required"))
|
|
495
497
|
false
|
|
496
498
|
end
|
|
497
499
|
|
|
@@ -501,9 +503,9 @@ module Spree
|
|
|
501
503
|
|
|
502
504
|
def create_proposed_shipments
|
|
503
505
|
if completed?
|
|
504
|
-
raise CannotRebuildShipments.new(I18n.t(
|
|
506
|
+
raise CannotRebuildShipments.new(I18n.t("spree.cannot_rebuild_shipments_order_completed"))
|
|
505
507
|
elsif shipments.any? { |shipment| !shipment.pending? }
|
|
506
|
-
raise CannotRebuildShipments.new(I18n.t(
|
|
508
|
+
raise CannotRebuildShipments.new(I18n.t("spree.cannot_rebuild_shipments_shipments_not_pending"))
|
|
507
509
|
else
|
|
508
510
|
shipments.destroy_all
|
|
509
511
|
shipments.push(*Spree::Config.stock.coordinator_class.new(self).shipments)
|
|
@@ -532,10 +534,10 @@ module Spree
|
|
|
532
534
|
deprecate ensure_updated_shipments: :check_shipments_and_restart_checkout, deprecator: Spree.deprecator
|
|
533
535
|
|
|
534
536
|
def restart_checkout_flow
|
|
535
|
-
return if state ==
|
|
537
|
+
return if state == "cart"
|
|
536
538
|
|
|
537
539
|
update_columns(
|
|
538
|
-
state:
|
|
540
|
+
state: "cart",
|
|
539
541
|
updated_at: Time.current
|
|
540
542
|
)
|
|
541
543
|
self.next if line_items.any?
|
|
@@ -605,10 +607,10 @@ module Spree
|
|
|
605
607
|
|
|
606
608
|
amount_to_take = [credit.amount_remaining, remaining_total].min
|
|
607
609
|
payments.create!(source: credit,
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
610
|
+
payment_method:,
|
|
611
|
+
amount: amount_to_take,
|
|
612
|
+
state: "checkout",
|
|
613
|
+
response_code: credit.generate_authorization_code)
|
|
612
614
|
remaining_total -= amount_to_take
|
|
613
615
|
end
|
|
614
616
|
end
|
|
@@ -622,8 +624,8 @@ module Spree
|
|
|
622
624
|
|
|
623
625
|
payments.reset
|
|
624
626
|
|
|
625
|
-
if payments.where(state: %w
|
|
626
|
-
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)
|
|
627
629
|
end
|
|
628
630
|
end
|
|
629
631
|
|
|
@@ -651,11 +653,11 @@ module Spree
|
|
|
651
653
|
end
|
|
652
654
|
|
|
653
655
|
def display_total_applicable_store_credit
|
|
654
|
-
Spree::Money.new(-total_applicable_store_credit, {
|
|
656
|
+
Spree::Money.new(-total_applicable_store_credit, {currency:})
|
|
655
657
|
end
|
|
656
658
|
|
|
657
659
|
def display_store_credit_remaining_after_capture
|
|
658
|
-
Spree::Money.new(total_available_store_credit - total_applicable_store_credit, {
|
|
660
|
+
Spree::Money.new(total_available_store_credit - total_applicable_store_credit, {currency:})
|
|
659
661
|
end
|
|
660
662
|
|
|
661
663
|
def bill_address_attributes=(attributes)
|
|
@@ -682,27 +684,27 @@ module Spree
|
|
|
682
684
|
end
|
|
683
685
|
|
|
684
686
|
def persist_user_address!
|
|
685
|
-
if !temporary_address && user
|
|
687
|
+
if !temporary_address && user&.respond_to?(:persist_order_address) && bill_address_id
|
|
686
688
|
user.persist_order_address(self)
|
|
687
689
|
end
|
|
688
690
|
end
|
|
689
691
|
|
|
690
692
|
def add_payment_sources_to_wallet
|
|
691
|
-
Spree::Config
|
|
692
|
-
add_payment_sources_to_wallet_class.new(self)
|
|
693
|
-
add_to_wallet
|
|
693
|
+
Spree::Config
|
|
694
|
+
.add_payment_sources_to_wallet_class.new(self)
|
|
695
|
+
.add_to_wallet
|
|
694
696
|
end
|
|
695
697
|
|
|
696
698
|
def add_default_payment_from_wallet
|
|
697
699
|
builder = Spree::Config.default_payment_builder_class.new(self)
|
|
698
700
|
|
|
699
|
-
if payment = builder.build
|
|
701
|
+
if (payment = builder.build)
|
|
700
702
|
payments << payment
|
|
701
703
|
|
|
702
704
|
if bill_address.nil?
|
|
703
705
|
# this is one of 2 places still using User#bill_address
|
|
704
706
|
self.bill_address = payment.source.try(:address) ||
|
|
705
|
-
|
|
707
|
+
user.bill_address
|
|
706
708
|
end
|
|
707
709
|
end
|
|
708
710
|
end
|
|
@@ -717,7 +719,7 @@ module Spree
|
|
|
717
719
|
|
|
718
720
|
def payments_attributes=(attributes)
|
|
719
721
|
validate_payments_attributes(attributes)
|
|
720
|
-
super
|
|
722
|
+
super
|
|
721
723
|
end
|
|
722
724
|
|
|
723
725
|
def validate_payments_attributes(attributes)
|
|
@@ -737,7 +739,7 @@ module Spree
|
|
|
737
739
|
return if !payment_required?
|
|
738
740
|
|
|
739
741
|
if payments.valid.empty?
|
|
740
|
-
errors.add(:base, I18n.t(
|
|
742
|
+
errors.add(:base, I18n.t("spree.no_payment_found"))
|
|
741
743
|
return false
|
|
742
744
|
end
|
|
743
745
|
|
|
@@ -758,13 +760,13 @@ module Spree
|
|
|
758
760
|
all_adjustments.each(&:finalize!)
|
|
759
761
|
|
|
760
762
|
# update payment and shipment(s) states, and save
|
|
761
|
-
recalculator.
|
|
763
|
+
recalculator.recalculate_payment_state
|
|
762
764
|
shipments.each do |shipment|
|
|
763
765
|
shipment.update_state
|
|
764
766
|
shipment.finalize!
|
|
765
767
|
end
|
|
766
768
|
|
|
767
|
-
recalculator.
|
|
769
|
+
recalculator.recalculate_shipment_state
|
|
768
770
|
save!
|
|
769
771
|
|
|
770
772
|
touch :completed_at
|
|
@@ -788,7 +790,7 @@ module Spree
|
|
|
788
790
|
# @return [Boolean] true if the email is required
|
|
789
791
|
# @note This method was called require_email before.
|
|
790
792
|
def email_required?
|
|
791
|
-
true unless new_record? || [
|
|
793
|
+
true unless new_record? || ["cart", "address"].include?(state)
|
|
792
794
|
end
|
|
793
795
|
|
|
794
796
|
def ensure_inventory_units
|
|
@@ -804,12 +806,12 @@ module Spree
|
|
|
804
806
|
end
|
|
805
807
|
|
|
806
808
|
def ensure_promotions_eligible
|
|
807
|
-
Spree::Config.promotions.order_adjuster_class.new(self).call
|
|
809
|
+
Spree::Config.promotions.order_adjuster_class.new(self).call(persist: false)
|
|
808
810
|
|
|
809
811
|
if promo_total_changed?
|
|
810
812
|
restart_checkout_flow
|
|
811
813
|
recalculate
|
|
812
|
-
errors.add(:base, I18n.t(
|
|
814
|
+
errors.add(:base, I18n.t("spree.promotion_total_changed_before_complete"))
|
|
813
815
|
end
|
|
814
816
|
errors.empty?
|
|
815
817
|
end
|
|
@@ -828,7 +830,7 @@ module Spree
|
|
|
828
830
|
|
|
829
831
|
def ensure_line_items_present
|
|
830
832
|
unless line_items.present?
|
|
831
|
-
errors.add(:base, I18n.t(
|
|
833
|
+
errors.add(:base, I18n.t("spree.there_are_no_items_for_this_order")) && (return false)
|
|
832
834
|
end
|
|
833
835
|
end
|
|
834
836
|
|
|
@@ -837,7 +839,7 @@ module Spree
|
|
|
837
839
|
# After this point, order redirects back to 'address' state and asks user to pick a proper address
|
|
838
840
|
# Therefore, shipments are not necessary at this point.
|
|
839
841
|
shipments.destroy_all
|
|
840
|
-
errors.add(:base, I18n.t(
|
|
842
|
+
errors.add(:base, I18n.t("spree.items_cannot_be_shipped")) && (return false)
|
|
841
843
|
end
|
|
842
844
|
end
|
|
843
845
|
|
|
@@ -869,11 +871,11 @@ module Spree
|
|
|
869
871
|
end
|
|
870
872
|
|
|
871
873
|
def use_billing?
|
|
872
|
-
use_billing.in?([true,
|
|
874
|
+
use_billing.in?([true, "true", "1"])
|
|
873
875
|
end
|
|
874
876
|
|
|
875
877
|
def use_shipping?
|
|
876
|
-
use_shipping.in?([true,
|
|
878
|
+
use_shipping.in?([true, "true", "1"])
|
|
877
879
|
end
|
|
878
880
|
|
|
879
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
|