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 ability to query Ordes / Payments / Shipments by number in Platform API (#11508)
Damian Legawiec5da264042f8e
diff --git a/api/app/controllers/spree/api/v2/platform/orders_controller.rb b/api/app/controllers/spree/api/v2/platform/orders_controller.rbindex 53553be423..74ec151f4e 100644--- a/api/app/controllers/spree/api/v2/platform/orders_controller.rb+++ b/api/app/controllers/spree/api/v2/platform/orders_controller.rb@@ -4,6 +4,7 @@ module Spreemodule Platformclass OrdersController < ResourceControllerinclude CouponCodesHelper+ include NumberResourcedef createresource = current_store.orders.new(permitted_resource_params)@@ -98,10 +99,6 @@ module SpreeSpree::Orderend- def resource- @resource ||= scope.find_by(number: params[:id]) || scope.find(params[:id])- end-def allowed_sort_attributessuper.push(:available_on, :total, :payment_total, :item_total, :shipment_total,:adjustment_total, :promo_total, :included_tax_total, :additional_tax_total,diff --git a/api/app/controllers/spree/api/v2/platform/payments_controller.rb b/api/app/controllers/spree/api/v2/platform/payments_controller.rbindex 79f8329483..a176602512 100644--- a/api/app/controllers/spree/api/v2/platform/payments_controller.rb+++ b/api/app/controllers/spree/api/v2/platform/payments_controller.rb@@ -3,6 +3,8 @@ module Spreemodule V2module Platformclass PaymentsController < ResourceController+ include NumberResource+privatedef model_classdiff --git a/api/spec/requests/spree/api/v2/platform/number_resources_spec.rb b/api/spec/requests/spree/api/v2/platform/number_resources_spec.rbnew file mode 100644index 0000000000..794c18e641--- /dev/null+++ b/api/spec/requests/spree/api/v2/platform/number_resources_spec.rb@@ -0,0 +1,43 @@+require 'spec_helper'++describe 'API V2 Number Resources Spec' do+ include_context 'Platform API v2'++ let(:bearer_token) { { 'Authorization' => valid_authorization } }++ let(:order) { create(:order, store: store) }++ describe 'orders#show' do+ context 'can fetch order by the number' do+ before do+ get "/api/v2/platform/orders/#{order.number}", headers: bearer_token+ end++ it_behaves_like 'returns 200 HTTP status'+ end+ end++ describe 'shipments#show' do+ let(:shipment) { create(:shipment, order: order) }++ context 'can fetch order by the number' do+ before do+ get "/api/v2/platform/shipments/#{shipment.number}", headers: bearer_token+ end++ it_behaves_like 'returns 200 HTTP status'+ end+ end++ describe 'payments#show' do+ let(:payment) { create(:payment, order: order) }++ context 'can fetch order by the number' do+ before do+ get "/api/v2/platform/payments/#{payment.number}", headers: bearer_token+ end++ it_behaves_like 'returns 200 HTTP status'+ end+ end+end