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
Add `Spree::Order#analytics_subtotal` (#12707)
Łukasz Adamczyk38d321d4e17c
diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rbindex d18255c0f9..9c8903b361 100644--- a/core/app/models/spree/order.rb+++ b/core/app/models/spree/order.rb@@ -249,6 +249,13 @@ module Spreepre_tax_item_amount + shipments.sum(:pre_tax_amount)end+ # Returns the subtotal used for analytics integrations+ # It's a sum of the item total and the promo total+ # @return [Float]+ def analytics_subtotal+ (item_total + line_items.sum(:promo_total)).to_f+ end+def shipping_discountshipment_adjustments.non_tax.eligible.sum(:amount) * - 1enddiff --git a/core/spec/models/spree/order_spec.rb b/core/spec/models/spree/order_spec.rbindex 2923ef7660..5c61a4653b 100644--- a/core/spec/models/spree/order_spec.rb+++ b/core/spec/models/spree/order_spec.rb@@ -1070,6 +1070,20 @@ describe Spree::Order, type: :model doendend+ describe '#analytics_subtotal' do+ let(:order) { create(:order_with_line_items, line_items_count: 2) }++ before do+ order.update_column(:item_total, 100)+ order.line_items[0].update_column(:promo_total, 10)+ order.line_items[1].update_column(:promo_total, 5)+ end++ it 'returns the subtotal used for analytics integrations' do+ expect(order.analytics_subtotal).to eq(115)+ end+ end+describe '#quantity' do# Uses a persisted record, as the quantity is retrieved via a DB countlet(:order) { create :order_with_line_items, line_items_count: 3 }