Skip to content

armgit / spree

Public Imported from GitHub
0

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.

Fix: Cancelling a dispatched order refused without saying why

Łukasz Adamczyk6ba8d101bee7
diff --git a/spree/core/app/workflows/spree/orders/cancel.rb b/spree/core/app/workflows/spree/orders/cancel.rb
index 0fa749e59e..bfbb31b938 100644
--- a/spree/core/app/workflows/spree/orders/cancel.rb
+++ b/spree/core/app/workflows/spree/orders/cancel.rb
@@ -71,7 +71,10 @@ module Spree
private
def ensure_cancellable
- failure(order) unless order.allow_cancel?
+ return if order.allow_cancel?
+
+ order.errors.add(:base, :not_cancellable, message: Spree.t('errors.messages.not_cancellable'))
+ failure(order)
end
# An ordinary order settles at the gateway, which returns the whole
diff --git a/spree/core/config/locales/en.yml b/spree/core/config/locales/en.yml
index f420258cea..e308d276a2 100644
--- a/spree/core/config/locales/en.yml
+++ b/spree/core/config/locales/en.yml
@@ -652,7 +652,6 @@ en:
not_saved:
one: '1 error prohibited this %{resource} from being saved:'
other: "%{count} errors prohibited this %{resource} from being saved:"
- refund_amount_requires_shared_payment: can only be set when the payment is shared across a split checkout
seeded_report_read_only: is a built-in report and cannot be changed — save a copy instead
number:
currency:
@@ -1081,6 +1080,7 @@ en:
must_be_greater_than_min_amount: must be greater than or equal to the minimum
must_be_origin_only: must be an origin (scheme and host) without path, query, or fragment
no_pickup_point_provider: this delivery method has no pickup point provider configured
+ not_cancellable: cannot be canceled once its goods have been dispatched
oidc_account_not_provisioned: This account is not authorized for this store. Ask an administrator for an invitation.
oidc_authentication_failed: We could not sign you in with this provider. Please try again.
oidc_missing_code: The identity provider did not return an authorization code.
@@ -1092,6 +1092,7 @@ en:
rate_provider_requires_shipping: "%{provider} quotes shipments, so this method must ship to an address"
rate_provider_unavailable: is not available for this store — connect its integration first
received_exceeds_expected: cannot be more than the %{expected} expected
+ refund_amount_requires_shared_payment: can only be set when the payment is shared across a split checkout
same_as_inviter: cannot be the same as the inviter
seller_delivery_method_not_shareable: only the marketplace's own delivery methods can be shared with sellers
seller_delivery_method_provider: a seller's delivery method prices its own rates and is fulfilled by hand — carrier accounts belong to the marketplace
diff --git a/spree/core/spec/workflows/spree/orders/cancel_spec.rb b/spree/core/spec/workflows/spree/orders/cancel_spec.rb
index 6659785668..6548e7a8bc 100644
--- a/spree/core/spec/workflows/spree/orders/cancel_spec.rb
+++ b/spree/core/spec/workflows/spree/orders/cancel_spec.rb
@@ -68,6 +68,19 @@ module Spree
end
end
+ context 'an order whose goods have gone out' do
+ let(:order) { create(:completed_order_with_totals) }
+
+ before { order.update_columns(fulfillment_status: 'fulfilled') }
+
+ it { expect(result).to be_failure }
+
+ it 'says why it refused' do
+ expect(result.error.value.full_messages.join).
+ to include(Spree.t('errors.messages.not_cancellable'))
+ end
+ end
+
context 'incomplete order' do
let(:order) { create(:order_with_totals) }