Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Added a bunch of helper utility methods (#12063)
Damian Legawiecb48af4424c55
diff --git a/api/app/models/spree/oauth_application.rb b/api/app/models/spree/oauth_application.rbindex ec86fbcb7a..438014b6f4 100644--- a/api/app/models/spree/oauth_application.rb+++ b/api/app/models/spree/oauth_application.rb@@ -6,6 +6,13 @@ module Spreebefore_validation :set_blank_for_redirect_uri+ # returns the last someone used this application+ #+ # @return [DateTime]+ def last_used_at+ access_tokens.order(:created_at).last&.created_at+ end+privatedef set_blank_for_redirect_uridiff --git a/core/app/models/spree/adjustment.rb b/core/app/models/spree/adjustment.rbindex 8641c74021..e03b950ebb 100644--- a/core/app/models/spree/adjustment.rb+++ b/core/app/models/spree/adjustment.rb@@ -64,6 +64,7 @@ module Spreescope :charge, -> { where("#{quoted_table_name}.amount >= 0") }scope :credit, -> { where("#{quoted_table_name}.amount < 0") }scope :nonzero, -> { where("#{quoted_table_name}.amount != 0") }+ scope :non_zero, -> { where.not(amount: [nil, 0]) }scope :promotion, -> { where(source_type: 'Spree::PromotionAction') }scope :return_authorization, -> { where(source_type: 'Spree::ReturnAuthorization') }scope :is_included, -> { where(included: true) }@@ -87,6 +88,10 @@ module Spreesource_type == 'Spree::PromotionAction'end+ def tax?+ source_type == 'Spree::TaxRate'+ end+# Passing a target here would always be recommended as it would avoid# hitting the database again and would ensure you're compute values over# the specific object amount passed here.diff --git a/core/app/models/spree/line_item.rb b/core/app/models/spree/line_item.rbindex 11d0b4cf86..1a912ed8d9 100644--- a/core/app/models/spree/line_item.rb+++ b/core/app/models/spree/line_item.rb@@ -99,6 +99,13 @@ module Spreeamount + taxable_adjustment_totalend+ # returns the total tax amount+ #+ # @return [BigDecimal]+ def tax_total+ included_tax_total + additional_tax_total+ end+alias discounted_money display_discounted_amountalias discounted_amount taxable_amount@@ -117,6 +124,20 @@ module Spree!sufficient_stock?end+ # returns true if any of the inventory units are shipped+ #+ # @return [Boolean]+ def any_shipped?+ inventory_units.any?(&:shipped?)+ end++ # returns true if all of the inventory units are shipped+ #+ # @return [Boolean]+ def fully_shipped?+ inventory_units.all?(&:shipped?)+ end+def options=(options = {})return unless options.present?diff --git a/core/app/models/spree/option_value_variant.rb b/core/app/models/spree/option_value_variant.rbindex f74fce82ff..36e55d22b1 100644--- a/core/app/models/spree/option_value_variant.rb+++ b/core/app/models/spree/option_value_variant.rb@@ -5,5 +5,9 @@ module Spreevalidates :option_value, :variant, presence: truevalidates :option_value_id, uniqueness: { scope: :variant_id }++ scope :for_option_types, lambda { |option_types|+ joins(:option_value).merge(Spree::OptionValue.where(option_types: option_types))+ }endenddiff --git a/core/app/models/spree/payment/gateway_options.rb b/core/app/models/spree/payment/gateway_options.rbindex 10bc8e5ed4..dd4a3d8b29 100644--- a/core/app/models/spree/payment/gateway_options.rb+++ b/core/app/models/spree/payment/gateway_options.rb@@ -5,6 +5,10 @@ module Spree@payment = paymentend+ def statement_descriptor_suffix+ order.number+ end+def emailorder.emailend