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
|
@@ -8,11 +8,11 @@ module Spree
|
|
|
8
8
|
|
|
9
9
|
def authorize(amount_in_cents, provided_store_credit, gateway_options = {})
|
|
10
10
|
if provided_store_credit.nil?
|
|
11
|
-
ActiveMerchant::Billing::Response.new(false, I18n.t(
|
|
11
|
+
ActiveMerchant::Billing::Response.new(false, I18n.t("spree.store_credit.unable_to_find"), {}, {})
|
|
12
12
|
else
|
|
13
13
|
action = ->(store_credit) {
|
|
14
14
|
store_credit.authorize(
|
|
15
|
-
amount_in_cents / 100.0
|
|
15
|
+
amount_in_cents / BigDecimal("100.0"),
|
|
16
16
|
gateway_options[:currency],
|
|
17
17
|
action_originator: gateway_options[:originator]
|
|
18
18
|
)
|
|
@@ -24,7 +24,7 @@ module Spree
|
|
|
24
24
|
def capture(amount_in_cents, auth_code, gateway_options = {})
|
|
25
25
|
action = ->(store_credit) {
|
|
26
26
|
store_credit.capture(
|
|
27
|
-
amount_in_cents / 100.0
|
|
27
|
+
amount_in_cents / BigDecimal("100.0"),
|
|
28
28
|
auth_code,
|
|
29
29
|
gateway_options[:currency],
|
|
30
30
|
action_originator: gateway_options[:originator]
|
|
@@ -35,14 +35,14 @@ module Spree
|
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
def purchase(amount_in_cents, store_credit, gateway_options = {})
|
|
38
|
-
eligible_events = store_credit.store_credit_events.where(amount: amount_in_cents / 100.0
|
|
38
|
+
eligible_events = store_credit.store_credit_events.where(amount: amount_in_cents / BigDecimal("100.0"), action: Spree::StoreCredit::ELIGIBLE_ACTION)
|
|
39
39
|
event = eligible_events.find do |eligible_event|
|
|
40
40
|
store_credit.store_credit_events.where(authorization_code: eligible_event.authorization_code)
|
|
41
|
-
|
|
41
|
+
.where.not(action: Spree::StoreCredit::ELIGIBLE_ACTION).empty?
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
if event.blank?
|
|
45
|
-
ActiveMerchant::Billing::Response.new(false, I18n.t(
|
|
45
|
+
ActiveMerchant::Billing::Response.new(false, I18n.t("spree.store_credit.unable_to_find"), {}, {})
|
|
46
46
|
else
|
|
47
47
|
capture(amount_in_cents, event.authorization_code, gateway_options)
|
|
48
48
|
end
|
|
@@ -60,7 +60,7 @@ module Spree
|
|
|
60
60
|
currency = gateway_options[:currency] || store_credit.currency
|
|
61
61
|
originator = gateway_options[:originator]
|
|
62
62
|
|
|
63
|
-
store_credit.credit(amount_in_cents / 100.0
|
|
63
|
+
store_credit.credit(amount_in_cents / BigDecimal("100.0"), auth_code, currency, action_originator: originator)
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
handle_action(action, :credit, auth_code)
|
|
@@ -73,13 +73,13 @@ module Spree
|
|
|
73
73
|
store_credit = store_credit_event.try(:store_credit)
|
|
74
74
|
|
|
75
75
|
if store_credit_event.nil? || store_credit.nil?
|
|
76
|
-
ActiveMerchant::Billing::Response.new(false,
|
|
76
|
+
ActiveMerchant::Billing::Response.new(false, "", {}, {})
|
|
77
77
|
elsif store_credit_event.capture_action?
|
|
78
78
|
false # payment#cancel! handles the refund
|
|
79
79
|
elsif store_credit_event.authorization_action?
|
|
80
80
|
void(auth_code)
|
|
81
81
|
else
|
|
82
|
-
ActiveMerchant::Billing::Response.new(false,
|
|
82
|
+
ActiveMerchant::Billing::Response.new(false, "", {}, {})
|
|
83
83
|
end
|
|
84
84
|
end
|
|
85
85
|
|
|
@@ -91,11 +91,11 @@ module Spree
|
|
|
91
91
|
|
|
92
92
|
def handle_action_call(store_credit, action, action_name, auth_code = nil)
|
|
93
93
|
store_credit.with_lock do
|
|
94
|
-
if response = action.call(store_credit)
|
|
94
|
+
if (response = action.call(store_credit))
|
|
95
95
|
# note that we only need to return the auth code on an 'auth', but it's innocuous to always return
|
|
96
96
|
ActiveMerchant::Billing::Response.new(true,
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
I18n.t("spree.store_credit.successful_action", action: action_name),
|
|
98
|
+
{}, {authorization: auth_code || response})
|
|
99
99
|
else
|
|
100
100
|
ActiveMerchant::Billing::Response.new(false, store_credit.errors.full_messages.join, {}, {})
|
|
101
101
|
end
|
|
@@ -107,7 +107,7 @@ module Spree
|
|
|
107
107
|
store_credit = Spree::StoreCreditEvent.find_by(authorization_code: auth_code).try(:store_credit)
|
|
108
108
|
|
|
109
109
|
if store_credit.nil?
|
|
110
|
-
ActiveMerchant::Billing::Response.new(false, I18n.t(
|
|
110
|
+
ActiveMerchant::Billing::Response.new(false, I18n.t("spree.store_credit.unable_to_find_for_action", auth_code:, action: action_name), {}, {})
|
|
111
111
|
else
|
|
112
112
|
handle_action_call(store_credit, action, action_name, auth_code)
|
|
113
113
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "spree/preferences/statically_configurable"
|
|
4
4
|
|
|
5
5
|
module Spree
|
|
6
6
|
# A base class which is used for implementing payment methods.
|
|
@@ -12,9 +12,10 @@ module Spree
|
|
|
12
12
|
#
|
|
13
13
|
class PaymentMethod < Spree::Base
|
|
14
14
|
include Spree::Preferences::Persistable
|
|
15
|
+
|
|
15
16
|
class UnsupportedPaymentMethod < StandardError; end
|
|
16
17
|
|
|
17
|
-
preference :server, :string, default:
|
|
18
|
+
preference :server, :string, default: "test"
|
|
18
19
|
preference :test_mode, :boolean, default: true
|
|
19
20
|
|
|
20
21
|
include Spree::SoftDeletable
|
|
@@ -53,7 +54,7 @@ module Spree
|
|
|
53
54
|
options[:default],
|
|
54
55
|
@human
|
|
55
56
|
].compact
|
|
56
|
-
options = {
|
|
57
|
+
options = {scope: [:activerecord, :models], count: 1, default: defaults}.merge!(options.except(:default))
|
|
57
58
|
I18n.translate(defaults.shift, **options)
|
|
58
59
|
end
|
|
59
60
|
end
|
|
@@ -64,12 +65,12 @@ module Spree
|
|
|
64
65
|
end
|
|
65
66
|
|
|
66
67
|
def find_sti_class(type_name)
|
|
67
|
-
super
|
|
68
|
+
super
|
|
68
69
|
rescue ActiveRecord::SubclassNotFound
|
|
69
|
-
raise UnsupportedPaymentMethod, "Found invalid payment type '#{type_name}'.\n"\
|
|
70
|
-
"This may happen after switching payment service provider, when payment methods "\
|
|
71
|
-
"reference old types that are not supported any more.\n"\
|
|
72
|
-
"If that is the case, consider running 'rake payment_method:deactivate_unsupported_payment_methods' "\
|
|
70
|
+
raise UnsupportedPaymentMethod, "Found invalid payment type '#{type_name}'.\n" \
|
|
71
|
+
"This may happen after switching payment service provider, when payment methods " \
|
|
72
|
+
"reference old types that are not supported any more.\n" \
|
|
73
|
+
"If that is the case, consider running 'rake payment_method:deactivate_unsupported_payment_methods' " \
|
|
73
74
|
"to fix the issue."
|
|
74
75
|
end
|
|
75
76
|
end
|
|
@@ -91,7 +92,7 @@ module Spree
|
|
|
91
92
|
gateway_options.delete :login if gateway_options.key?(:login) && gateway_options[:login].nil?
|
|
92
93
|
|
|
93
94
|
# All environments except production considered to be test
|
|
94
|
-
test_server = gateway_options[:server] !=
|
|
95
|
+
test_server = gateway_options[:server] != "production"
|
|
95
96
|
test_mode = gateway_options[:test_mode]
|
|
96
97
|
|
|
97
98
|
gateway_options[:test] = (test_server || test_mode)
|
|
@@ -182,9 +183,9 @@ module Spree
|
|
|
182
183
|
# @return [ActiveMerchant::Billing::Response|FalseClass]
|
|
183
184
|
def try_void(payment)
|
|
184
185
|
void_attempt = if payment.payment_method.payment_profiles_supported?
|
|
185
|
-
void(payment.transaction_id, payment.source, {
|
|
186
|
+
void(payment.transaction_id, payment.source, {originator: payment})
|
|
186
187
|
else
|
|
187
|
-
void(payment.transaction_id, {
|
|
188
|
+
void(payment.transaction_id, {originator: payment})
|
|
188
189
|
end
|
|
189
190
|
|
|
190
191
|
return void_attempt if void_attempt.success?
|
|
@@ -8,7 +8,7 @@ module Spree
|
|
|
8
8
|
|
|
9
9
|
has_many :payments, as: :source
|
|
10
10
|
has_many :wallet_payment_sources,
|
|
11
|
-
class_name:
|
|
11
|
+
class_name: "Spree::WalletPaymentSource",
|
|
12
12
|
as: :payment_source,
|
|
13
13
|
inverse_of: :payment_source,
|
|
14
14
|
dependent: :destroy
|
|
@@ -17,7 +17,7 @@ module Spree
|
|
|
17
17
|
|
|
18
18
|
# @return [Array<String>] the actions available on this payment source
|
|
19
19
|
def actions
|
|
20
|
-
%w
|
|
20
|
+
%w[capture void credit]
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
# @param payment [Spree::Payment] the payment we want to know if can be captured
|
|
@@ -19,9 +19,9 @@ module Spree
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def activate!
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
Spree.deprecator.warn "The #{self.class.name} module is deprecated. " \
|
|
23
|
+
"If you still use dashboards, please copy all controllers and views from #{self.class.name} to your application."
|
|
24
|
+
can [:admin, :home], :dashboards
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
end
|
|
@@ -70,7 +70,7 @@ module Spree
|
|
|
70
70
|
can :create, Spree.user_class
|
|
71
71
|
can [:show, :update, :update_email], Spree.user_class, id: user.id
|
|
72
72
|
can :read, State
|
|
73
|
-
can :read, StockItem, stock_location: {
|
|
73
|
+
can :read, StockItem, stock_location: {active: true}
|
|
74
74
|
can :read, StockLocation, active: true
|
|
75
75
|
can :read, Taxon
|
|
76
76
|
can :read, Taxonomy
|
data/app/models/spree/price.rb
CHANGED
|
@@ -4,9 +4,9 @@ module Spree
|
|
|
4
4
|
class Price < Spree::Base
|
|
5
5
|
include Spree::SoftDeletable
|
|
6
6
|
|
|
7
|
-
MAXIMUM_AMOUNT = BigDecimal(
|
|
7
|
+
MAXIMUM_AMOUNT = BigDecimal("99_999_999.99")
|
|
8
8
|
|
|
9
|
-
belongs_to :variant, -> { with_discarded }, class_name:
|
|
9
|
+
belongs_to :variant, -> { with_discarded }, class_name: "Spree::Variant", touch: true, optional: true
|
|
10
10
|
belongs_to :country, class_name: "Spree::Country", foreign_key: "country_iso", primary_key: "iso", optional: true
|
|
11
11
|
|
|
12
12
|
delegate :product, to: :variant
|
|
@@ -17,20 +17,21 @@ module Spree
|
|
|
17
17
|
greater_than_or_equal_to: 0,
|
|
18
18
|
less_than_or_equal_to: MAXIMUM_AMOUNT
|
|
19
19
|
}
|
|
20
|
-
validates :currency, inclusion: {
|
|
20
|
+
validates :currency, inclusion: {in: ::Money::Currency.all.map(&:iso_code), message: :invalid_code}
|
|
21
21
|
validates :country, presence: true, unless: -> { for_any_country? }
|
|
22
22
|
|
|
23
23
|
scope :currently_valid, -> { order(Arel.sql("country_iso IS NULL")).order(updated_at: :DESC, id: :DESC) }
|
|
24
|
-
scope :for_master, -> { joins(:variant).where(spree_variants: {
|
|
25
|
-
scope :for_variant, -> { joins(:variant).where(spree_variants: {
|
|
24
|
+
scope :for_master, -> { joins(:variant).where(spree_variants: {is_master: true}) }
|
|
25
|
+
scope :for_variant, -> { joins(:variant).where(spree_variants: {is_master: false}) }
|
|
26
26
|
scope :for_any_country, -> { where(country: nil) }
|
|
27
27
|
scope :with_default_attributes, -> { where(Spree::Config.default_pricing_options.desired_attributes) }
|
|
28
28
|
|
|
29
29
|
extend DisplayMoney
|
|
30
|
+
|
|
30
31
|
money_methods :amount, :price
|
|
31
32
|
alias_method :money, :display_amount
|
|
32
33
|
|
|
33
|
-
self.allowed_ransackable_attributes = %w
|
|
34
|
+
self.allowed_ransackable_attributes = %w[amount variant_id currency country_iso]
|
|
34
35
|
|
|
35
36
|
# An alias for #amount
|
|
36
37
|
def price
|
|
@@ -17,9 +17,9 @@ module Spree
|
|
|
17
17
|
def self.property_conditions(property)
|
|
18
18
|
properties = Property.table_name
|
|
19
19
|
case property
|
|
20
|
-
when String
|
|
21
|
-
when Property then {
|
|
22
|
-
else {
|
|
20
|
+
when String then {"#{properties}.name" => property}
|
|
21
|
+
when Property then {"#{properties}.id" => property.id}
|
|
22
|
+
else {"#{properties}.id" => property.to_i}
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
25
|
|
|
@@ -29,17 +29,17 @@ module Spree
|
|
|
29
29
|
scope :descend_by_name, -> { order(name: :desc) }
|
|
30
30
|
|
|
31
31
|
add_search_scope :ascend_by_master_price do
|
|
32
|
-
joins(master: :prices).select(
|
|
33
|
-
|
|
32
|
+
joins(master: :prices).select("spree_products.* , spree_prices.amount")
|
|
33
|
+
.order(Spree::Price.arel_table[:amount].asc)
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
add_search_scope :descend_by_master_price do
|
|
37
|
-
joins(master: :prices).select(
|
|
38
|
-
|
|
37
|
+
joins(master: :prices).select("spree_products.* , spree_prices.amount")
|
|
38
|
+
.order(Spree::Price.arel_table[:amount].desc)
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
add_search_scope :price_between do |low, high|
|
|
42
|
-
joins(master: :prices).where(Price.table_name => {
|
|
42
|
+
joins(master: :prices).where(Price.table_name => {amount: low..high})
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
add_search_scope :master_price_lte do |price|
|
|
@@ -69,7 +69,7 @@ module Spree
|
|
|
69
69
|
# SELECT COUNT(*) ...
|
|
70
70
|
add_search_scope :in_taxon do |taxon|
|
|
71
71
|
includes(:classifications)
|
|
72
|
-
.where(
|
|
72
|
+
.where("spree_products_taxons.taxon_id" => taxon.self_and_descendants.pluck(:id))
|
|
73
73
|
.order(Spree::Classification.arel_table[:position].asc)
|
|
74
74
|
end
|
|
75
75
|
|
|
@@ -98,9 +98,9 @@ module Spree
|
|
|
98
98
|
add_search_scope :with_option do |option|
|
|
99
99
|
option_types = Spree::OptionType.table_name
|
|
100
100
|
conditions = case option
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
when String then {"#{option_types}.name" => option}
|
|
102
|
+
when OptionType then {"#{option_types}.id" => option.id}
|
|
103
|
+
else {"#{option_types}.id" => option.to_i}
|
|
104
104
|
end
|
|
105
105
|
|
|
106
106
|
joins(:option_types).where(conditions)
|
|
@@ -109,22 +109,22 @@ module Spree
|
|
|
109
109
|
add_search_scope :with_option_value do |option, value|
|
|
110
110
|
option_values = Spree::OptionValue.table_name
|
|
111
111
|
option_type_id = case option
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
when String then Spree::OptionType.find_by(name: option) || option.to_i
|
|
113
|
+
when Spree::OptionType then option.id
|
|
114
|
+
else option.to_i
|
|
115
115
|
end
|
|
116
116
|
|
|
117
117
|
conditions = "#{option_values}.name = ? AND #{option_values}.option_type_id = ?", value, option_type_id
|
|
118
|
-
group(
|
|
118
|
+
group("spree_products.id").joins(variants_including_master: :option_values).where(conditions)
|
|
119
119
|
end
|
|
120
120
|
|
|
121
121
|
# Finds all products which have either:
|
|
122
122
|
# 1) have an option value with the name matching the one given
|
|
123
123
|
# 2) have a product property with a value matching the one given
|
|
124
124
|
add_search_scope :with do |value|
|
|
125
|
-
includes(variants_including_master: :option_values)
|
|
126
|
-
includes(:product_properties)
|
|
127
|
-
where("#{Spree::OptionValue.table_name}.name = ? OR #{Spree::ProductProperty.table_name}.value = ?", value, value)
|
|
125
|
+
includes(variants_including_master: :option_values)
|
|
126
|
+
.includes(:product_properties)
|
|
127
|
+
.where("#{Spree::OptionValue.table_name}.name = ? OR #{Spree::ProductProperty.table_name}.value = ?", value, value)
|
|
128
128
|
end
|
|
129
129
|
|
|
130
130
|
# Finds all products that have a name containing the given words.
|
|
@@ -157,8 +157,8 @@ module Spree
|
|
|
157
157
|
# joins: "LEFT OUTER JOIN (SELECT line_items.variant_id as vid, COUNT(*) as cnt FROM line_items GROUP BY line_items.variant_id) AS popularity_count ON variants.id = vid",
|
|
158
158
|
# order: 'COALESCE(cnt, 0) DESC'
|
|
159
159
|
add_search_scope :descend_by_popularity do
|
|
160
|
-
joins(:master)
|
|
161
|
-
order(Arel.sql(%{
|
|
160
|
+
joins(:master)
|
|
161
|
+
.order(Arel.sql(%{
|
|
162
162
|
COALESCE((
|
|
163
163
|
SELECT
|
|
164
164
|
COUNT(#{Spree::LineItem.quoted_table_name}.id)
|
|
@@ -230,10 +230,10 @@ module Spree
|
|
|
230
230
|
# Produce an array of keywords for use in scopes.
|
|
231
231
|
# Always return array with at least an empty string to avoid SQL errors
|
|
232
232
|
def prepare_words(words)
|
|
233
|
-
return [
|
|
233
|
+
return [""] if words.blank?
|
|
234
234
|
|
|
235
235
|
splitted = words.split(/[,\s]/).map(&:strip)
|
|
236
|
-
splitted.any? ? splitted : [
|
|
236
|
+
splitted.any? ? splitted : [""]
|
|
237
237
|
end
|
|
238
238
|
|
|
239
239
|
def get_taxons(*ids_or_records_or_names)
|
data/app/models/spree/product.rb
CHANGED
|
@@ -7,6 +7,7 @@ module Spree
|
|
|
7
7
|
# variant.
|
|
8
8
|
class Product < Spree::Base
|
|
9
9
|
extend FriendlyId
|
|
10
|
+
|
|
10
11
|
friendly_id :slug_candidates, use: :history
|
|
11
12
|
|
|
12
13
|
include Spree::SoftDeletable
|
|
@@ -15,7 +16,7 @@ module Spree
|
|
|
15
16
|
variants_including_master.discard_all
|
|
16
17
|
self.product_option_types = []
|
|
17
18
|
self.product_properties = []
|
|
18
|
-
|
|
19
|
+
classifications.destroy_all
|
|
19
20
|
end
|
|
20
21
|
|
|
21
22
|
has_many :product_option_types, dependent: :destroy, inverse_of: :product
|
|
@@ -30,27 +31,27 @@ module Spree
|
|
|
30
31
|
has_many :classifications, dependent: :delete_all, inverse_of: :product
|
|
31
32
|
has_many :taxons, through: :classifications, before_remove: :remove_taxon
|
|
32
33
|
|
|
33
|
-
belongs_to :tax_category, class_name:
|
|
34
|
-
belongs_to :shipping_category, class_name:
|
|
35
|
-
belongs_to :primary_taxon, class_name:
|
|
34
|
+
belongs_to :tax_category, class_name: "Spree::TaxCategory", optional: true
|
|
35
|
+
belongs_to :shipping_category, class_name: "Spree::ShippingCategory", inverse_of: :products
|
|
36
|
+
belongs_to :primary_taxon, class_name: "Spree::Taxon", optional: true
|
|
36
37
|
|
|
37
38
|
has_one :master,
|
|
38
39
|
-> { where(is_master: true).with_discarded },
|
|
39
40
|
inverse_of: :product,
|
|
40
|
-
class_name:
|
|
41
|
+
class_name: "Spree::Variant",
|
|
41
42
|
autosave: true,
|
|
42
43
|
dependent: false
|
|
43
44
|
|
|
44
45
|
has_many :variants,
|
|
45
46
|
-> { where(is_master: false).order(:position) },
|
|
46
47
|
inverse_of: :product,
|
|
47
|
-
class_name:
|
|
48
|
+
class_name: "Spree::Variant",
|
|
48
49
|
dependent: false
|
|
49
50
|
|
|
50
51
|
has_many :variants_including_master,
|
|
51
52
|
-> { order(:position) },
|
|
52
53
|
inverse_of: :product,
|
|
53
|
-
class_name:
|
|
54
|
+
class_name: "Spree::Variant",
|
|
54
55
|
dependent: :destroy
|
|
55
56
|
|
|
56
57
|
has_many :prices, -> { order(Spree::Variant.arel_table[:position].asc, Spree::Variant.arel_table[:id].asc, :currency) }, through: :variants_including_master
|
|
@@ -63,14 +64,14 @@ module Spree
|
|
|
63
64
|
has_many :option_values, -> { distinct }, through: :variants_including_master
|
|
64
65
|
|
|
65
66
|
scope :sort_by_master_default_price_amount_asc, -> {
|
|
66
|
-
with_default_price.order(
|
|
67
|
+
with_default_price.order("spree_prices.amount ASC")
|
|
67
68
|
}
|
|
68
69
|
scope :sort_by_master_default_price_amount_desc, -> {
|
|
69
|
-
with_default_price.order(
|
|
70
|
+
with_default_price.order("spree_prices.amount DESC")
|
|
70
71
|
}
|
|
71
72
|
scope :with_default_price, -> {
|
|
72
73
|
left_joins(master: :prices)
|
|
73
|
-
.where(master: {
|
|
74
|
+
.where(master: {spree_prices: Spree::Config.default_pricing_options.desired_attributes})
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
def find_or_build_master
|
|
@@ -95,13 +96,13 @@ module Spree
|
|
|
95
96
|
end
|
|
96
97
|
|
|
97
98
|
delegate :amount_in,
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
99
|
+
:display_amount,
|
|
100
|
+
:display_price,
|
|
101
|
+
:has_default_price?,
|
|
102
|
+
:images,
|
|
103
|
+
:price_for_options,
|
|
104
|
+
:rebuild_vat_prices=,
|
|
105
|
+
to: :find_or_build_master
|
|
105
106
|
|
|
106
107
|
alias_method :master_images, :images
|
|
107
108
|
|
|
@@ -120,18 +121,18 @@ module Spree
|
|
|
120
121
|
before_validation :normalize_slug, on: :update
|
|
121
122
|
before_validation :validate_master
|
|
122
123
|
|
|
123
|
-
validates :meta_keywords, length: {
|
|
124
|
-
validates :meta_title, length: {
|
|
124
|
+
validates :meta_keywords, length: {maximum: 255}
|
|
125
|
+
validates :meta_title, length: {maximum: 255}
|
|
125
126
|
validates :name, presence: true
|
|
126
127
|
validates :price, presence: true, if: proc { Spree::Config[:require_master_price] }
|
|
127
|
-
validates :slug, presence: true, uniqueness: {
|
|
128
|
+
validates :slug, presence: true, uniqueness: {allow_blank: true, case_sensitive: true}
|
|
128
129
|
|
|
129
130
|
attr_accessor :option_values_hash
|
|
130
131
|
|
|
131
132
|
accepts_nested_attributes_for :variant_property_rules, allow_destroy: true
|
|
132
133
|
accepts_nested_attributes_for :product_properties, allow_destroy: true, reject_if: lambda { |pp| pp[:property_name].blank? }
|
|
133
134
|
|
|
134
|
-
|
|
135
|
+
alias_method :options, :product_option_types
|
|
135
136
|
|
|
136
137
|
self.allowed_ransackable_associations = %w[stores variants_including_master master variants option_values]
|
|
137
138
|
self.allowed_ransackable_attributes = %w[name slug]
|
|
@@ -147,6 +148,11 @@ module Spree
|
|
|
147
148
|
super || Spree::TaxCategory.find_by(is_default: true)
|
|
148
149
|
end
|
|
149
150
|
|
|
151
|
+
# @return [Integer] tax category id for this product, or the default tax category id
|
|
152
|
+
def tax_category_id
|
|
153
|
+
super || tax_category&.id
|
|
154
|
+
end
|
|
155
|
+
|
|
150
156
|
# Ensures option_types and product_option_types exist for keys in
|
|
151
157
|
# option_values_hash.
|
|
152
158
|
#
|
|
@@ -225,24 +231,24 @@ module Spree
|
|
|
225
231
|
# associated with the products variants grouped by option type
|
|
226
232
|
def variant_option_values_by_option_type(variant_scope = nil)
|
|
227
233
|
option_value_scope = Spree::OptionValuesVariant.joins(:variant)
|
|
228
|
-
.where(spree_variants: {
|
|
234
|
+
.where(spree_variants: {product_id: id})
|
|
229
235
|
option_value_scope = option_value_scope.merge(variant_scope) if variant_scope
|
|
230
236
|
option_value_ids = option_value_scope.distinct.pluck(:option_value_id)
|
|
231
|
-
Spree::OptionValue.where(id: option_value_ids)
|
|
232
|
-
includes(:option_type)
|
|
233
|
-
order("#{Spree::OptionType.table_name}.position, #{Spree::OptionValue.table_name}.position")
|
|
234
|
-
group_by(&:option_type)
|
|
237
|
+
Spree::OptionValue.where(id: option_value_ids)
|
|
238
|
+
.includes(:option_type)
|
|
239
|
+
.order("#{Spree::OptionType.table_name}.position, #{Spree::OptionValue.table_name}.position")
|
|
240
|
+
.group_by(&:option_type)
|
|
235
241
|
end
|
|
236
242
|
|
|
237
243
|
# @return [Boolean] true if there are no option values
|
|
238
244
|
def empty_option_values?
|
|
239
|
-
options.empty? || !option_types.left_joins(:option_values).where(
|
|
245
|
+
options.empty? || !option_types.left_joins(:option_values).where("spree_option_values.id IS NULL").empty?
|
|
240
246
|
end
|
|
241
247
|
|
|
242
248
|
# @param property_name [String] the name of the property to find
|
|
243
249
|
# @return [String] the value of the given property. nil if property is undefined on this product
|
|
244
250
|
def property(property_name)
|
|
245
|
-
return nil unless prop = properties.find_by(name: property_name)
|
|
251
|
+
return nil unless (prop = properties.find_by(name: property_name))
|
|
246
252
|
product_properties.find_by(property: prop).try(:value)
|
|
247
253
|
end
|
|
248
254
|
|
|
@@ -270,10 +276,8 @@ module Spree
|
|
|
270
276
|
#
|
|
271
277
|
# @return [Fixnum, Infinity]
|
|
272
278
|
def total_on_hand
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
else
|
|
276
|
-
stock_items.sum(:count_on_hand)
|
|
279
|
+
variants_including_master.sum do |variant|
|
|
280
|
+
Spree::Config.stock.quantifier_class.new(variant).total_on_hand
|
|
277
281
|
end
|
|
278
282
|
end
|
|
279
283
|
|
|
@@ -301,14 +305,6 @@ module Spree
|
|
|
301
305
|
|
|
302
306
|
private
|
|
303
307
|
|
|
304
|
-
def any_variants_not_track_inventory?
|
|
305
|
-
if variants_including_master.loaded?
|
|
306
|
-
variants_including_master.any? { |variant| !variant.should_track_inventory? }
|
|
307
|
-
else
|
|
308
|
-
!Spree::Config.track_inventory_levels || variants_including_master.where(track_inventory: false).exists?
|
|
309
|
-
end
|
|
310
|
-
end
|
|
311
|
-
|
|
312
308
|
# Builds variants from a hash of option types & values
|
|
313
309
|
def build_variants_from_option_values_hash
|
|
314
310
|
ensure_option_types_exist_for_values_hash
|
|
@@ -377,4 +373,4 @@ module Spree
|
|
|
377
373
|
end
|
|
378
374
|
end
|
|
379
375
|
|
|
380
|
-
require_dependency
|
|
376
|
+
require_dependency "spree/product/scopes"
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
module Spree
|
|
4
4
|
class ProductOptionType < Spree::Base
|
|
5
|
-
belongs_to :product, class_name:
|
|
6
|
-
belongs_to :option_type, class_name:
|
|
5
|
+
belongs_to :product, class_name: "Spree::Product", inverse_of: :product_option_types, touch: true
|
|
6
|
+
belongs_to :option_type, class_name: "Spree::OptionType", inverse_of: :product_option_types
|
|
7
7
|
acts_as_list scope: :product
|
|
8
8
|
end
|
|
9
9
|
end
|
|
@@ -6,9 +6,9 @@ module Spree
|
|
|
6
6
|
|
|
7
7
|
acts_as_list scope: :product
|
|
8
8
|
|
|
9
|
-
belongs_to :product, touch: true, class_name:
|
|
10
|
-
belongs_to :property, class_name:
|
|
9
|
+
belongs_to :product, touch: true, class_name: "Spree::Product", inverse_of: :product_properties
|
|
10
|
+
belongs_to :property, class_name: "Spree::Property", inverse_of: :product_properties
|
|
11
11
|
|
|
12
|
-
self.allowed_ransackable_attributes = [
|
|
12
|
+
self.allowed_ransackable_attributes = ["value"]
|
|
13
13
|
end
|
|
14
14
|
end
|
data/app/models/spree/refund.rb
CHANGED
|
@@ -5,14 +5,14 @@ module Spree
|
|
|
5
5
|
include Metadata
|
|
6
6
|
|
|
7
7
|
belongs_to :payment, inverse_of: :refunds, optional: true
|
|
8
|
-
belongs_to :reason, class_name:
|
|
8
|
+
belongs_to :reason, class_name: "Spree::RefundReason", foreign_key: :refund_reason_id, optional: true
|
|
9
9
|
belongs_to :reimbursement, inverse_of: :refunds, optional: true
|
|
10
10
|
|
|
11
11
|
has_many :log_entries, as: :source
|
|
12
12
|
|
|
13
13
|
validates :payment, presence: true
|
|
14
14
|
validates :reason, presence: true
|
|
15
|
-
validates :amount, presence: true, numericality: {
|
|
15
|
+
validates :amount, presence: true, numericality: {greater_than: 0}
|
|
16
16
|
|
|
17
17
|
validate :amount_is_less_than_or_equal_to_allowed_amount, on: :create
|
|
18
18
|
|
|
@@ -23,9 +23,9 @@ module Spree
|
|
|
23
23
|
delegate :currency, to: :payment
|
|
24
24
|
|
|
25
25
|
def money
|
|
26
|
-
Spree::Money.new(amount, {
|
|
26
|
+
Spree::Money.new(amount, {currency:})
|
|
27
27
|
end
|
|
28
|
-
|
|
28
|
+
alias_method :display_amount, :money
|
|
29
29
|
|
|
30
30
|
class << self
|
|
31
31
|
def total_amount_reimbursed_for(reimbursement)
|
|
@@ -68,21 +68,21 @@ module Spree
|
|
|
68
68
|
# return an activemerchant response object if successful or else raise an error
|
|
69
69
|
def process!(credit_cents)
|
|
70
70
|
response = if payment.payment_method.payment_profiles_supported?
|
|
71
|
-
payment.payment_method.credit(credit_cents, payment.source, payment.transaction_id, {
|
|
71
|
+
payment.payment_method.credit(credit_cents, payment.source, payment.transaction_id, {originator: self})
|
|
72
72
|
else
|
|
73
|
-
payment.payment_method.credit(credit_cents, payment.transaction_id, {
|
|
73
|
+
payment.payment_method.credit(credit_cents, payment.transaction_id, {originator: self})
|
|
74
74
|
end
|
|
75
75
|
|
|
76
76
|
if !response.success?
|
|
77
|
-
logger.error(I18n.t(
|
|
78
|
-
text = response.params[
|
|
77
|
+
logger.error(I18n.t("spree.gateway_error") + " #{response.to_yaml}")
|
|
78
|
+
text = response.params["message"] || response.params["response_reason_text"] || response.message
|
|
79
79
|
raise Core::GatewayError.new(text)
|
|
80
80
|
end
|
|
81
81
|
|
|
82
82
|
response
|
|
83
83
|
rescue ActiveMerchant::ConnectionError => error
|
|
84
|
-
logger.error(I18n.t(
|
|
85
|
-
raise Core::GatewayError.new(I18n.t(
|
|
84
|
+
logger.error(I18n.t("spree.gateway_error") + " #{error.inspect}")
|
|
85
|
+
raise Core::GatewayError.new(I18n.t("spree.unable_to_connect_to_gateway"))
|
|
86
86
|
end
|
|
87
87
|
|
|
88
88
|
def amount_is_less_than_or_equal_to_allowed_amount
|
|
@@ -5,9 +5,9 @@ module Spree
|
|
|
5
5
|
scope :active, -> { where(active: true) }
|
|
6
6
|
default_scope -> { order(arel_table[:name].lower) }
|
|
7
7
|
|
|
8
|
-
validates :name, presence: true, uniqueness: {
|
|
8
|
+
validates :name, presence: true, uniqueness: {case_sensitive: false, allow_blank: true}
|
|
9
9
|
|
|
10
|
-
RETURN_PROCESSING_REASON =
|
|
10
|
+
RETURN_PROCESSING_REASON = "Return processing"
|
|
11
11
|
|
|
12
12
|
has_many :refunds
|
|
13
13
|
|