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
Simplify Shipments API controller code (#11498)
Damian Legawiec8809bed09a7a
diff --git a/api/app/controllers/spree/api/v2/platform/shipments_controller.rb b/api/app/controllers/spree/api/v2/platform/shipments_controller.rbindex 19e4d43d77..f528dcd1f8 100644--- a/api/app/controllers/spree/api/v2/platform/shipments_controller.rb+++ b/api/app/controllers/spree/api/v2/platform/shipments_controller.rb@@ -5,8 +5,7 @@ module Spreeclass ShipmentsController < ResourceControllerinclude NumberResource- before_action :load_variant, only: %i[remove_item transfer_to_location transfer_to_shipment]- before_action :load_stock_location, only: %i[transfer_to_location]+ before_action :load_variant, only: %i[transfer_to_location transfer_to_shipment]SHIPMENT_STATES = %w[ready ship cancel resume pend]@@ -61,6 +60,7 @@ module Spreeenddef transfer_to_location+ stock_location = Spree::StockLocation.find(params.dig(:shipment, :stock_location_id))quantity = params.dig(:shipment, :quantity)&.to_i || 1unless quantity > 0@@ -68,7 +68,7 @@ module Spreereturnend- transfer = resource.transfer_to_location(@variant, quantity, @stock_location)+ transfer = resource.transfer_to_location(@variant, quantity, stock_location)if transfer.valid? && transfer.run!render json: { message: I18n.t('spree.api.shipment_transfer_success') }, status: 201else@@ -111,10 +111,6 @@ module Spree@variant = current_store.variants.find_by(id: params.dig(:shipment, :variant_id))end- def load_stock_location- @stock_location = Spree::StockLocation.find(params.dig(:shipment, :stock_location_id))- end-def spree_permitted_attributesSpree::Shipment.json_api_permitted_attributes + [:selected_shipping_rate_id