Module: Spree

Extended by:
ActionView::Helpers::TagHelper, ActionView::Helpers::TranslationHelper
Defined in:
app/models/spree/product.rb,
lib/spree/core.rb,
lib/spree/i18n.rb,
lib/spree/money.rb,
lib/spree/i18n/base.rb,
lib/spree/migrations.rb,
app/models/spree/role.rb,
app/models/spree/zone.rb,
lib/spree/core/engine.rb,
lib/spree/core/routes.rb,
app/models/spree/asset.rb,
app/models/spree/image.rb,
app/models/spree/order.rb,
app/models/spree/price.rb,
app/models/spree/state.rb,
app/models/spree/store.rb,
app/models/spree/taxon.rb,
lib/spree/core/version.rb,
app/models/spree/refund.rb,
lib/spree/core/importer.rb,
app/models/spree/ability.rb,
app/models/spree/address.rb,
app/models/spree/country.rb,
app/models/spree/gateway.rb,
app/models/spree/payment.rb,
app/models/spree/variant.rb,
lib/spree/service_module.rb,
app/models/spree/exchange.rb,
app/models/spree/property.rb,
app/models/spree/shipment.rb,
app/models/spree/tax_rate.rb,
app/models/spree/taxonomy.rb,
lib/spree/core/components.rb,
app/models/spree/line_item.rb,
app/models/spree/log_entry.rb,
app/models/spree/promotion.rb,
app/models/spree/prototype.rb,
app/models/spree/role_user.rb,
lib/spree/core/search/base.rb,
lib/spree/localized_number.rb,
app/models/spree/adjustment.rb,
app/models/spree/calculator.rb,
app/models/spree/stock_item.rb,
app/models/spree/credit_card.rb,
app/models/spree/legacy_user.rb,
app/models/spree/option_type.rb,
app/models/spree/return_item.rb,
app/models/spree/taxon_image.rb,
app/models/spree/zone_member.rb,
lib/spree/core/query_filters.rb,
app/finders/spree/taxons/find.rb,
app/helpers/spree/base_helper.rb,
app/mailers/spree/base_mailer.rb,
app/mailers/spree/test_mailer.rb,
app/models/spree/option_value.rb,
app/models/spree/order_merger.rb,
app/models/spree/state_change.rb,
app/models/spree/stock/packer.rb,
app/models/spree/store_credit.rb,
app/models/spree/tax_category.rb,
app/sorters/spree/orders/sort.rb,
lib/spree/core/importer/order.rb,
lib/spree/dependencies_helper.rb,
app/mailers/spree/order_mailer.rb,
app/models/spree/gateway/bogus.rb,
app/models/spree/order_updater.rb,
app/models/spree/refund_reason.rb,
app/models/spree/reimbursement.rb,
app/models/spree/shipping_rate.rb,
app/models/spree/stock/package.rb,
app/services/spree/cart/create.rb,
app/services/spree/cart/update.rb,
lib/spree/core/product_filters.rb,
lib/spree/core/token_generator.rb,
lib/spree/permitted_attributes.rb,
lib/spree/testing_support/i18n.rb,
app/finders/spree/products/find.rb,
app/models/spree/classification.rb,
app/models/spree/inventory_unit.rb,
app/models/spree/order/checkout.rb,
app/models/spree/order/payments.rb,
app/models/spree/payment_method.rb,
app/models/spree/promotion_rule.rb,
app/models/spree/stock/adjuster.rb,
app/models/spree/stock_location.rb,
app/models/spree/stock_movement.rb,
app/models/spree/stock_transfer.rb,
app/sorters/spree/products/sort.rb,
lib/spree/core/importer/product.rb,
lib/spree/core/number_generator.rb,
lib/spree/testing_support/flash.rb,
app/finders/spree/countries/find.rb,
app/models/spree/customer_return.rb,
app/models/spree/order_inventory.rb,
app/models/spree/order_promotion.rb,
app/models/spree/prototype_taxon.rb,
app/models/spree/shipping_method.rb,
app/models/spree/stock/estimator.rb,
app/services/spree/cart/add_item.rb,
app/services/spree/checkout/next.rb,
lib/spree/testing_support/kernel.rb,
app/helpers/spree/products_helper.rb,
app/mailers/spree/shipment_mailer.rb,
app/models/spree/app_dependencies.rb,
app/models/spree/product_property.rb,
app/models/spree/promotion_action.rb,
app/models/spree/shipment_handler.rb,
app/models/spree/stock/quantifier.rb,
app/services/spree/generate_token.rb,
lib/spree/core/product_duplicator.rb,
lib/spree/core/query_filters/date.rb,
lib/spree/core/query_filters/text.rb,
app/models/spree/app_configuration.rb,
app/models/spree/shipping_category.rb,
app/models/spree/stock/coordinator.rb,
app/models/spree/stock/prioritizer.rb,
app/models/spree/store_credit_type.rb,
app/services/spree/checkout/update.rb,
app/finders/spree/credit_cards/find.rb,
app/models/spree/fulfilment_changer.rb,
app/models/spree/order/address_book.rb,
app/models/spree/order/store_credit.rb,
app/models/spree/payment/processing.rb,
app/models/spree/promotion_category.rb,
app/models/spree/property_prototype.rb,
app/models/spree/reimbursement_type.rb,
app/models/spree/returns_calculator.rb,
app/models/spree/stock/content_item.rb,
app/models/spree/store_credit_event.rb,
app/services/spree/cart/recalculate.rb,
app/services/spree/cart/remove_item.rb,
app/services/spree/checkout/advance.rb,
lib/spree/core/query_filters/number.rb,
app/models/concerns/spree/named_type.rb,
app/models/spree/product_option_type.rb,
app/models/spree/promotion_rule_user.rb,
app/models/spree/shipping_calculator.rb,
app/models/spree/stock/splitter/base.rb,
app/paginators/spree/shared/paginate.rb,
app/services/spree/cart/set_quantity.rb,
app/services/spree/checkout/complete.rb,
app/finders/spree/orders/find_current.rb,
app/models/spree/calculator/flat_rate.rb,
app/models/spree/gateway/bogus_simple.rb,
app/models/spree/option_value_variant.rb,
app/models/spree/payment_method/check.rb,
app/models/spree/promotion/rules/user.rb,
app/models/spree/promotion_rule_taxon.rb,
app/models/spree/reimbursement/credit.rb,
app/models/spree/return_authorization.rb,
app/models/spree/shipping_method_zone.rb,
app/models/spree/stock/differentiator.rb,
app/services/spree/compare_line_items.rb,
lib/spree/testing_support/preferences.rb,
lib/spree/testing_support/url_helpers.rb,
app/finders/spree/orders/find_complete.rb,
app/mailers/spree/reimbursement_mailer.rb,
app/models/concerns/spree/user_address.rb,
app/models/concerns/spree/user_methods.rb,
app/models/spree/calculator/flexi_rate.rb,
app/models/spree/calculator/price_sack.rb,
app/models/spree/option_type_prototype.rb,
app/models/spree/payment_capture_event.rb,
app/models/spree/promotion/rules/taxon.rb,
app/models/spree/stock/splitter/weight.rb,
app/models/spree/store_credit_category.rb,
app/presenters/spree/variant_presenter.rb,
lib/spree/core/controller_helpers/auth.rb,
app/models/concerns/spree/default_price.rb,
app/models/concerns/spree/display_money.rb,
app/models/spree/calculator/default_tax.rb,
app/models/spree/order/currency_updater.rb,
app/models/spree/product_promotion_rule.rb,
app/models/spree/promotion_handler/cart.rb,
app/models/spree/promotion_handler/page.rb,
lib/spree/core/controller_helpers/order.rb,
lib/spree/core/controller_helpers/store.rb,
lib/spree/core/query_filters/comparable.rb,
lib/spree/testing_support/image_helpers.rb,
app/models/concerns/spree/product_scopes.rb,
app/models/concerns/spree/user_reporting.rb,
app/models/spree/adjustable/adjuster/tax.rb,
app/models/spree/payment/gateway_options.rb,
app/models/spree/promotion/rules/country.rb,
app/models/spree/promotion/rules/product.rb,
app/models/spree/reimbursement_performer.rb,
app/services/spree/cart/remove_line_item.rb,
lib/spree/core/controller_helpers/common.rb,
lib/spree/core/controller_helpers/search.rb,
app/finders/spree/variants/visible_finder.rb,
app/models/concerns/spree/number_as_param.rb,
app/models/spree/adjustable/adjuster/base.rb,
app/models/spree/promotion_handler/coupon.rb,
app/models/spree/shipping_method_category.rb,
app/models/spree/calculator/tiered_percent.rb,
app/models/spree/reimbursement_type/credit.rb,
lib/generators/spree/dummy/dummy_generator.rb,
app/models/concerns/spree/adjustment_source.rb,
app/models/spree/promotion/rules/item_total.rb,
app/models/spree/promotion_action_line_item.rb,
app/models/spree/stock/splitter/backordered.rb,
app/finders/spree/line_items/find_by_variant.rb,
app/models/spree/calculator/tiered_flat_rate.rb,
app/models/spree/payment_method/store_credit.rb,
app/models/spree/promotion/rules/first_order.rb,
app/models/spree/return_authorization_reason.rb,
app/services/spree/checkout/add_store_credit.rb,
app/models/concerns/spree/user_payment_source.rb,
app/models/spree/asset/support/active_storage.rb,
app/models/spree/calculator/shipping/per_item.rb,
app/models/spree/promotion/rules/option_value.rb,
app/models/spree/reimbursement_tax_calculator.rb,
app/models/spree/stock/availability_validator.rb,
app/models/spree/stock/inventory_unit_builder.rb,
lib/spree/testing_support/controller_requests.rb,
app/finders/spree/variants/option_types_finder.rb,
app/models/spree/adjustable/adjuster/promotion.rb,
app/models/spree/calculator/shipping/flat_rate.rb,
app/presenters/spree/product_summary_presenter.rb,
app/services/spree/checkout/get_shipping_rates.rb,
lib/generators/spree/install/install_generator.rb,
app/models/concerns/spree/vat_price_calculation.rb,
app/models/spree/adjustable/adjustments_updater.rb,
app/models/spree/calculator/shipping/flexi_rate.rb,
app/models/spree/calculator/shipping/price_sack.rb,
app/models/spree/promotion/rules/user_logged_in.rb,
app/presenters/spree/variants/options_presenter.rb,
app/services/spree/cart/estimate_shipping_rates.rb,
app/services/spree/checkout/remove_store_credit.rb,
lib/spree/testing_support/authorization_helpers.rb,
app/models/concerns/spree/calculated_adjustments.rb,
app/models/spree/calculator/percent_on_line_item.rb,
app/models/spree/promotion/actions/free_shipping.rb,
app/models/spree/promotion_handler/free_shipping.rb,
app/models/spree/adjustable/promotion_accumulator.rb,
app/models/spree/promotion/rules/one_use_per_user.rb,
app/models/spree/stock/splitter/shipping_category.rb,
app/models/spree/calculator/flat_percent_item_total.rb,
app/models/spree/image/configuration/active_storage.rb,
lib/spree/core/controller_helpers/strong_parameters.rb,
app/models/spree/promotion/actions/create_adjustment.rb,
app/models/spree/promotion/actions/create_line_items.rb,
app/presenters/spree/variants/option_types_presenter.rb,
lib/generators/spree/custom_user/custom_user_generator.rb,
lib/generators/spree/dummy_model/dummy_model_generator.rb,
app/models/spree/promotion_handler/promotion_duplicator.rb,
app/models/spree/reimbursement/reimbursement_type_engine.rb,
app/models/spree/validations/db_maximum_length_validator.rb,
app/models/spree/calculator/returns/default_refund_amount.rb,
app/models/spree/reimbursement_type/reimbursement_helpers.rb,
app/models/spree/taxon_image/configuration/active_storage.rb,
app/models/spree/promotion/actions/create_item_adjustments.rb,
app/models/spree/return_item/eligibility_validator/default.rb,
app/models/spree/reimbursement/reimbursement_type_validator.rb,
app/models/spree/calculator/shipping/flat_percent_item_total.rb,
app/models/spree/return_item/eligibility_validator/base_validator.rb,
app/models/spree/return_item/eligibility_validator/r_m_a_required.rb,
app/models/spree/return_item/eligibility_validator/order_completed.rb,
app/models/spree/return_item/eligibility_validator/inventory_shipped.rb,
app/models/spree/return_item/eligibility_validator/no_reimbursements.rb,
app/models/spree/return_item/eligibility_validator/time_since_purchase.rb,
app/models/spree/return_item/exchange_variant_eligibility/same_product.rb,
app/models/spree/return_item/exchange_variant_eligibility/same_option_value.rb

Overview

A rule to apply to an order greater than (or greater than or equal to) a specific amount

Defined Under Namespace

Modules: Adjustable, AdjustmentSource, BaseHelper, CalculatedAdjustments, Cart, Checkout, Core, Countries, CreditCards, DefaultPrice, DependenciesHelper, DisplayMoney, DummyGeneratorHelper, LineItems, NamedType, NumberAsParam, Orders, PermittedAttributes, Preferences, ProductScopes, Products, ProductsHelper, PromotionHandler, RansackableAttributes, ServiceModule, Shared, Stock, Taxons, TestingSupport, UserAddress, UserMethods, UserPaymentSource, UserReporting, Validations, Variants, VatPriceCalculation, ViewContext Classes: Ability, Address, Adjustment, AppConfiguration, AppDependencies, Asset, Base, BaseController, BaseMailer, Calculator, Classification, CompareLineItems, Country, CreditCard, CustomUserGenerator, CustomerReturn, DummyGenerator, DummyModelGenerator, Exchange, FulfilmentChanger, Gateway, GenerateToken, Image, InstallGenerator, InventoryUnit, LegacyUser, LineItem, LocalizedNumber, LogEntry, Migrations, Money, OptionType, OptionTypePrototype, OptionValue, OptionValueVariant, Order, OrderInventory, OrderMailer, OrderMerger, OrderPromotion, OrderUpdater, Payment, PaymentCaptureEvent, PaymentMethod, Preference, Price, Product, ProductDuplicator, ProductOptionType, ProductPromotionRule, ProductProperty, ProductSummaryPresenter, Promotion, PromotionAction, PromotionActionLineItem, PromotionCategory, PromotionRule, PromotionRuleTaxon, PromotionRuleUser, Property, PropertyPrototype, Prototype, PrototypeTaxon, Refund, RefundReason, Reimbursement, ReimbursementMailer, ReimbursementPerformer, ReimbursementTaxCalculator, ReimbursementType, ReturnAuthorization, ReturnAuthorizationReason, ReturnItem, ReturnsCalculator, Role, RoleUser, Shipment, ShipmentHandler, ShipmentMailer, ShippingCalculator, ShippingCategory, ShippingMethod, ShippingMethodCategory, ShippingMethodZone, ShippingRate, State, StateChange, StockItem, StockLocation, StockMovement, StockTransfer, Store, StoreCredit, StoreCreditCategory, StoreCreditEvent, StoreCreditType, TaxCategory, TaxRate, Taxon, TaxonImage, Taxonomy, TestMailer, Variant, VariantPresenter, Zone, ZoneMember

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.missing_translation_messagesObject

Returns the value of attribute missing_translation_messages


12
13
14
# File 'lib/spree/testing_support/i18n.rb', line 12

def missing_translation_messages
  @missing_translation_messages
end

.unused_translation_messagesObject

Returns the value of attribute unused_translation_messages


12
13
14
# File 'lib/spree/testing_support/i18n.rb', line 12

def unused_translation_messages
  @unused_translation_messages
end

.unused_translationsObject

Returns the value of attribute unused_translations


12
13
14
# File 'lib/spree/testing_support/i18n.rb', line 12

def unused_translations
  @unused_translations
end

.used_translationsObject

Returns the value of attribute used_translations


12
13
14
# File 'lib/spree/testing_support/i18n.rb', line 12

def used_translations
  @used_translations
end

Class Method Details

.admin_pathObject


32
33
34
# File 'lib/spree/core.rb', line 32

def self.admin_path
  Spree::Config[:admin_path]
end

.admin_path=(path) ⇒ Object

Used to configure admin_path for Spree

Example:

write the following line in `config/initializers/spree.rb`

Spree.admin_path = '/custom-path'

43
44
45
# File 'lib/spree/core.rb', line 43

def self.admin_path=(path)
  Spree::Config[:admin_path] = path
end

.check_missing_translationsObject


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/spree/testing_support/i18n.rb', line 28

def self.check_missing_translations
  self.missing_translation_messages = []
  self.used_translations ||= []
  used_translations.map { |a| a.split('.') }.each do |translation_keys|
    root = translations
    processed_keys = []
    translation_keys.each do |key|
      root = root.fetch(key.to_sym)
      processed_keys << key.to_sym
    rescue KeyError
      error = "#{(processed_keys << key).join('.')} (#{I18n.locale})"
      unless Spree.missing_translation_messages.include?(error)
        Spree.missing_translation_messages << error
      end
    end
  end
end

.check_unused_translationsObject


46
47
48
49
50
51
52
53
54
55
# File 'lib/spree/testing_support/i18n.rb', line 46

def self.check_unused_translations
  self.used_translations ||= []
  self.unused_translation_messages = []
  self.unused_translations = []
  load_translations(translations)
  translation_diff = unused_translations - used_translations
  translation_diff.each do |translation|
    Spree.unused_translation_messages << "#{translation} (#{I18n.locale})"
  end
end

.config {|Spree::Config| ... } ⇒ Object

Used to configure Spree.

Example:

Spree.config do |config|
  config.track_inventory_levels = false
end

This method is defined within the core gem on purpose. Some people may only wish to use the Core part of Spree.

Yields:

  • (Spree::Config)

57
58
59
# File 'lib/spree/core.rb', line 57

def self.config
  yield(Spree::Config)
end

.contextObject


23
24
25
# File 'lib/spree/i18n.rb', line 23

def context
  Spree::ViewContext.context
end

.dependencies {|Spree::Dependencies| ... } ⇒ Object

Used to set dependencies for Spree.

Example:

Spree.dependencies do |dependency|
  dependency.cart_add_item_service = MyCustomAddToCart
end

This method is defined within the core gem on purpose. Some people may only wish to use the Core part of Spree.

Yields:

  • (Spree::Dependencies)

71
72
73
# File 'lib/spree/core.rb', line 71

def self.dependencies
  yield(Spree::Dependencies)
end

.normal_tObject

Add spree namespace and delegate to Rails TranslationHelper for some nice extra functionality. e.g return reasonable strings for missing translations


14
15
16
17
18
19
20
21
# File 'lib/spree/testing_support/i18n.rb', line 14

def translate(*args)
  @virtual_path = virtual_path

  options = args.extract_options!
  options[:scope] = [*options[:scope]].unshift(:spree)
  args << options
  super(*args)
end

.translate(*args) ⇒ Object Also known as: t

Add spree namespace and delegate to Rails TranslationHelper for some nice extra functionality. e.g return reasonable strings for missing translations


12
13
14
15
16
17
18
19
# File 'lib/spree/i18n.rb', line 12

def translate(*args)
  @virtual_path = virtual_path

  options = args.extract_options!
  options[:scope] = [*options[:scope]].unshift(:spree)
  args << options
  super(*args)
end

.user_class(constantize: true) ⇒ Object


24
25
26
27
28
29
30
# File 'lib/spree/core.rb', line 24

def self.user_class(constantize: true)
  if @@user_class.is_a?(Class)
    raise 'Spree.user_class MUST be a String or Symbol object, not a Class object.'
  elsif @@user_class.is_a?(String) || @@user_class.is_a?(Symbol)
    constantize ? @@user_class.to_s.constantize : @@user_class.to_s
  end
end

.versionObject


2
3
4
# File 'lib/spree/core/version.rb', line 2

def self.version
  '4.1.2'
end

.virtual_pathObject


27
28
29
30
31
32
33
# File 'lib/spree/i18n.rb', line 27

def virtual_path
  if context
    path = context.instance_variable_get('@virtual_path')

    path&.gsub(/spree/, '')
  end
end