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
FIX order summary mail total amount
Michał Brożek122880913a9b
diff --git a/admin/app/views/spree/admin/gift_card_batches/_form.html.erb b/admin/app/views/spree/admin/gift_card_batches/_form.html.erbindex 7f2121fb1c..2d6978d246 100644--- a/admin/app/views/spree/admin/gift_card_batches/_form.html.erb+++ b/admin/app/views/spree/admin/gift_card_batches/_form.html.erb@@ -3,13 +3,13 @@<div class="card mb-4"><div class="card-header"><h5 class="card-title">- <%= Spree.t(:gift_card_batch) %>+ <%= Spree.t('admin.gift_card_batches.gift_card_batch') %></h5></div><div class="card-body"><div class="form-group">- <%= f.label :prefix, raw(Spree.t(:prefix) + required_span_tag)%>+ <%= f.label :prefix, raw(Spree.t('admin.gift_card_batches.prefix') + required_span_tag)%><%= f.text_field :prefix, class: 'form-control', disabled: f.object.persisted? %><%= f.error_message_on :prefix %></div>@@ -32,7 +32,7 @@</div><div class="form-group">- <%= f.label :codes_count, raw(Spree.t(:codes_count) + required_span_tag) %>+ <%= f.label :codes_count, raw(Spree.t('admin.gift_card_batches.codes_count') + required_span_tag) %><%= f.number_field :codes_count, class: 'form-control', disabled: f.object.persisted?, required: true %><%= f.error_message_on :codes_count %></div>diff --git a/admin/app/views/spree/admin/gift_card_batches/new.html.erb b/admin/app/views/spree/admin/gift_card_batches/new.html.erbindex 79b0bd1ebd..ff8406e5b9 100644--- a/admin/app/views/spree/admin/gift_card_batches/new.html.erb+++ b/admin/app/views/spree/admin/gift_card_batches/new.html.erb@@ -1,6 +1,6 @@<% content_for :page_title do %><%= page_header_back_button spree.admin_gift_cards_path %>- <%= Spree.t(:new_gift_card_batch) %>+ <%= Spree.t('admin.gift_card_batches.new_gift_card_batch') %><% end %><%= render partial: 'spree/admin/shared/error_messages', locals: { target: @object } %>diff --git a/admin/app/views/spree/admin/gift_cards/_filters.html.erb b/admin/app/views/spree/admin/gift_cards/_filters.html.erbindex ef036ffc2f..707b2453b9 100644--- a/admin/app/views/spree/admin/gift_cards/_filters.html.erb+++ b/admin/app/views/spree/admin/gift_cards/_filters.html.erb@@ -25,7 +25,7 @@<% end %><div class="form-group">- <%= f.label :batch_prefix_eq, Spree.t(:prefix) %>+ <%= f.label :batch_prefix_eq, Spree.t('admin.gift_card_batches.prefix') %><%= f.text_field :batch_prefix_eq, class: "form-control", data: {filters_target: :input} %></div>diff --git a/admin/app/views/spree/admin/gift_cards/_list.html.erb b/admin/app/views/spree/admin/gift_cards/_list.html.erbindex be589c7e94..d7eb929481 100644--- a/admin/app/views/spree/admin/gift_cards/_list.html.erb+++ b/admin/app/views/spree/admin/gift_cards/_list.html.erb@@ -11,7 +11,7 @@<th><%= Spree.t(:expires_at) %></th><% if params[:user_id].blank? %>- <th><%= Spree.t(:issued_to) %></th>+ <th><%= Spree.t('admin.gift_cards.issued_to') %></th><th></th><% end %></tr>diff --git a/admin/app/views/spree/admin/gift_cards/_table_filter_dropdown.html.erb b/admin/app/views/spree/admin/gift_cards/_table_filter_dropdown.html.erbindex ec11ded5f4..298911572e 100644--- a/admin/app/views/spree/admin/gift_cards/_table_filter_dropdown.html.erb+++ b/admin/app/views/spree/admin/gift_cards/_table_filter_dropdown.html.erb@@ -5,7 +5,7 @@</button><div class="dropdown-menu w-100" style="min-width: 200px">- <%= active_link_to Spree.t(:all_statuses), params.to_unsafe_h.deep_merge({page: nil, q: {status_eq: nil}}), class: 'dropdown-item', active: (params[:q] || {}).values_at(*%w[status_eq in_stock_items out_of_stock_items] ).all?(&:blank?) %>+ <%= active_link_to Spree.t('admin.gift_cards.all_statuses'), params.to_unsafe_h.deep_merge({page: nil, q: {status_eq: nil}}), class: 'dropdown-item', active: (params[:q] || {}).values_at(*%w[status_eq in_stock_items out_of_stock_items] ).all?(&:blank?) %><%= link_to Spree.t('admin.gift_cards.active'),params.to_unsafe_h.deep_merge({page: nil, q: {status_eq: :active}}),diff --git a/admin/app/views/spree/admin/gift_cards/new.html.erb b/admin/app/views/spree/admin/gift_cards/new.html.erbindex 1586110207..44069a3848 100644--- a/admin/app/views/spree/admin/gift_cards/new.html.erb+++ b/admin/app/views/spree/admin/gift_cards/new.html.erb@@ -5,7 +5,7 @@<%= page_header_back_button spree.admin_gift_cards_path %><% end %>- <%= Spree.t(:new_gift_card) %>+ <%= Spree.t('admin.gift_cards.new_gift_card') %><% end %><%= render partial: 'spree/admin/shared/error_messages', locals: { target: @object } %>diff --git a/admin/config/locales/en.yml b/admin/config/locales/en.ymlindex d7eb089711..8749e28539 100644--- a/admin/config/locales/en.yml+++ b/admin/config/locales/en.yml@@ -77,6 +77,19 @@ en:export_only_filtered_records: Export only filtered records, matching the search criteriafilters: Filtersgetting_started: Getting started+ gift_card_batches:+ codes_count: Codes count+ gift_card_batch: Gift card batch+ new_gift_card_batch: New Gift Card Batch+ prefix: Prefix+ gift_cards:+ active: Active+ all: All+ all_statuses: All statuses+ expired: Expired+ issued_to: Issued to+ new_gift_card: New gift card+ redeemed: Redeemedintegrations:invalid_integration_type: This integration is not allowedpage_subtitle: Connect your store to third-party services to enhance customer experience.diff --git a/core/app/jobs/spree/gift_cards/bulk_generate_job.rb b/core/app/jobs/spree/gift_cards/bulk_generate_job.rbindex ac9837a285..e754177474 100644--- a/core/app/jobs/spree/gift_cards/bulk_generate_job.rb+++ b/core/app/jobs/spree/gift_cards/bulk_generate_job.rb@@ -1,7 +1,7 @@module Spreemodule GiftCardsclass BulkGenerateJob < ::Spree::BaseJob- queue_as Spree.queues.gift_cards_bulk_generate+ queue_as Spree.queues.gift_cardsdef perform(id)gift_cards_batch = Spree::GiftCardBatch.find(id)diff --git a/core/app/models/spree/gift_card.rb b/core/app/models/spree/gift_card.rbindex e524221658..4797d2fc1d 100644--- a/core/app/models/spree/gift_card.rb+++ b/core/app/models/spree/gift_card.rb@@ -23,7 +23,7 @@ module Spreehas_many :orders, through: :store_credits, source: :ordersend- has_many :users, through: :orders+ has_many :users, through: :orders, class_name: Spree.user_class.to_sscope :active, -> { where(state: [:active, :partialy_redeemed]).where(expires_at: [nil, Time.current..]) }scope :expired, -> { where(state: :active).where(expires_at: ..Time.current) }@@ -38,8 +38,6 @@ module Spreebefore_validation :normalize_codeafter_validation :set_amount_remaining- after_commit :track_gift_card_issued, on: :create-before_destroy :ensure_can_be_deletedmoney_methods :amount, :used_amount, :amount_remaining, :minimum_order_amount@@ -146,20 +144,6 @@ module Spreeself.amount_remaining = amountend- def track_gift_card_issued- return unless user_id.present?-- if store_integration('klaviyo').present?- Klaviyo::CreateEventWorker.perform_async(- store_integration('klaviyo').id,- 'Gift Card Issued',- id,- self.class.to_s,- user.email- )- end- end-def ensure_can_be_deletedreturn if can_be_deleted?diff --git a/core/app/models/spree/gift_card_batch.rb b/core/app/models/spree/gift_card_batch.rbindex 9edbac5d30..e7faf250e5 100644--- a/core/app/models/spree/gift_card_batch.rb+++ b/core/app/models/spree/gift_card_batch.rb@@ -3,10 +3,8 @@ module Spreeextend DisplayMoneyinclude Spree::SingleStoreResource- LIMIT = ENV.fetch('GIFT_CARD_BATCH_LIMIT', 50_000).to_i-validates :codes_count, :amount, :prefix, presence: true- validates :codes_count, numericality: { greater_than: 0, less_than_or_equal_to: LIMIT }+ validates :codes_count, numericality: { greater_than: 0, less_than_or_equal_to: Spree::Config[:gift_card_batch_limit] }validates :amount, numericality: { greater_than: 0 }validates :minimum_order_amount, numericality: { greater_than_or_equal_to: 0 }diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rbindex 3705dcdc3d..10ccf431fd 100644--- a/core/app/models/spree/order.rb+++ b/core/app/models/spree/order.rb@@ -896,17 +896,14 @@ module Spreedef after_cancelshipments.each(&:cancel!)- payments.completed.each(&:cancel!)-- # Free up authorized store credits- payments.store_credits.pending.each(&:void!)# payments fully covered by gift card won't be refunded# we want to only void the payment- if (parent || self).gift_card.present? && covered_by_store_credit?+ if gift_card.present? && covered_by_store_credit?payments.completed.store_credits.each(&:void!)else- payments.completed.not_for_shipping.each(&:cancel!)+ payments.completed.each(&:cancel!)+ payments.store_credits.pending.each(&:void!)endsend_cancel_emaildiff --git a/core/config/locales/en.yml b/core/config/locales/en.ymlindex 241fdb2015..f3757d27d7 100644--- a/core/config/locales/en.yml+++ b/core/config/locales/en.yml@@ -228,6 +228,10 @@ en:base:card_expired: Card has expiredexpiry_invalid: Card expiration is invalid+ spree/gift_card:+ attributes:+ base:+ cannot_destroy_used_gift_card: Can't delete a used gift cardspree/image:attributes:attachment:@@ -314,10 +318,6 @@ en:attributes:variant:taken: You already added this item to your wishlist- spree/gift_card:- attributes:- base:- cannot_destroy_used_gift_card: "Can't delete a used gift card"models:spree/address:one: Address@@ -1037,7 +1037,7 @@ en:expiration: Expirationexpiration_date: Expiration Dateexpired: Expired- expires_at: Expires at+ expires_at: Expires Atexplore_taxon: Explore taxonexport: Exportexport_mailer:@@ -1093,13 +1093,12 @@ en:generate_code: Generate coupon codeget_back_to_the: Get back to thegift_card: Gift card- gift_cards: Gift cardsgift_card_applied: The gift card was successfully applied to your order!- gift_card_removed: The gift card was successfully removed from your order- gift_card_using_store_credit_error: You can't apply the gift card after you applied the store credit.gift_card_minimum_order_value_error: You can't apply the gift card. The order total must be at least %{minimum_order_amount}, excluding shipping cost.gift_card_no_amount_remaining: You can't apply the gift card with no balance on it.- remove_gift_card_on_completed_order_error: You can't remove the gift card after the order was placed+ gift_card_removed: The gift card was successfully removed from your order+ gift_card_using_store_credit_error: You can't apply the gift card after you applied the store credit.+ gift_cards: Gift cardsgo_to_category: Go to categorygo_to_facebook: Go to facebookgo_to_homepage: Go to Home Page@@ -1263,6 +1262,7 @@ en:metadata: Metadatamin: Minminimal_amount: Minimal Amount+ minimum_order_amount: Minimum Order Amountminimum_password_length:one: "(%{count} character minimum)"other: "(%{count} characters minimum)"@@ -1756,6 +1756,7 @@ en:remember_me: Remember meremove: Removeremove_condition: Remove condition+ remove_gift_card_on_completed_order_error: You can't remove the gift card after the order was placedremove_image: Remove Imagerename: Renamereport: Reportdiff --git a/core/lib/spree/core.rb b/core/lib/spree/core.rbindex 12127995e3..39200ae1f4 100644--- a/core/lib/spree/core.rb+++ b/core/lib/spree/core.rb@@ -105,7 +105,8 @@ module Spreecoupon_codes: :default,webhooks: :default,themes: :default,- addresses: :default+ addresses: :default,+ gift_cards: :default)enddiff --git a/core/lib/spree/core/configuration.rb b/core/lib/spree/core/configuration.rbindex 7a9d67f81f..9eefe99227 100644--- a/core/lib/spree/core/configuration.rb+++ b/core/lib/spree/core/configuration.rb@@ -45,6 +45,7 @@ module Spreepreference :expedited_exchanges, :boolean, default: false # NOTE this requires payment profiles to be supported on your gateway of choice as well as a delayed job handler to be configured with activejob. kicks off an exchange shipment upon return authorization save. charge customer if they do not return items within timely manner.preference :expedited_exchanges_days_window, :integer, default: 14 # the amount of days the customer has to return their item after the expedited exchange is shipped in order to avoid being chargedpreference :geocode_addresses, :boolean, default: true+ preference :gift_card_batch_limit, :integer, default: 50_000preference :layout, :string, deprecated: 'Please use Spree::Frontend::Config[:layout] instead'preference :logo, :string, deprecated: truepreference :mailer_logo, :string, deprecated: truediff --git a/core/spec/models/spree/gift_card_batch_spec.rb b/core/spec/models/spree/gift_card_batch_spec.rbindex 68bb6bb537..d20750b896 100644--- a/core/spec/models/spree/gift_card_batch_spec.rb+++ b/core/spec/models/spree/gift_card_batch_spec.rb@@ -12,7 +12,7 @@# updated_at :datetime not null# tenant_id :bigint not null#-require 'rails_helper'+require 'spec_helper'RSpec.describe Spree::GiftCardBatch, type: :model dodescribe '#create_gift_cards' do@@ -23,10 +23,10 @@ RSpec.describe Spree::GiftCardBatch, type: :model doexpect(gift_card_batch.gift_cards.count).to eq 2- expect(gift_card_batch.gift_cards.pluck(:amount).uniq).to eq [gift_card_batch.amount]- expect(gift_card_batch.gift_cards.pluck(:amount_remaining).uniq).to eq [gift_card_batch.amount]- expect(gift_card_batch.gift_cards.pluck(:expires_at).uniq).to eq [gift_card_batch.expires_at]- expect(gift_card_batch.gift_cards.take.code).to match(/batch_/)+ expect(gift_card_batch.gift_cards.pluck(:amount).uniq).to eq [gift_card_batch.amount]+ expect(gift_card_batch.gift_cards.pluck(:amount_remaining).uniq).to eq [gift_card_batch.amount]+ expect(gift_card_batch.gift_cards.pluck(:expires_at).uniq).to eq [gift_card_batch.expires_at]+ expect(gift_card_batch.gift_cards.take.code).to match(/batch_/)endend@@ -45,7 +45,7 @@ RSpec.describe Spree::GiftCardBatch, type: :model dobefore { gift_card_batch.codes_count = 501 }it 'enqueues a job' do- expect(Spree::GiftCards::BulkGenerateWorker).to receive(:perform_async)+ expect(Spree::GiftCards::BulkGenerateJob).to receive(:perform_later)gift_card_batch.saveenddiff --git a/core/spec/models/spree/gift_card_spec.rb b/core/spec/models/spree/gift_card_spec.rbindex e6d5270757..4ee50604e0 100644--- a/core/spec/models/spree/gift_card_spec.rb+++ b/core/spec/models/spree/gift_card_spec.rb@@ -17,7 +17,7 @@# tenant_id :bigint not null# user_id :bigint#-require 'rails_helper'+require 'spec_helper'RSpec.describe Spree::GiftCard, type: :model dodescribe 'before_destroy :ensure_can_be_deleted' do@@ -37,56 +37,6 @@ RSpec.describe Spree::GiftCard, type: :model doendend- describe 'after_commit :track_gift_card_issued' do- subject do- create(- :gift_card,- user: user,- code: 'gift-card-code-1234',- amount: 10,- minimum_order_amount: 50,- expires_at: 2.days.from_now- )- end-- before do- Sidekiq::Worker.clear_all- end-- context 'with klaviyo integration' do- let!(:klaviyo_integration) { create(:klaviyo_integration) }-- context 'without user assigned' do- let(:user) { nil }-- it 'skips tracking' do- subject- expect(Klaviyo::CreateEventWorker.jobs).to be_empty- end- end-- context 'with user assigned' do- let(:user) { create(:user) }-- it 'tracks the gift card issued' do- subject-- expect(Klaviyo::CreateEventWorker.jobs.count).to eq(1)- expect(Klaviyo::CreateEventWorker.jobs.last['args']).to eq([klaviyo_integration.id, 'Gift Card Issued', subject.id, 'Spree::GiftCard', user.email])- end- end- end-- context 'without klaviyo integration' do- let(:user) { create(:user) }-- it 'skips tracking' do- subject- expect(Klaviyo::CreateEventWorker.jobs).to be_empty- end- end- end-describe '#display_state' docontext 'when expired' dolet(:gift_card) { build(:gift_card, expires_at: 1.day.ago, state: :active) }diff --git a/core/spec/models/spree/order_spec.rb b/core/spec/models/spree/order_spec.rbindex c97e3cba4c..6f494fbb23 100644--- a/core/spec/models/spree/order_spec.rb+++ b/core/spec/models/spree/order_spec.rb@@ -171,6 +171,36 @@ describe Spree::Order, type: :model doendend+ describe '#after_cancel' do+ context 'when gift card is present' do+ let(:gift_card) { create(:gift_card, amount: 110) }+ let(:order) { create(:completed_order_with_totals, store: store, gift_card: gift_card, total: 110) }+ let!(:payment) { create(:store_credit_payment, order: order, state: 'completed', amount: 110) }++ it 'handles additional actions' do+ order.cancel+ order.reload++ expect(order.shipments).to all(have_attributes(state: 'canceled'))+ expect(order.payments.store_credits).to all(have_attributes(state: 'void'))+ end+ end++ context 'when no gift card' do+ let(:order) { create(:completed_order_with_totals, store: store) }+ let!(:payment) { create(:payment, order: order, state: 'completed', amount: 10) }++ it 'handles additional actions' do+ order.cancel+ order.reload++ expect(order.shipments).to all(have_attributes(state: 'canceled'))+ expect(order.payments).to all(have_attributes(state: 'void'))+ expect(order.payments.store_credits).to all(have_attributes(state: 'void'))+ end+ end+ end+describe '#canceled_by' dosubject { order.canceled_by(admin_user) }diff --git a/emails/app/views/spree/shared/purchased_items_table/_total.html.erb b/emails/app/views/spree/shared/purchased_items_table/_total.html.erbindex 9cb31c5c4f..7c885d5f76 100644--- a/emails/app/views/spree/shared/purchased_items_table/_total.html.erb+++ b/emails/app/views/spree/shared/purchased_items_table/_total.html.erb@@ -7,7 +7,7 @@</td><td><p class="f-fallback purchase_total">- <strong><%= order.display_total %></strong>+ <strong><%= order.display_total_minus_store_credits %></strong></p></td></tr>diff --git a/storefront/config/locales/en.yml b/storefront/config/locales/en.ymlindex f7c15e320d..38e7e7037e 100644--- a/storefront/config/locales/en.yml+++ b/storefront/config/locales/en.yml@@ -7,13 +7,13 @@ en:newsletter_settings: Newsletter settingsno_addresses_description: If you place an order, you will find address details here.no_addresses_title: You currently have no Addresses+ no_gift_cards: You currently have no gift cardsno_orders_description: If you place an order, you will find details here.no_orders_title: You currently have no ordersno_store_credits: You don't have any store credit.personal_details: Personal detailsplease_update_your_contact_details: Please update your contact detailsstore_credits_history: Store credits history- no_gift_cards: You currently have no gift cardscart:items_in_cart: Items in cartshipping_and_taxes_calculated_at_checkout: Shipping & taxes calculated at checkout