solidus_core 2.10.5 → 3.0.8
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/app/assets/javascripts/spree.js.erb +0 -22
- data/app/controllers/spree/base_controller.rb +1 -0
- data/app/helpers/spree/store_helper.rb +0 -11
- data/app/mailers/spree/base_mailer.rb +4 -0
- data/app/mailers/spree/carton_mailer.rb +1 -5
- data/app/mailers/spree/order_mailer.rb +1 -1
- data/app/models/concerns/spree/active_storage_adapter/attachment.rb +71 -0
- data/app/models/concerns/spree/active_storage_adapter/normalization.rb +39 -0
- data/app/models/concerns/spree/active_storage_adapter.rb +118 -0
- data/app/models/concerns/spree/adjustment_source.rb +0 -15
- data/app/models/concerns/spree/calculated_adjustments.rb +0 -18
- data/app/models/concerns/spree/default_price.rb +1 -1
- data/app/models/concerns/spree/soft_deletable.rb +16 -0
- data/app/models/concerns/spree/user_address_book.rb +61 -44
- data/app/models/concerns/spree/user_methods.rb +23 -12
- data/app/models/spree/ability.rb +0 -13
- data/app/models/spree/address/name.rb +31 -0
- data/app/models/spree/address/state_validator.rb +71 -0
- data/app/models/spree/address.rb +17 -95
- data/app/models/spree/adjustment.rb +1 -29
- data/app/models/spree/base.rb +1 -28
- data/app/models/spree/calculator/default_tax.rb +1 -1
- data/app/models/spree/calculator/flexi_rate.rb +0 -5
- data/app/models/spree/calculator.rb +8 -11
- data/app/models/spree/country.rb +1 -6
- data/app/models/spree/credit_card.rb +2 -29
- data/app/models/spree/customer_return.rb +5 -6
- data/app/models/spree/exchange.rb +1 -1
- data/app/models/spree/image/active_storage_attachment.rb +29 -0
- data/app/models/spree/image/paperclip_attachment.rb +1 -1
- data/app/models/spree/image.rb +0 -7
- data/app/models/spree/inventory_unit.rb +1 -22
- data/app/models/spree/line_item.rb +12 -46
- data/app/models/spree/log_entry.rb +74 -1
- data/app/models/spree/option_type.rb +1 -1
- data/app/models/spree/option_value.rb +2 -2
- data/app/models/spree/order/payments.rb +2 -2
- data/app/models/spree/order.rb +70 -132
- data/app/models/spree/order_cancellations.rb +4 -24
- data/app/models/spree/order_inventory.rb +16 -4
- data/app/models/spree/order_merger.rb +7 -5
- data/app/models/spree/order_promotion.rb +1 -1
- data/app/models/spree/order_shipping.rb +6 -9
- data/app/models/spree/order_updater.rb +7 -15
- data/app/models/spree/payment/cancellation.rb +3 -22
- data/app/models/spree/payment/processing.rb +54 -30
- data/app/models/spree/payment.rb +13 -9
- data/app/models/spree/payment_create.rb +1 -13
- data/app/models/spree/payment_method/bogus_credit_card.rb +13 -9
- data/app/models/spree/payment_method/credit_card.rb +1 -3
- data/app/models/spree/payment_method/simple_bogus_credit_card.rb +4 -4
- data/app/models/spree/payment_method.rb +7 -106
- data/app/models/spree/payment_source.rb +2 -2
- data/app/models/spree/preference.rb +1 -1
- data/app/models/spree/price.rb +3 -9
- data/app/models/spree/product/scopes.rb +9 -32
- data/app/models/spree/product.rb +24 -52
- data/app/models/spree/promotion/actions/create_adjustment.rb +0 -3
- data/app/models/spree/promotion/actions/create_item_adjustments.rb +0 -3
- data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +0 -3
- data/app/models/spree/promotion/actions/free_shipping.rb +6 -5
- data/app/models/spree/promotion/rules/taxon.rb +2 -15
- data/app/models/spree/promotion.rb +15 -8
- data/app/models/spree/promotion_action.rb +5 -15
- data/app/models/spree/promotion_code/batch_builder.rb +0 -14
- data/app/models/spree/promotion_code.rb +8 -3
- data/app/models/spree/promotion_code_batch.rb +1 -1
- data/app/models/spree/promotion_handler/coupon.rb +2 -2
- data/app/models/spree/promotion_rule.rb +5 -1
- data/app/models/spree/promotion_rule_role.rb +1 -1
- data/app/models/spree/refund.rb +19 -13
- data/app/models/spree/reimbursement.rb +11 -22
- data/app/models/spree/reimbursement_performer.rb +2 -8
- data/app/models/spree/reimbursement_type/credit.rb +1 -4
- data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +8 -2
- data/app/models/spree/reimbursement_type/store_credit.rb +1 -4
- data/app/models/spree/return_authorization.rb +2 -5
- data/app/models/spree/return_item/exchange_variant_eligibility/same_option_value.rb +1 -1
- data/app/models/spree/return_item.rb +10 -18
- data/app/models/spree/role.rb +1 -1
- data/app/models/spree/shipment.rb +3 -56
- data/app/models/spree/shipping_calculator.rb +1 -1
- data/app/models/spree/shipping_manifest.rb +2 -2
- data/app/models/spree/shipping_method.rb +3 -35
- data/app/models/spree/shipping_rate.rb +1 -3
- data/app/models/spree/shipping_rate_tax.rb +1 -1
- data/app/models/spree/state.rb +0 -4
- data/app/models/spree/stock/availability_validator.rb +2 -2
- data/app/models/spree/stock/inventory_unit_builder.rb +18 -7
- data/app/models/spree/stock/inventory_units_finalizer.rb +3 -5
- data/app/models/spree/stock/inventory_validator.rb +2 -2
- data/app/models/spree/stock/package.rb +1 -1
- data/app/models/spree/stock/simple_coordinator.rb +7 -18
- data/app/models/spree/stock/splitter/base.rb +2 -7
- data/app/models/spree/stock_item.rb +3 -15
- data/app/models/spree/stock_movement.rb +2 -0
- data/app/models/spree/store.rb +1 -13
- data/app/models/spree/store_credit.rb +9 -7
- data/app/models/spree/store_credit_category.rb +3 -8
- data/app/models/spree/store_credit_event.rb +1 -7
- data/app/models/spree/store_credit_reason.rb +0 -4
- data/app/models/spree/tax/tax_helpers.rb +1 -1
- data/app/models/spree/tax_calculator/shipping_rate.rb +1 -12
- data/app/models/spree/tax_category.rb +2 -8
- data/app/models/spree/tax_rate.rb +7 -34
- data/app/models/spree/taxon/active_storage_attachment.rb +13 -0
- data/app/models/spree/taxon/paperclip_attachment.rb +0 -4
- data/app/models/spree/taxon.rb +1 -12
- data/app/models/spree/user_address.rb +3 -2
- data/app/models/spree/variant.rb +8 -58
- data/app/models/spree/variant_property_rule.rb +5 -1
- data/app/models/spree/wallet/add_payment_sources_to_wallet.rb +8 -3
- data/app/models/spree/zone.rb +1 -1
- data/config/locales/en.yml +293 -13
- data/db/default/spree/countries.rb +1 -1
- data/db/default/spree/states.rb +12 -4
- data/db/default/spree/store_credit.rb +2 -2
- data/db/migrate/20180416083007_add_apply_to_all_to_variant_property_rule.rb +12 -0
- data/db/migrate/20200320144521_add_default_billng_flag_to_user_addresses.rb +6 -0
- data/db/migrate/20200530111458_add_bcc_email_to_spree_stores.rb +7 -0
- data/db/migrate/20201008213609_add_discontinue_on_to_spree_products.rb +7 -0
- data/db/migrate/20210122110141_add_name_to_spree_addresses.rb +13 -0
- data/lib/generators/{spree → solidus}/install/install_generator.rb +82 -14
- data/lib/generators/{spree → solidus}/install/templates/config/initializers/spree.rb.tt +4 -9
- data/lib/generators/spree/dummy/dummy_generator.rb +2 -1
- data/lib/generators/spree/dummy/templates/rails/database.yml +6 -1
- data/lib/generators/spree/dummy/templates/rails/storage.yml +3 -0
- data/lib/generators/spree/dummy/templates/rails/test.rb +6 -1
- data/lib/solidus/migrations/promotions_with_code_handlers.rb +1 -1
- data/lib/spree/app_configuration.rb +104 -72
- data/lib/spree/core/class_constantizer.rb +2 -0
- data/lib/spree/core/controller_helpers/auth.rb +4 -4
- data/lib/spree/core/controller_helpers/current_host.rb +17 -0
- data/lib/spree/core/controller_helpers/order.rb +8 -27
- data/lib/spree/core/controller_helpers/payment_parameters.rb +0 -54
- data/lib/spree/core/controller_helpers/pricing.rb +0 -8
- data/lib/spree/core/controller_helpers/strong_parameters.rb +0 -4
- data/lib/spree/core/engine.rb +23 -8
- data/lib/spree/core/environment_extension.rb +0 -9
- data/lib/spree/core/importer/order.rb +24 -10
- data/lib/spree/core/permalinks.rb +1 -3
- data/lib/spree/core/product_filters.rb +5 -44
- data/lib/spree/core/role_configuration.rb +0 -14
- data/lib/spree/core/search/base.rb +0 -26
- data/lib/spree/core/state_machines/order.rb +249 -0
- data/lib/spree/core/state_machines/return_item/reception_status.rb +2 -2
- data/lib/spree/core/state_machines.rb +11 -1
- data/lib/spree/core/validators/email.rb +2 -2
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/core.rb +11 -19
- data/lib/spree/deprecation.rb +1 -1
- data/lib/spree/encryptor.rb +25 -0
- data/lib/spree/event/adapters/active_support_notifications.rb +32 -0
- data/lib/spree/event/configuration.rb +7 -7
- data/lib/spree/event/subscriber.rb +22 -20
- data/lib/spree/event/subscriber_registry.rb +94 -0
- data/lib/spree/event.rb +20 -18
- data/lib/spree/i18n.rb +0 -22
- data/lib/spree/mailer_previews/carton_preview.rb +2 -1
- data/lib/spree/money.rb +3 -18
- data/lib/spree/permission_sets/configuration_display.rb +14 -14
- data/lib/spree/permission_sets/default_customer.rb +16 -16
- data/lib/spree/permission_sets/order_display.rb +11 -11
- data/lib/spree/permission_sets/order_management.rb +1 -1
- data/lib/spree/permission_sets/product_display.rb +9 -9
- data/lib/spree/permission_sets/promotion_display.rb +5 -5
- data/lib/spree/permission_sets/restricted_stock_display.rb +2 -2
- data/lib/spree/permission_sets/restricted_stock_management.rb +1 -1
- data/lib/spree/permission_sets/stock_display.rb +2 -2
- data/lib/spree/permission_sets/stock_management.rb +1 -1
- data/lib/spree/permission_sets/user_display.rb +3 -3
- data/lib/spree/permission_sets/user_management.rb +4 -3
- data/lib/spree/permitted_attributes.rb +12 -56
- data/lib/spree/preferences/persistable.rb +23 -0
- data/lib/spree/preferences/preferable.rb +4 -3
- data/lib/spree/preferences/preferable_class_methods.rb +22 -3
- data/lib/spree/testing_support/ability_helpers.rb +9 -9
- data/lib/spree/testing_support/authorization_helpers.rb +1 -0
- data/lib/spree/testing_support/blacklist_urls.rb +23 -0
- data/lib/spree/testing_support/capybara_ext.rb +3 -30
- data/lib/spree/testing_support/common_rake.rb +3 -3
- data/lib/spree/testing_support/controller_requests.rb +0 -82
- data/lib/spree/testing_support/dummy_app/mailer_previews/test_mailer_preview.rb +4 -0
- data/lib/spree/testing_support/dummy_app/migrations.rb +2 -6
- data/lib/spree/testing_support/dummy_app/rake_tasks.rb +1 -3
- data/lib/spree/testing_support/dummy_app.rb +41 -24
- data/lib/spree/testing_support/factories/address_factory.rb +7 -4
- data/lib/spree/testing_support/factories/adjustment_factory.rb +10 -5
- data/lib/spree/testing_support/factories/adjustment_reason_factory.rb +5 -0
- data/lib/spree/testing_support/factories/calculator_factory.rb +5 -0
- data/lib/spree/testing_support/factories/carton_factory.rb +7 -2
- data/lib/spree/testing_support/factories/country_factory.rb +5 -0
- data/lib/spree/testing_support/factories/credit_card_factory.rb +5 -0
- data/lib/spree/testing_support/factories/customer_return_factory.rb +8 -3
- data/lib/spree/testing_support/factories/image_factory.rb +6 -1
- data/lib/spree/testing_support/factories/inventory_unit_factory.rb +9 -4
- data/lib/spree/testing_support/factories/line_item_factory.rb +7 -2
- data/lib/spree/testing_support/factories/option_type_factory.rb +8 -0
- data/lib/spree/testing_support/factories/option_value_factory.rb +5 -0
- data/lib/spree/testing_support/factories/order_factory.rb +11 -7
- data/lib/spree/testing_support/factories/order_promotion_factory.rb +7 -2
- data/lib/spree/testing_support/factories/payment_factory.rb +9 -4
- data/lib/spree/testing_support/factories/payment_method_factory.rb +5 -0
- data/lib/spree/testing_support/factories/price_factory.rb +6 -1
- data/lib/spree/testing_support/factories/product_factory.rb +10 -5
- data/lib/spree/testing_support/factories/product_option_type_factory.rb +7 -2
- data/lib/spree/testing_support/factories/product_property_factory.rb +7 -2
- data/lib/spree/testing_support/factories/promotion_category_factory.rb +5 -0
- data/lib/spree/testing_support/factories/promotion_code_factory.rb +7 -2
- data/lib/spree/testing_support/factories/promotion_factory.rb +13 -2
- data/lib/spree/testing_support/factories/property_factory.rb +5 -0
- data/lib/spree/testing_support/factories/refund_factory.rb +7 -2
- data/lib/spree/testing_support/factories/refund_reason_factory.rb +5 -0
- data/lib/spree/testing_support/factories/reimbursement_factory.rb +7 -2
- data/lib/spree/testing_support/factories/reimbursement_type_factory.rb +5 -0
- data/lib/spree/testing_support/factories/return_authorization_factory.rb +8 -3
- data/lib/spree/testing_support/factories/return_item_factory.rb +8 -4
- data/lib/spree/testing_support/factories/return_reason_factory.rb +5 -0
- data/lib/spree/testing_support/factories/role_factory.rb +5 -0
- data/lib/spree/testing_support/factories/shipment_factory.rb +9 -3
- data/lib/spree/testing_support/factories/shipping_category_factory.rb +5 -0
- data/lib/spree/testing_support/factories/shipping_method_factory.rb +8 -3
- data/lib/spree/testing_support/factories/shipping_rate_factory.rb +7 -2
- data/lib/spree/testing_support/factories/state_factory.rb +7 -1
- data/lib/spree/testing_support/factories/stock_item_factory.rb +7 -2
- data/lib/spree/testing_support/factories/stock_location_factory.rb +8 -3
- data/lib/spree/testing_support/factories/stock_movement_factory.rb +6 -1
- data/lib/spree/testing_support/factories/stock_package_factory.rb +7 -2
- data/lib/spree/testing_support/factories/store_credit_category_factory.rb +13 -0
- data/lib/spree/testing_support/factories/store_credit_event_factory.rb +8 -2
- data/lib/spree/testing_support/factories/store_credit_factory.rb +8 -3
- data/lib/spree/testing_support/factories/store_credit_reason_factory.rb +8 -1
- data/lib/spree/testing_support/factories/store_credit_type_factory.rb +5 -0
- data/lib/spree/testing_support/factories/store_factory.rb +6 -1
- data/lib/spree/testing_support/factories/tax_category_factory.rb +7 -1
- data/lib/spree/testing_support/factories/tax_rate_factory.rb +8 -3
- data/lib/spree/testing_support/factories/taxon_factory.rb +10 -1
- data/lib/spree/testing_support/factories/taxonomy_factory.rb +5 -0
- data/lib/spree/testing_support/factories/user_factory.rb +14 -3
- data/lib/spree/testing_support/factories/variant_factory.rb +9 -4
- data/lib/spree/testing_support/factories/variant_property_rule_condition_factory.rb +7 -2
- data/lib/spree/testing_support/factories/variant_property_rule_factory.rb +8 -3
- data/lib/spree/testing_support/factories/variant_property_rule_value_factory.rb +7 -2
- data/lib/spree/testing_support/factories/zone_factory.rb +8 -3
- data/lib/spree/testing_support/factories.rb +8 -4
- data/lib/spree/testing_support/factory_bot.rb +68 -0
- data/lib/spree/testing_support/fixtures/blank.jpg +0 -0
- data/lib/spree/testing_support/fixtures/file.txt +1 -0
- data/lib/spree/testing_support/job_helpers.rb +24 -0
- data/lib/spree/testing_support/order_walkthrough.rb +10 -13
- data/lib/spree/testing_support/precompiled_assets.rb +15 -0
- data/lib/spree/testing_support/preferences.rb +0 -23
- data/lib/spree/testing_support/sequences.rb +4 -1
- data/lib/spree/testing_support/shared_examples/gallery.rb +1 -1
- data/lib/spree/testing_support/translations.rb +25 -0
- data/lib/spree/testing_support.rb +31 -0
- data/lib/tasks/solidus/check_orders_with_invalid_email.rake +18 -0
- data/lib/tasks/upgrade.rake +15 -0
- data/solidus_core.gemspec +30 -7
- metadata +137 -408
- data/app/mailers/spree/test_mailer.rb +0 -13
- data/app/models/concerns/spree/user_payment_source.rb +0 -26
- data/app/models/spree/calculator/free_shipping.rb +0 -21
- data/app/models/spree/calculator/percent_per_item.rb +0 -49
- data/app/models/spree/calculator/price_sack.rb +0 -27
- data/app/models/spree/gateway/bogus.rb +0 -13
- data/app/models/spree/gateway/bogus_simple.rb +0 -13
- data/app/models/spree/gateway.rb +0 -14
- data/app/models/spree/order/checkout.rb +0 -243
- data/app/models/spree/order_capturing.rb +0 -50
- data/app/models/spree/promotion_handler/free_shipping.rb +0 -9
- data/lib/solidus/migrations/rename_gateways.rb +0 -41
- data/lib/spree/core/current_store.rb +0 -24
- data/lib/spree/paranoia_deprecations.rb +0 -21
- data/lib/spree/promo/environment.rb +0 -12
- data/lib/spree/testing_support/bar_ability.rb +0 -19
- data/lib/tasks/core.rake +0 -104
- data/lib/tasks/email.rake +0 -11
- data/lib/tasks/migrations/copy_order_bill_address_to_credit_card.rake +0 -119
- data/lib/tasks/migrations/migrate_shipping_rate_taxes.rake +0 -22
- data/lib/tasks/migrations/migrate_user_addresses.rake +0 -34
- data/lib/tasks/migrations/rename_gateways.rake +0 -23
- data/lib/tasks/order_capturing.rake +0 -27
- data/script/rails +0 -10
- data/spec/fixtures/thinking-cat.jpg +0 -0
- data/spec/helpers/base_helper_spec.rb +0 -168
- data/spec/helpers/products_helper_spec.rb +0 -202
- data/spec/helpers/taxons_helper_spec.rb +0 -43
- data/spec/jobs/promotion_code_batch_job_spec.rb +0 -96
- data/spec/lib/calculated_adjustments_spec.rb +0 -133
- data/spec/lib/i18n_spec.rb +0 -97
- data/spec/lib/search/base_spec.rb +0 -91
- data/spec/lib/search/variant_spec.rb +0 -115
- data/spec/lib/spree/app_configuration_spec.rb +0 -140
- data/spec/lib/spree/core/class_constantizer_spec.rb +0 -91
- data/spec/lib/spree/core/controller_helpers/auth_spec.rb +0 -73
- data/spec/lib/spree/core/controller_helpers/order_spec.rb +0 -126
- data/spec/lib/spree/core/controller_helpers/payment_parameters_spec.rb +0 -195
- data/spec/lib/spree/core/controller_helpers/pricing_spec.rb +0 -94
- data/spec/lib/spree/core/controller_helpers/search_spec.rb +0 -21
- data/spec/lib/spree/core/controller_helpers/store_spec.rb +0 -18
- data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +0 -48
- data/spec/lib/spree/core/current_store_spec.rb +0 -33
- data/spec/lib/spree/core/environment_extension_spec.rb +0 -46
- data/spec/lib/spree/core/importer/order_spec.rb +0 -484
- data/spec/lib/spree/core/role_configuration_spec.rb +0 -155
- data/spec/lib/spree/core/stock_configuration_spec.rb +0 -95
- data/spec/lib/spree/core/testing_support/factories/address_factory_spec.rb +0 -61
- data/spec/lib/spree/core/testing_support/factories/adjustment_factory_spec.rb +0 -20
- data/spec/lib/spree/core/testing_support/factories/adjustment_reason_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/calculator_factory_spec.rb +0 -44
- data/spec/lib/spree/core/testing_support/factories/carton_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/country_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/credit_card_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/customer_return_factory_spec.rb +0 -39
- data/spec/lib/spree/core/testing_support/factories/image_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/inventory_unit_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/line_item_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/option_type_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/option_value_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/order_factory_spec.rb +0 -376
- data/spec/lib/spree/core/testing_support/factories/order_promotion_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/payment_factory_spec.rb +0 -40
- data/spec/lib/spree/core/testing_support/factories/payment_method_factory_spec.rb +0 -32
- data/spec/lib/spree/core/testing_support/factories/price_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/product_factory_spec.rb +0 -32
- data/spec/lib/spree/core/testing_support/factories/product_option_type_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/product_property_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/promotion_category_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/promotion_code_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/promotion_factory_spec.rb +0 -32
- data/spec/lib/spree/core/testing_support/factories/property_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/refund_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/refund_reason_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/reimbursement_factory_spec.rb +0 -20
- data/spec/lib/spree/core/testing_support/factories/reimbursement_type_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/return_authorization_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/return_item_factory_spec.rb +0 -20
- data/spec/lib/spree/core/testing_support/factories/return_reason_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/role_factory_spec.rb +0 -20
- data/spec/lib/spree/core/testing_support/factories/shipment_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/shipping_category_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/shipping_method_factory_spec.rb +0 -44
- data/spec/lib/spree/core/testing_support/factories/shipping_rate_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/state_factory_spec.rb +0 -59
- data/spec/lib/spree/core/testing_support/factories/stock_item_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/stock_location_factory_spec.rb +0 -35
- data/spec/lib/spree/core/testing_support/factories/stock_movement_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/stock_package_factory_spec.rb +0 -28
- data/spec/lib/spree/core/testing_support/factories/store_credit_category_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/store_credit_event_factory_spec.rb +0 -43
- data/spec/lib/spree/core/testing_support/factories/store_credit_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/store_credit_reason_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/store_credit_type_factory_spec.rb +0 -20
- data/spec/lib/spree/core/testing_support/factories/store_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/tax_category_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/tax_rate_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/taxon_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/taxonomy_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/user_factory_spec.rb +0 -24
- data/spec/lib/spree/core/testing_support/factories/variant_factory_spec.rb +0 -56
- data/spec/lib/spree/core/testing_support/factories/variant_property_rule_condition_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/variant_property_rule_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/variant_property_rule_value_factory_spec.rb +0 -14
- data/spec/lib/spree/core/testing_support/factories/zone_factory_spec.rb +0 -20
- data/spec/lib/spree/core/testing_support/preferences_spec.rb +0 -61
- data/spec/lib/spree/core/validators/email_spec.rb +0 -53
- data/spec/lib/spree/core/version_spec.rb +0 -19
- data/spec/lib/spree/event/subscriber_spec.rb +0 -85
- data/spec/lib/spree/event_spec.rb +0 -130
- data/spec/lib/spree/localized_number_spec.rb +0 -45
- data/spec/lib/spree/migrations_spec.rb +0 -32
- data/spec/lib/spree/money_spec.rb +0 -298
- data/spec/lib/spree/permission_sets/default_customer_spec.rb +0 -22
- data/spec/lib/spree/permitted_attributes_spec.rb +0 -41
- data/spec/lib/spree/promo/environment_spec.rb +0 -53
- data/spec/lib/tasks/dummy_task.rake +0 -12
- data/spec/lib/tasks/dummy_task_spec.rb +0 -30
- data/spec/lib/tasks/migrations/migrate_shipping_rate_taxes_spec.rb +0 -21
- data/spec/mailers/carton_mailer_spec.rb +0 -44
- data/spec/mailers/order_mailer_spec.rb +0 -117
- data/spec/mailers/promotion_code_batch_mailer_spec.rb +0 -47
- data/spec/mailers/reimbursement_mailer_spec.rb +0 -36
- data/spec/mailers/test_mailer_spec.rb +0 -13
- data/spec/models/spree/ability_spec.rb +0 -279
- data/spec/models/spree/address_spec.rb +0 -399
- data/spec/models/spree/adjustment_reason_spec.rb +0 -11
- data/spec/models/spree/adjustment_spec.rb +0 -339
- data/spec/models/spree/asset_spec.rb +0 -25
- data/spec/models/spree/calculator/default_tax_spec.rb +0 -260
- data/spec/models/spree/calculator/distributed_amount_spec.rb +0 -82
- data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +0 -39
- data/spec/models/spree/calculator/flat_rate_spec.rb +0 -52
- data/spec/models/spree/calculator/flexi_rate_spec.rb +0 -158
- data/spec/models/spree/calculator/free_shipping_spec.rb +0 -8
- data/spec/models/spree/calculator/percent_on_line_item_spec.rb +0 -20
- data/spec/models/spree/calculator/percent_per_item_spec.rb +0 -12
- data/spec/models/spree/calculator/price_sack_spec.rb +0 -35
- data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +0 -70
- data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +0 -44
- data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +0 -18
- data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +0 -56
- data/spec/models/spree/calculator/shipping/per_item_spec.rb +0 -25
- data/spec/models/spree/calculator/shipping/price_sack_spec.rb +0 -44
- data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +0 -99
- data/spec/models/spree/calculator/tiered_percent_spec.rb +0 -197
- data/spec/models/spree/calculator_spec.rb +0 -43
- data/spec/models/spree/carton_spec.rb +0 -145
- data/spec/models/spree/classification_spec.rb +0 -126
- data/spec/models/spree/concerns/display_money_spec.rb +0 -44
- data/spec/models/spree/concerns/ordered_property_value_list_spec.rb +0 -52
- data/spec/models/spree/concerns/user_address_book_spec.rb +0 -358
- data/spec/models/spree/concerns/user_methods_spec.rb +0 -122
- data/spec/models/spree/country_spec.rb +0 -154
- data/spec/models/spree/credit_card_spec.rb +0 -373
- data/spec/models/spree/customer_return_spec.rb +0 -294
- data/spec/models/spree/distributed_amounts_handler_spec.rb +0 -83
- data/spec/models/spree/exchange_spec.rb +0 -76
- data/spec/models/spree/fulfilment_changer_spec.rb +0 -340
- data/spec/models/spree/gallery/product_gallery_spec.rb +0 -21
- data/spec/models/spree/gallery/variant_gallery_spec.rb +0 -21
- data/spec/models/spree/gateway/bogus_simple.rb +0 -14
- data/spec/models/spree/gateway/bogus_spec.rb +0 -14
- data/spec/models/spree/gateway_spec.rb +0 -14
- data/spec/models/spree/image_spec.rb +0 -25
- data/spec/models/spree/inventory_unit_spec.rb +0 -309
- data/spec/models/spree/line_item_spec.rb +0 -240
- data/spec/models/spree/option_type_spec.rb +0 -16
- data/spec/models/spree/option_value_spec.rb +0 -52
- data/spec/models/spree/order/address_spec.rb +0 -52
- data/spec/models/spree/order/adjustments_spec.rb +0 -29
- data/spec/models/spree/order/callbacks_spec.rb +0 -44
- data/spec/models/spree/order/checkout_spec.rb +0 -740
- data/spec/models/spree/order/finalizing_spec.rb +0 -92
- data/spec/models/spree/order/number_generator_spec.rb +0 -47
- data/spec/models/spree/order/outstanding_balance_integration_spec.rb +0 -138
- data/spec/models/spree/order/payment_spec.rb +0 -280
- data/spec/models/spree/order/risk_assessment_spec.rb +0 -70
- data/spec/models/spree/order/state_machine_spec.rb +0 -122
- data/spec/models/spree/order/totals_spec.rb +0 -26
- data/spec/models/spree/order/validations_spec.rb +0 -17
- data/spec/models/spree/order_cancellations_spec.rb +0 -233
- data/spec/models/spree/order_capturing_spec.rb +0 -16
- data/spec/models/spree/order_contents_spec.rb +0 -362
- data/spec/models/spree/order_inventory_spec.rb +0 -285
- data/spec/models/spree/order_merger_spec.rb +0 -162
- data/spec/models/spree/order_mutex_spec.rb +0 -89
- data/spec/models/spree/order_promotion_spec.rb +0 -33
- data/spec/models/spree/order_shipping_spec.rb +0 -247
- data/spec/models/spree/order_spec.rb +0 -1687
- data/spec/models/spree/order_taxation_spec.rb +0 -128
- data/spec/models/spree/order_update_attributes_spec.rb +0 -49
- data/spec/models/spree/order_updater_spec.rb +0 -556
- data/spec/models/spree/payment/cancellation_spec.rb +0 -84
- data/spec/models/spree/payment_create_spec.rb +0 -195
- data/spec/models/spree/payment_method/bogus_credit_card_spec.rb +0 -10
- data/spec/models/spree/payment_method/check_spec.rb +0 -80
- data/spec/models/spree/payment_method/credit_card_spec.rb +0 -68
- data/spec/models/spree/payment_method/simple_bogus_credit_card_spec.rb +0 -20
- data/spec/models/spree/payment_method/store_credit_spec.rb +0 -325
- data/spec/models/spree/payment_method_spec.rb +0 -408
- data/spec/models/spree/payment_spec.rb +0 -1270
- data/spec/models/spree/permission_sets/base_spec.rb +0 -14
- data/spec/models/spree/permission_sets/configuration_display.rb +0 -79
- data/spec/models/spree/permission_sets/configuration_management_spec.rb +0 -49
- data/spec/models/spree/permission_sets/dashboard_display_spec.rb +0 -23
- data/spec/models/spree/permission_sets/order_display_spec.rb +0 -56
- data/spec/models/spree/permission_sets/order_management_spec.rb +0 -43
- data/spec/models/spree/permission_sets/product_display_spec.rb +0 -57
- data/spec/models/spree/permission_sets/product_management_spec.rb +0 -39
- data/spec/models/spree/permission_sets/promotion_display_spec.rb +0 -41
- data/spec/models/spree/permission_sets/promotion_management_spec.rb +0 -29
- data/spec/models/spree/permission_sets/restricted_stock_display_spec.rb +0 -42
- data/spec/models/spree/permission_sets/restricted_stock_management_spec.rb +0 -42
- data/spec/models/spree/permission_sets/stock_display_spec.rb +0 -25
- data/spec/models/spree/permission_sets/stock_management_spec.rb +0 -23
- data/spec/models/spree/permission_sets/user_display_spec.rb +0 -39
- data/spec/models/spree/permission_sets/user_management_spec.rb +0 -58
- data/spec/models/spree/preference_spec.rb +0 -79
- data/spec/models/spree/preferences/configuration_spec.rb +0 -27
- data/spec/models/spree/preferences/preferable_spec.rb +0 -334
- data/spec/models/spree/preferences/scoped_store_spec.rb +0 -62
- data/spec/models/spree/preferences/static_model_preferences_spec.rb +0 -79
- data/spec/models/spree/preferences/statically_configurable_spec.rb +0 -67
- data/spec/models/spree/preferences/store_spec.rb +0 -40
- data/spec/models/spree/price_spec.rb +0 -150
- data/spec/models/spree/product/scopes_spec.rb +0 -164
- data/spec/models/spree/product_duplicator_spec.rb +0 -92
- data/spec/models/spree/product_filter_spec.rb +0 -28
- data/spec/models/spree/product_property_spec.rb +0 -20
- data/spec/models/spree/product_spec.rb +0 -584
- data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +0 -126
- data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +0 -198
- data/spec/models/spree/promotion/actions/create_quantity_adjustments_spec.rb +0 -298
- data/spec/models/spree/promotion/actions/free_shipping_spec.rb +0 -61
- data/spec/models/spree/promotion/rules/first_order_spec.rb +0 -87
- data/spec/models/spree/promotion/rules/first_repeat_purchase_since_spec.rb +0 -71
- data/spec/models/spree/promotion/rules/item_total_spec.rb +0 -128
- data/spec/models/spree/promotion/rules/nth_order_spec.rb +0 -72
- data/spec/models/spree/promotion/rules/one_use_per_user_spec.rb +0 -54
- data/spec/models/spree/promotion/rules/option_value_spec.rb +0 -96
- data/spec/models/spree/promotion/rules/product_spec.rb +0 -193
- data/spec/models/spree/promotion/rules/store_spec.rb +0 -35
- data/spec/models/spree/promotion/rules/taxon_spec.rb +0 -227
- data/spec/models/spree/promotion/rules/user_logged_in_spec.rb +0 -33
- data/spec/models/spree/promotion/rules/user_role_spec.rb +0 -88
- data/spec/models/spree/promotion/rules/user_spec.rb +0 -39
- data/spec/models/spree/promotion_action_spec.rb +0 -44
- data/spec/models/spree/promotion_category_spec.rb +0 -19
- data/spec/models/spree/promotion_code/batch_builder_spec.rb +0 -107
- data/spec/models/spree/promotion_code_batch_spec.rb +0 -54
- data/spec/models/spree/promotion_code_spec.rb +0 -206
- data/spec/models/spree/promotion_handler/cart_spec.rb +0 -132
- data/spec/models/spree/promotion_handler/coupon_spec.rb +0 -419
- data/spec/models/spree/promotion_handler/page_spec.rb +0 -45
- data/spec/models/spree/promotion_handler/shipping_spec.rb +0 -96
- data/spec/models/spree/promotion_rule_spec.rb +0 -34
- data/spec/models/spree/promotion_spec.rb +0 -945
- data/spec/models/spree/refund_spec.rb +0 -200
- data/spec/models/spree/reimbursement/credit_spec.rb +0 -38
- data/spec/models/spree/reimbursement/reimbursement_type_engine_spec.rb +0 -144
- data/spec/models/spree/reimbursement/reimbursement_type_validator_spec.rb +0 -85
- data/spec/models/spree/reimbursement_performer_spec.rb +0 -33
- data/spec/models/spree/reimbursement_spec.rb +0 -278
- data/spec/models/spree/reimbursement_tax_calculator_spec.rb +0 -52
- data/spec/models/spree/reimbursement_type/credit_spec.rb +0 -56
- data/spec/models/spree/reimbursement_type/exchange_spec.rb +0 -48
- data/spec/models/spree/reimbursement_type/original_payment_spec.rb +0 -110
- data/spec/models/spree/reimbursement_type/store_credit_spec.rb +0 -111
- data/spec/models/spree/return_authorization_spec.rb +0 -226
- data/spec/models/spree/return_item/eligibility_validator/default_spec.rb +0 -79
- data/spec/models/spree/return_item/eligibility_validator/inventory_shipped_spec.rb +0 -59
- data/spec/models/spree/return_item/eligibility_validator/no_reimbursements_spec.rb +0 -86
- data/spec/models/spree/return_item/eligibility_validator/order_completed_spec.rb +0 -35
- data/spec/models/spree/return_item/eligibility_validator/rma_required_spec.rb +0 -31
- data/spec/models/spree/return_item/eligibility_validator/time_since_purchase_spec.rb +0 -42
- data/spec/models/spree/return_item/exchange_variant_eligibility/same_option_value_spec.rb +0 -66
- data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +0 -43
- data/spec/models/spree/return_item_spec.rb +0 -785
- data/spec/models/spree/returns_calculator_spec.rb +0 -16
- data/spec/models/spree/shipment_spec.rb +0 -914
- data/spec/models/spree/shipping_calculator_spec.rb +0 -45
- data/spec/models/spree/shipping_manifest_spec.rb +0 -110
- data/spec/models/spree/shipping_method_spec.rb +0 -292
- data/spec/models/spree/shipping_rate_spec.rb +0 -154
- data/spec/models/spree/shipping_rate_tax_spec.rb +0 -79
- data/spec/models/spree/state_spec.rb +0 -43
- data/spec/models/spree/stock/allocator/on_hand_first_spec.rb +0 -146
- data/spec/models/spree/stock/availability_spec.rb +0 -143
- data/spec/models/spree/stock/availability_validator_spec.rb +0 -140
- data/spec/models/spree/stock/content_item_spec.rb +0 -70
- data/spec/models/spree/stock/differentiator_spec.rb +0 -41
- data/spec/models/spree/stock/estimator_spec.rb +0 -241
- data/spec/models/spree/stock/inventory_unit_builder_spec.rb +0 -34
- data/spec/models/spree/stock/inventory_units_finalizer_spec.rb +0 -58
- data/spec/models/spree/stock/location_filter/active_spec.rb +0 -22
- data/spec/models/spree/stock/location_sorter/default_first_spec.rb +0 -22
- data/spec/models/spree/stock/location_sorter/unsorted_spec.rb +0 -21
- data/spec/models/spree/stock/package_spec.rb +0 -182
- data/spec/models/spree/stock/quantifier_spec.rb +0 -113
- data/spec/models/spree/stock/shipping_rate_selector_spec.rb +0 -18
- data/spec/models/spree/stock/shipping_rate_sorter_spec.rb +0 -18
- data/spec/models/spree/stock/simple_coordinator_spec.rb +0 -264
- data/spec/models/spree/stock/splitter/backordered_spec.rb +0 -31
- data/spec/models/spree/stock/splitter/base_spec.rb +0 -22
- data/spec/models/spree/stock/splitter/shipping_category_spec.rb +0 -48
- data/spec/models/spree/stock/splitter/weight_spec.rb +0 -31
- data/spec/models/spree/stock/splitter_chain_spec.rb +0 -66
- data/spec/models/spree/stock_item_spec.rb +0 -348
- data/spec/models/spree/stock_location_spec.rb +0 -288
- data/spec/models/spree/stock_movement_spec.rb +0 -58
- data/spec/models/spree/stock_quantities_spec.rb +0 -249
- data/spec/models/spree/store_credit_category_spec.rb +0 -19
- data/spec/models/spree/store_credit_event_spec.rb +0 -328
- data/spec/models/spree/store_credit_spec.rb +0 -900
- data/spec/models/spree/store_selector/by_server_name_spec.rb +0 -28
- data/spec/models/spree/store_selector/legacy_spec.rb +0 -46
- data/spec/models/spree/store_spec.rb +0 -156
- data/spec/models/spree/tax/order_adjuster_spec.rb +0 -35
- data/spec/models/spree/tax/shipping_rate_taxer_spec.rb +0 -59
- data/spec/models/spree/tax/tax_location_spec.rb +0 -79
- data/spec/models/spree/tax/taxation_integration_spec.rb +0 -815
- data/spec/models/spree/tax_calculator/default_spec.rb +0 -56
- data/spec/models/spree/tax_category_spec.rb +0 -50
- data/spec/models/spree/tax_rate_spec.rb +0 -317
- data/spec/models/spree/taxon_spec.rb +0 -197
- data/spec/models/spree/taxonomy_spec.rb +0 -15
- data/spec/models/spree/taxons/paperclip_attachment_spec.rb +0 -29
- data/spec/models/spree/unit_cancel_spec.rb +0 -126
- data/spec/models/spree/user_last_url_storer/rules/authentication_rule_spec.rb +0 -31
- data/spec/models/spree/user_last_url_storer_spec.rb +0 -60
- data/spec/models/spree/user_spec.rb +0 -247
- data/spec/models/spree/validations/db_maximum_length_validator_spec.rb +0 -33
- data/spec/models/spree/variant/price_selector_spec.rb +0 -90
- data/spec/models/spree/variant/pricing_options_spec.rb +0 -204
- data/spec/models/spree/variant/scopes_spec.rb +0 -94
- data/spec/models/spree/variant/vat_price_generator_spec.rb +0 -77
- data/spec/models/spree/variant_property_rule_condition_spec.rb +0 -17
- data/spec/models/spree/variant_property_rule_spec.rb +0 -85
- data/spec/models/spree/variant_property_rule_value_spec.rb +0 -20
- data/spec/models/spree/variant_spec.rb +0 -862
- data/spec/models/spree/wallet_payment_source_spec.rb +0 -77
- data/spec/models/spree/wallet_spec.rb +0 -155
- data/spec/models/spree/zone_spec.rb +0 -248
- data/spec/rails_helper.rb +0 -46
- data/spec/shared_examples/calculator_shared_examples.rb +0 -10
- data/spec/spec_helper.rb +0 -36
- data/spec/support/big_decimal.rb +0 -7
- data/spec/support/concerns/default_price.rb +0 -44
- data/spec/support/concerns/payment_source.rb +0 -66
- data/spec/support/concerns/working_factories.rb +0 -15
- data/spec/support/dummy_ability.rb +0 -7
- /data/lib/generators/{spree → solidus}/install/templates/vendor/assets/javascripts/spree/backend/all.js +0 -0
- /data/lib/generators/{spree → solidus}/install/templates/vendor/assets/javascripts/spree/frontend/all.js +0 -0
- /data/lib/generators/{spree → solidus}/install/templates/vendor/assets/stylesheets/spree/backend/all.css +0 -0
- /data/lib/generators/{spree → solidus}/install/templates/vendor/assets/stylesheets/spree/frontend/all.css +0 -0
- /data/{app/models → lib}/spree/user_class_handle.rb +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'spree/preferences/persistable'
|
4
4
|
require 'spree/preferences/statically_configurable'
|
5
5
|
|
6
6
|
module Spree
|
@@ -12,26 +12,15 @@ module Spree
|
|
12
12
|
# This class is not meant to be instantiated. Please create instances of concrete payment methods.
|
13
13
|
#
|
14
14
|
class PaymentMethod < Spree::Base
|
15
|
+
include Spree::Preferences::Persistable
|
16
|
+
|
15
17
|
preference :server, :string, default: 'test'
|
16
18
|
preference :test_mode, :boolean, default: true
|
17
19
|
|
18
|
-
|
19
|
-
include Spree::ParanoiaDeprecations
|
20
|
-
|
21
|
-
include Discard::Model
|
22
|
-
self.discard_column = :deleted_at
|
20
|
+
include Spree::SoftDeletable
|
23
21
|
|
24
22
|
acts_as_list
|
25
23
|
|
26
|
-
# @private
|
27
|
-
def self.const_missing(name)
|
28
|
-
if name == :DISPLAY
|
29
|
-
const_set(:DISPLAY, [:both, :front_end, :back_end])
|
30
|
-
else
|
31
|
-
super
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
24
|
validates :name, :type, presence: true
|
36
25
|
|
37
26
|
has_many :payments, class_name: "Spree::Payment", inverse_of: :payment_method
|
@@ -63,56 +52,14 @@ module Spree
|
|
63
52
|
@human
|
64
53
|
].compact
|
65
54
|
options = { scope: [:activerecord, :models], count: 1, default: defaults }.merge!(options.except(:default))
|
66
|
-
I18n.translate(defaults.shift, options)
|
55
|
+
I18n.translate(defaults.shift, **options)
|
67
56
|
end
|
68
57
|
end
|
69
58
|
|
70
59
|
class << self
|
71
|
-
# @deprecated Use Spree::Config.environment.payment_methods instead
|
72
|
-
def providers
|
73
|
-
Spree::Deprecation.warn 'Spree::PaymentMethod.providers is deprecated and will be deleted in Solidus 3.0. ' \
|
74
|
-
'Please use Rails.application.config.spree.payment_methods instead'
|
75
|
-
Spree::Config.environment.payment_methods
|
76
|
-
end
|
77
|
-
|
78
|
-
# @deprecated Use {.active}, {.available_to_users}, and {.available_to_admin} scopes instead.
|
79
|
-
def available(display_on = nil, store: nil)
|
80
|
-
Spree::Deprecation.warn "Spree::PaymentMethod.available is deprecated."\
|
81
|
-
"Please use .active, .available_to_users, and .available_to_admin scopes instead."\
|
82
|
-
"For payment methods associated with a specific store, use Spree::PaymentMethod.available_to_store(your_store)"\
|
83
|
-
" as the base applying any further filtering"
|
84
|
-
|
85
|
-
display_on = display_on.to_s
|
86
|
-
|
87
|
-
available_payment_methods =
|
88
|
-
case display_on
|
89
|
-
when 'front_end'
|
90
|
-
active.available_to_users
|
91
|
-
when 'back_end'
|
92
|
-
active.available_to_admin
|
93
|
-
else
|
94
|
-
active.available_to_users.available_to_admin
|
95
|
-
end
|
96
|
-
available_payment_methods.select do |payment|
|
97
|
-
store.nil? || store.payment_methods.empty? || store.payment_methods.include?(payment)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
60
|
def model_name
|
102
61
|
ModelName.new(self, Spree)
|
103
62
|
end
|
104
|
-
|
105
|
-
# @deprecated Use .active.any? instead
|
106
|
-
def active?
|
107
|
-
Spree::Deprecation.warn "#{self}.active? is deprecated. Use #{self}.active.any? instead"
|
108
|
-
where(type: to_s, active: true).count > 0
|
109
|
-
end
|
110
|
-
|
111
|
-
# @deprecated Use .with_deleted.find instead
|
112
|
-
def find_with_destroyed(*args)
|
113
|
-
Spree::Deprecation.warn "#{self}.find_with_destroyed is deprecated. Use #{self}.with_deleted.find instead"
|
114
|
-
unscoped { find(*args) }
|
115
|
-
end
|
116
63
|
end
|
117
64
|
|
118
65
|
# Represents the gateway of this payment method
|
@@ -139,8 +86,6 @@ module Spree
|
|
139
86
|
|
140
87
|
@gateway ||= gateway_class.new(gateway_options)
|
141
88
|
end
|
142
|
-
alias_method :provider, :gateway
|
143
|
-
deprecate provider: :gateway, deprecator: Spree::Deprecation
|
144
89
|
|
145
90
|
# Represents all preferences as a Hash
|
146
91
|
#
|
@@ -160,29 +105,6 @@ module Spree
|
|
160
105
|
raise ::NotImplementedError, "You must implement payment_source_class method for #{self.class}."
|
161
106
|
end
|
162
107
|
|
163
|
-
# @deprecated Use {Spree::PaymentMethod#available_to_users=} and {Spree::PaymentMethod#available_to_admin=} instead
|
164
|
-
def display_on=(value)
|
165
|
-
Spree::Deprecation.warn "Spree::PaymentMethod#display_on= is deprecated."\
|
166
|
-
"Please use #available_to_users= and #available_to_admin= instead."
|
167
|
-
self.available_to_users = value.blank? || value == 'front_end'
|
168
|
-
self.available_to_admin = value.blank? || value == 'back_end'
|
169
|
-
end
|
170
|
-
|
171
|
-
# @deprecated Use {Spree::PaymentMethod#available_to_users} and {Spree::PaymentMethod#available_to_admin} instead
|
172
|
-
def display_on
|
173
|
-
Spree::Deprecation.warn "Spree::PaymentMethod#display_on is deprecated."\
|
174
|
-
"Please use #available_to_users and #available_to_admin instead."
|
175
|
-
if available_to_users? && available_to_admin?
|
176
|
-
''
|
177
|
-
elsif available_to_users?
|
178
|
-
'front_end'
|
179
|
-
elsif available_to_admin?
|
180
|
-
'back_end'
|
181
|
-
else
|
182
|
-
'none'
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
108
|
# Used as partial name for your payment method
|
187
109
|
#
|
188
110
|
# Currently your payment method needs to provide these partials:
|
@@ -203,21 +125,7 @@ module Spree
|
|
203
125
|
# The view that represents your payment method on orders through the api
|
204
126
|
#
|
205
127
|
def partial_name
|
206
|
-
|
207
|
-
end
|
208
|
-
|
209
|
-
# :nodoc:
|
210
|
-
# If method_type has been overridden, call it and return the value, otherwise return nil
|
211
|
-
def deprecated_method_type_override
|
212
|
-
if method(:method_type).owner != Spree::PaymentMethod
|
213
|
-
Spree::Deprecation.warn "#{method(:method_type).owner} is overriding PaymentMethod#method_type. This is deprecated and will be removed from Solidus 3.0 (override partial_name instead).", caller[1..-1]
|
214
|
-
method_type
|
215
|
-
end
|
216
|
-
end
|
217
|
-
|
218
|
-
def method_type
|
219
|
-
Spree::Deprecation.warn "method_type is deprecated and will be removed from Solidus 3.0 (use partial_name instead)", caller
|
220
|
-
partial_name
|
128
|
+
type.demodulize.underscore
|
221
129
|
end
|
222
130
|
|
223
131
|
def payment_profiles_supported?
|
@@ -275,14 +183,7 @@ module Spree
|
|
275
183
|
# Represents the gateway class of this payment method
|
276
184
|
#
|
277
185
|
def gateway_class
|
278
|
-
|
279
|
-
Spree::Deprecation.warn \
|
280
|
-
"provider_class is deprecated and will be removed from Solidus 3.0 " \
|
281
|
-
"(use gateway_class instead)"
|
282
|
-
public_send :provider_class
|
283
|
-
else
|
284
|
-
raise ::NotImplementedError, "You must implement gateway_class method for #{self.class}."
|
285
|
-
end
|
186
|
+
raise ::NotImplementedError, "You must implement gateway_class method for #{self.class}."
|
286
187
|
end
|
287
188
|
end
|
288
189
|
end
|
@@ -23,9 +23,9 @@ module Spree
|
|
23
23
|
end
|
24
24
|
|
25
25
|
# @param payment [Spree::Payment] the payment we want to know if can be voided
|
26
|
-
# @return [Boolean] true when the payment is not failed or
|
26
|
+
# @return [Boolean] true when the payment is not failed, voided or invalid
|
27
27
|
def can_void?(payment)
|
28
|
-
|
28
|
+
payment.can_void?
|
29
29
|
end
|
30
30
|
|
31
31
|
# Indicates whether its possible to credit the payment. Note that most
|
data/app/models/spree/price.rb
CHANGED
@@ -1,18 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'discard'
|
4
|
-
|
5
3
|
module Spree
|
6
4
|
class Price < Spree::Base
|
7
|
-
|
8
|
-
include Spree::ParanoiaDeprecations
|
9
|
-
|
10
|
-
include Discard::Model
|
11
|
-
self.discard_column = :deleted_at
|
5
|
+
include Spree::SoftDeletable
|
12
6
|
|
13
7
|
MAXIMUM_AMOUNT = BigDecimal('99_999_999.99')
|
14
8
|
|
15
|
-
belongs_to :variant, -> {
|
9
|
+
belongs_to :variant, -> { with_discarded }, class_name: 'Spree::Variant', touch: true, optional: true
|
16
10
|
belongs_to :country, class_name: "Spree::Country", foreign_key: "country_iso", primary_key: "iso", optional: true
|
17
11
|
|
18
12
|
delegate :product, to: :variant
|
@@ -61,7 +55,7 @@ module Spree
|
|
61
55
|
|
62
56
|
def display_country
|
63
57
|
if country_iso
|
64
|
-
"#{country_iso} (#{
|
58
|
+
"#{country_iso} (#{I18n.t(country_iso, scope: [:spree, :country_names])})"
|
65
59
|
else
|
66
60
|
I18n.t(:any_country, scope: [:spree, :admin, :prices])
|
67
61
|
end
|
@@ -29,11 +29,13 @@ 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: :default_price).
|
32
|
+
joins(master: :default_price).select('spree_products.* , spree_prices.amount')
|
33
|
+
.order(Spree::Price.arel_table[:amount].asc)
|
33
34
|
end
|
34
35
|
|
35
36
|
add_search_scope :descend_by_master_price do
|
36
|
-
joins(master: :default_price).
|
37
|
+
joins(master: :default_price).select('spree_products.* , spree_prices.amount')
|
38
|
+
.order(Spree::Price.arel_table[:amount].desc)
|
37
39
|
end
|
38
40
|
|
39
41
|
add_search_scope :price_between do |low, high|
|
@@ -68,7 +70,6 @@ module Spree
|
|
68
70
|
add_search_scope :in_taxon do |taxon|
|
69
71
|
includes(:classifications)
|
70
72
|
.where('spree_products_taxons.taxon_id' => taxon.self_and_descendants.pluck(:id))
|
71
|
-
.select(Spree::Classification.arel_table[:position])
|
72
73
|
.order(Spree::Classification.arel_table[:position].asc)
|
73
74
|
end
|
74
75
|
|
@@ -182,7 +183,10 @@ module Spree
|
|
182
183
|
end
|
183
184
|
# Can't use add_search_scope for this as it needs a default argument
|
184
185
|
def self.available(available_on = nil)
|
185
|
-
with_master_price
|
186
|
+
with_master_price
|
187
|
+
.where("#{Spree::Product.quoted_table_name}.available_on <= ?", available_on || Time.current)
|
188
|
+
.where("#{Spree::Product.quoted_table_name}.discontinue_on IS NULL OR" \
|
189
|
+
"#{Spree::Product.quoted_table_name}.discontinue_on >= ?", Time.current)
|
186
190
|
end
|
187
191
|
search_scopes << :available
|
188
192
|
|
@@ -197,33 +201,6 @@ module Spree
|
|
197
201
|
where(subquery.arel.exists)
|
198
202
|
end
|
199
203
|
|
200
|
-
def self.distinct_by_product_ids(sort_order = nil)
|
201
|
-
Spree::Deprecation.warn "Product.distinct_by_product_ids is deprecated and should not be used"
|
202
|
-
|
203
|
-
sort_column = sort_order.split(" ").first
|
204
|
-
|
205
|
-
# Postgres will complain when using ordering by expressions not present in
|
206
|
-
# SELECT DISTINCT. e.g.
|
207
|
-
#
|
208
|
-
# PG::InvalidColumnReference: ERROR: for SELECT DISTINCT, ORDER BY
|
209
|
-
# expressions must appear in select list. e.g.
|
210
|
-
#
|
211
|
-
# SELECT DISTINCT "spree_products".* FROM "spree_products" LEFT OUTER JOIN
|
212
|
-
# "spree_variants" ON "spree_variants"."product_id" = "spree_products"."id" AND "spree_variants"."is_master" = 't'
|
213
|
-
# AND "spree_variants"."deleted_at" IS NULL LEFT OUTER JOIN "spree_prices" ON
|
214
|
-
# "spree_prices"."variant_id" = "spree_variants"."id" AND "spree_prices"."currency" = 'USD'
|
215
|
-
# AND "spree_prices"."deleted_at" IS NULL WHERE "spree_products"."deleted_at" IS NULL AND ('t'='t')
|
216
|
-
# ORDER BY "spree_prices"."amount" ASC LIMIT 10 OFFSET 0
|
217
|
-
#
|
218
|
-
# Don't allow sort_column, a variable coming from params,
|
219
|
-
# to be anything but a column in the database
|
220
|
-
if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL' && !column_names.include?(sort_column)
|
221
|
-
all
|
222
|
-
else
|
223
|
-
distinct
|
224
|
-
end
|
225
|
-
end
|
226
|
-
|
227
204
|
class << self
|
228
205
|
private
|
229
206
|
|
@@ -233,7 +210,7 @@ module Spree
|
|
233
210
|
|
234
211
|
# specifically avoid having an order for taxon search (conflicts with main order)
|
235
212
|
def prepare_taxon_conditions(taxons)
|
236
|
-
ids = taxons.
|
213
|
+
ids = taxons.flat_map { |taxon| taxon.self_and_descendants.pluck(:id) }.uniq
|
237
214
|
joins(:taxons).where("#{Spree::Taxon.table_name}.id" => ids)
|
238
215
|
end
|
239
216
|
|
data/app/models/spree/product.rb
CHANGED
@@ -1,25 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'discard'
|
4
|
-
|
5
3
|
module Spree
|
6
4
|
# Products represent an entity for sale in a store. Products can have
|
7
5
|
# variations, called variants. Product properties include description,
|
8
6
|
# permalink, availability, shipping category, etc. that do not change by
|
9
7
|
# variant.
|
10
|
-
#
|
11
|
-
# @note this model uses {https://github.com/radar/paranoia paranoia}.
|
12
|
-
# +#destroy+ will only soft-destroy records and the default scope hides
|
13
|
-
# soft-destroyed records using +WHERE deleted_at IS NULL+.
|
14
8
|
class Product < Spree::Base
|
15
9
|
extend FriendlyId
|
16
10
|
friendly_id :slug_candidates, use: :history
|
17
11
|
|
18
|
-
|
19
|
-
include Spree::ParanoiaDeprecations
|
20
|
-
|
21
|
-
include Discard::Model
|
22
|
-
self.discard_column = :deleted_at
|
12
|
+
include Spree::SoftDeletable
|
23
13
|
|
24
14
|
after_discard do
|
25
15
|
variants_including_master.discard_all
|
@@ -48,7 +38,7 @@ module Spree
|
|
48
38
|
belongs_to :shipping_category, class_name: 'Spree::ShippingCategory', inverse_of: :products, optional: true
|
49
39
|
|
50
40
|
has_one :master,
|
51
|
-
-> { where(is_master: true).
|
41
|
+
-> { where(is_master: true).with_discarded },
|
52
42
|
inverse_of: :product,
|
53
43
|
class_name: 'Spree::Variant',
|
54
44
|
autosave: true
|
@@ -95,7 +85,6 @@ module Spree
|
|
95
85
|
:has_default_price?,
|
96
86
|
:images,
|
97
87
|
:price_for,
|
98
|
-
:price_in,
|
99
88
|
:rebuild_vat_prices=,
|
100
89
|
to: :find_or_build_master
|
101
90
|
|
@@ -121,7 +110,7 @@ module Spree
|
|
121
110
|
validates :name, presence: true
|
122
111
|
validates :price, presence: true, if: proc { Spree::Config[:require_master_price] }
|
123
112
|
validates :shipping_category_id, presence: true
|
124
|
-
validates :slug, presence: true, uniqueness: { allow_blank: true }
|
113
|
+
validates :slug, presence: true, uniqueness: { allow_blank: true, case_sensitive: true }
|
125
114
|
|
126
115
|
attr_accessor :option_values_hash
|
127
116
|
|
@@ -134,7 +123,7 @@ module Spree
|
|
134
123
|
self.whitelisted_ransackable_attributes = %w[name slug]
|
135
124
|
|
136
125
|
def self.ransackable_scopes(_auth_object = nil)
|
137
|
-
%i(
|
126
|
+
%i(with_discarded with_variant_sku_cont)
|
138
127
|
end
|
139
128
|
|
140
129
|
# @return [Boolean] true if there are any variants
|
@@ -174,25 +163,23 @@ module Spree
|
|
174
163
|
end
|
175
164
|
|
176
165
|
# Determines if product is available. A product is available if it has not
|
177
|
-
# been deleted
|
166
|
+
# been deleted, the available_on date is in the past
|
167
|
+
# and the discontinue_on date is nil or in the future.
|
178
168
|
#
|
179
169
|
# @return [Boolean] true if this product is available
|
180
170
|
def available?
|
181
|
-
!
|
171
|
+
!deleted? && available_on&.past? && !discontinued?
|
182
172
|
end
|
183
173
|
|
184
|
-
#
|
174
|
+
# Determines if product is discontinued.
|
185
175
|
#
|
186
|
-
#
|
187
|
-
#
|
188
|
-
#
|
189
|
-
#
|
190
|
-
|
191
|
-
|
192
|
-
return {} unless option_types.include?(opt_type)
|
193
|
-
variants.with_prices(pricing_options).group_by { |variant| variant.option_values.detect { |option| option.option_type == opt_type } }
|
176
|
+
# A product is discontinued if the discontinue_on date
|
177
|
+
# is not nil and in the past.
|
178
|
+
#
|
179
|
+
# @return [Boolean] true if this product is discontinued
|
180
|
+
def discontinued?
|
181
|
+
!!discontinue_on&.past?
|
194
182
|
end
|
195
|
-
deprecate :categorise_variants_from_option, deprecator: Spree::Deprecation
|
196
183
|
|
197
184
|
# Poor man's full text search.
|
198
185
|
#
|
@@ -209,17 +196,6 @@ module Spree
|
|
209
196
|
where conditions.inject(:or)
|
210
197
|
end
|
211
198
|
|
212
|
-
# @param current_currency [String] currency to filter variants by; defaults to Spree's default
|
213
|
-
# @deprecated This method can only handle prices for currencies
|
214
|
-
# @return [Array<Spree::Variant>] all variants with at least one option value
|
215
|
-
def variants_and_option_values(current_currency = nil)
|
216
|
-
variants.includes(:option_values).active(current_currency).select do |variant|
|
217
|
-
variant.option_values.any?
|
218
|
-
end
|
219
|
-
end
|
220
|
-
deprecate variants_and_option_values: :variants_and_option_values_for,
|
221
|
-
deprecator: Spree::Deprecation
|
222
|
-
|
223
199
|
# @param pricing_options [Spree::Variant::PricingOptions] the pricing options to search
|
224
200
|
# for, default: the default pricing options
|
225
201
|
# @return [Array<Spree::Variant>] all variants with at least one option value
|
@@ -291,16 +267,6 @@ module Spree
|
|
291
267
|
end
|
292
268
|
end
|
293
269
|
|
294
|
-
# Image that can be used for the product.
|
295
|
-
#
|
296
|
-
# Will first search for images on the product, then those belonging to the
|
297
|
-
# variants. If all else fails, will return a new image object.
|
298
|
-
# @return [Spree::Image] the image to display
|
299
|
-
def display_image
|
300
|
-
Spree::Deprecation.warn('Spree::Product#display_image is DEPRECATED. Choose an image from Spree::Product#gallery instead.')
|
301
|
-
images.first || variant_images.first || Spree::Image.new
|
302
|
-
end
|
303
|
-
|
304
270
|
# Finds the variant property rule that matches the provided option value ids.
|
305
271
|
#
|
306
272
|
# @param option_value_ids [Array<Integer>] list of option value ids
|
@@ -361,8 +327,14 @@ module Spree
|
|
361
327
|
# If the master is invalid, the Product object will be assigned its errors
|
362
328
|
def validate_master
|
363
329
|
unless master.valid?
|
364
|
-
|
365
|
-
errors.
|
330
|
+
if Gem::Requirement.new(">= 6.1").satisfied_by?(Rails.gem_version)
|
331
|
+
master.errors.each do |error|
|
332
|
+
errors.add(error.attribute, error.message)
|
333
|
+
end
|
334
|
+
else
|
335
|
+
master.errors.each do |att, error|
|
336
|
+
errors.add(att, error)
|
337
|
+
end
|
366
338
|
end
|
367
339
|
end
|
368
340
|
end
|
@@ -381,11 +353,11 @@ module Spree
|
|
381
353
|
|
382
354
|
# Iterate through this product's taxons and taxonomies and touch their timestamps in a batch
|
383
355
|
def touch_taxons
|
384
|
-
taxons_to_touch = taxons.
|
356
|
+
taxons_to_touch = taxons.flat_map(&:self_and_ancestors).uniq
|
385
357
|
unless taxons_to_touch.empty?
|
386
358
|
Spree::Taxon.where(id: taxons_to_touch.map(&:id)).update_all(updated_at: Time.current)
|
387
359
|
|
388
|
-
taxonomy_ids_to_touch = taxons_to_touch.
|
360
|
+
taxonomy_ids_to_touch = taxons_to_touch.flat_map(&:taxonomy_id).uniq
|
389
361
|
Spree::Taxonomy.where(id: taxonomy_ids_to_touch).update_all(updated_at: Time.current)
|
390
362
|
end
|
391
363
|
end
|
@@ -39,9 +39,6 @@ module Spree
|
|
39
39
|
# item_total and ship_total
|
40
40
|
def compute_amount(calculable)
|
41
41
|
amount = calculator.compute(calculable)
|
42
|
-
if !amount.is_a?(BigDecimal)
|
43
|
-
Spree::Deprecation.warn "#{calculator.class.name}#compute returned #{amount.inspect}, it should return a BigDecimal"
|
44
|
-
end
|
45
42
|
amount ||= BigDecimal(0)
|
46
43
|
amount = amount.abs
|
47
44
|
[(calculable.item_total + calculable.ship_total), amount].min * -1
|
@@ -33,9 +33,6 @@ module Spree
|
|
33
33
|
order = adjustable.is_a?(Order) ? adjustable : adjustable.order
|
34
34
|
return 0 unless promotion.line_item_actionable?(order, adjustable)
|
35
35
|
promotion_amount = calculator.compute(adjustable)
|
36
|
-
if !promotion_amount.is_a?(BigDecimal)
|
37
|
-
Spree::Deprecation.warn "#{calculator.class.name}#compute returned #{promotion_amount.inspect}, it should return a BigDecimal"
|
38
|
-
end
|
39
36
|
promotion_amount ||= BigDecimal(0)
|
40
37
|
promotion_amount = promotion_amount.abs
|
41
38
|
[adjustable.amount, promotion_amount].min * -1
|
@@ -57,9 +57,6 @@ module Spree
|
|
57
57
|
#
|
58
58
|
def compute_amount(line_item)
|
59
59
|
adjustment_amount = calculator.compute(PartialLineItem.new(line_item))
|
60
|
-
if !adjustment_amount.is_a?(BigDecimal)
|
61
|
-
Spree::Deprecation.warn "#{calculator.class.name}#compute returned #{adjustment_amount.inspect}, it should return a BigDecimal"
|
62
|
-
end
|
63
60
|
adjustment_amount ||= BigDecimal(0)
|
64
61
|
adjustment_amount = adjustment_amount.abs
|
65
62
|
|
@@ -8,8 +8,9 @@ module Spree
|
|
8
8
|
order = payload[:order]
|
9
9
|
promotion_code = payload[:promotion_code]
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
created_adjustments = order.shipments.map do |shipment|
|
12
|
+
next if promotion_credit_exists?(shipment)
|
13
|
+
|
13
14
|
shipment.adjustments.create!(
|
14
15
|
order: shipment.order,
|
15
16
|
amount: compute_amount(shipment),
|
@@ -17,11 +18,11 @@ module Spree
|
|
17
18
|
promotion_code: promotion_code,
|
18
19
|
label: label
|
19
20
|
)
|
20
|
-
true
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
|
+
# Did we actually end up creating any adjustments?
|
23
24
|
# If so, then this action should be classed as 'successful'
|
24
|
-
|
25
|
+
created_adjustments.any?
|
25
26
|
end
|
26
27
|
|
27
28
|
def label
|
@@ -38,11 +38,7 @@ module Spree
|
|
38
38
|
eligibility_errors.add(:base, eligibility_error_message(:has_excluded_taxon), error_code: :has_excluded_taxon)
|
39
39
|
end
|
40
40
|
else
|
41
|
-
|
42
|
-
warn_invalid_match_policy(assume: 'any')
|
43
|
-
unless order_taxons.where(id: rule_taxon_ids_with_children).exists?
|
44
|
-
eligibility_errors.add(:base, eligibility_error_message(:no_matching_taxons), error_code: :no_matching_taxons)
|
45
|
-
end
|
41
|
+
raise "unexpected match policy: #{preferred_match_policy.inspect}"
|
46
42
|
end
|
47
43
|
|
48
44
|
eligibility_errors.empty?
|
@@ -60,9 +56,7 @@ module Spree
|
|
60
56
|
when 'none'
|
61
57
|
!found
|
62
58
|
else
|
63
|
-
|
64
|
-
warn_invalid_match_policy(assume: 'any')
|
65
|
-
found
|
59
|
+
raise "unexpected match policy: #{preferred_match_policy.inspect}"
|
66
60
|
end
|
67
61
|
end
|
68
62
|
|
@@ -77,13 +71,6 @@ module Spree
|
|
77
71
|
|
78
72
|
private
|
79
73
|
|
80
|
-
def warn_invalid_match_policy(assume:)
|
81
|
-
Spree::Deprecation.warn(
|
82
|
-
"#{self.class.name} id=#{id} has unexpected match policy #{preferred_match_policy.inspect}. "\
|
83
|
-
"Interpreting it as '#{assume}'."
|
84
|
-
)
|
85
|
-
end
|
86
|
-
|
87
74
|
# All taxons in an order
|
88
75
|
def taxons_in_order(order)
|
89
76
|
Spree::Taxon.joins(products: { variants_including_master: :line_items })
|
@@ -28,26 +28,34 @@ module Spree
|
|
28
28
|
validates_associated :rules
|
29
29
|
|
30
30
|
validates :name, presence: true
|
31
|
-
validates :path, uniqueness: { allow_blank: true }
|
31
|
+
validates :path, uniqueness: { allow_blank: true, case_sensitive: true }
|
32
32
|
validates :usage_limit, numericality: { greater_than: 0, allow_nil: true }
|
33
33
|
validates :per_code_usage_limit, numericality: { greater_than_or_equal_to: 0, allow_nil: true }
|
34
34
|
validates :description, length: { maximum: 255 }
|
35
|
-
validate :
|
35
|
+
validate :apply_automatically_disallowed_with_paths
|
36
36
|
|
37
37
|
before_save :normalize_blank_values
|
38
38
|
|
39
39
|
scope :coupons, -> { joins(:codes).distinct }
|
40
40
|
scope :advertised, -> { where(advertise: true) }
|
41
|
-
scope :active, ->
|
41
|
+
scope :active, -> { has_actions.started_and_unexpired }
|
42
|
+
scope :started_and_unexpired, -> do
|
42
43
|
table = arel_table
|
43
44
|
time = Time.current
|
45
|
+
|
44
46
|
where(table[:starts_at].eq(nil).or(table[:starts_at].lt(time))).
|
45
47
|
where(table[:expires_at].eq(nil).or(table[:expires_at].gt(time)))
|
46
48
|
end
|
49
|
+
scope :has_actions, -> do
|
50
|
+
joins(:promotion_actions)
|
51
|
+
end
|
47
52
|
scope :applied, -> { joins(:order_promotions).distinct }
|
48
53
|
|
49
54
|
self.whitelisted_ransackable_associations = ['codes']
|
50
55
|
self.whitelisted_ransackable_attributes = %w[name path promotion_category_id]
|
56
|
+
def self.ransackable_scopes(*)
|
57
|
+
%i(active)
|
58
|
+
end
|
51
59
|
|
52
60
|
def self.order_activatable?(order)
|
53
61
|
order && !UNACTIVATABLE_ORDER_STATES.include?(order.state)
|
@@ -81,7 +89,7 @@ module Spree
|
|
81
89
|
end
|
82
90
|
|
83
91
|
def active?
|
84
|
-
started? && not_expired?
|
92
|
+
started? && not_expired? && actions.present?
|
85
93
|
end
|
86
94
|
|
87
95
|
def inactive?
|
@@ -164,10 +172,10 @@ module Spree
|
|
164
172
|
end
|
165
173
|
|
166
174
|
def products
|
167
|
-
rules.where(type: "Spree::Promotion::Rules::Product").
|
175
|
+
rules.where(type: "Spree::Promotion::Rules::Product").flat_map(&:products).uniq
|
168
176
|
end
|
169
177
|
|
170
|
-
# Whether the promotion has exceeded
|
178
|
+
# Whether the promotion has exceeded its usage restrictions.
|
171
179
|
#
|
172
180
|
# @param excluded_orders [Array<Spree::Order>] Orders to exclude from usage limit
|
173
181
|
# @return true or false
|
@@ -257,10 +265,9 @@ module Spree
|
|
257
265
|
match_policy == "all"
|
258
266
|
end
|
259
267
|
|
260
|
-
def
|
268
|
+
def apply_automatically_disallowed_with_paths
|
261
269
|
return unless apply_automatically
|
262
270
|
|
263
|
-
errors.add(:apply_automatically, :disallowed_with_code) if codes.any?
|
264
271
|
errors.add(:apply_automatically, :disallowed_with_path) if path.present?
|
265
272
|
end
|
266
273
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'spree/preferences/persistable'
|
4
4
|
|
5
5
|
module Spree
|
6
6
|
# Base class for all types of promotion action.
|
@@ -8,11 +8,8 @@ module Spree
|
|
8
8
|
# PromotionActions perform the necessary tasks when a promotion is activated
|
9
9
|
# by an event and determined to be eligible.
|
10
10
|
class PromotionAction < Spree::Base
|
11
|
-
|
12
|
-
include Spree::
|
13
|
-
|
14
|
-
include Discard::Model
|
15
|
-
self.discard_column = :deleted_at
|
11
|
+
include Spree::Preferences::Persistable
|
12
|
+
include Spree::SoftDeletable
|
16
13
|
|
17
14
|
belongs_to :promotion, class_name: 'Spree::Promotion', inverse_of: :promotion_actions, optional: true
|
18
15
|
|
@@ -35,15 +32,8 @@ module Spree
|
|
35
32
|
#
|
36
33
|
# @param order [Spree::Order] the order to remove the action from
|
37
34
|
# @return [void]
|
38
|
-
def remove_from(
|
39
|
-
|
40
|
-
[order, *order.line_items, *order.shipments].each do |item|
|
41
|
-
item.adjustments.each do |adjustment|
|
42
|
-
if adjustment.source == self
|
43
|
-
item.adjustments.destroy(adjustment)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
35
|
+
def remove_from(_order)
|
36
|
+
raise 'remove_from should be implemented in a sub-class of PromotionAction'
|
47
37
|
end
|
48
38
|
|
49
39
|
def to_partial_path
|