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.

Merge main into the typed stock movements branch

Łukasz Adamczyk9f4250607cce
diff --cc packages/admin-sdk/src/types/generated/Variant.ts
index b62a626da5,d02046790d..5e6fdba158
--- a/packages/admin-sdk/src/types/generated/Variant.ts
+++ b/packages/admin-sdk/src/types/generated/Variant.ts
@@@ -1,7 -1,7 +1,7 @@@
- // Typelizer digest 72ece6108af7b4e03c056d457d7186ec
-// Typelizer digest 1d105dfa6c8c37b378ed7355684e8fe7
++// Typelizer digest 3981c27f433be71217f0b96be7fd2b90
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
- import type {Price, PriceHistory, Media, OptionValue, CustomField, StockLevel} from '@/types'
-import type {Price, PriceHistory, Seller, Media, OptionValue, CustomField, StockItem} from '@/types'
++import type {Price, PriceHistory, Seller, Media, OptionValue, CustomField, StockLevel} from '@/types'
interface Variant {
id: string;
@@@ -47,8 -49,9 +49,9 @@@
reserved_quantity: number;
total_on_hand: number | null;
product_name: string;
+ delivery_profile_id: string | null;
prices?: Array<Price>;
- stock_items?: Array<StockItem>;
+ stock_levels?: Array<StockLevel>;
}
export default Variant;
diff --cc spree/api/app/controllers/spree/api/v3/store/delivery_methods_controller.rb
index 316754d365,286a1af429..992e01f2a6
--- a/spree/api/app/controllers/spree/api/v3/store/delivery_methods_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/store/delivery_methods_controller.rb
@@@ -94,11 -94,11 +94,11 @@@ module Spre
return true if location.pickup_stock_policy == 'any'
cart.line_items.includes(variant: :product).all? do |line_item|
- next true if line_item.variant.product.digital?
+ next true if line_item.variant.digital?
next true unless line_item.variant.should_track_inventory?
- stock_item = location.stock_item(line_item.variant)
- stock_item.present? && stock_item.count_on_hand >= line_item.quantity
+ stock_level = location.stock_level(line_item.variant)
+ stock_level.present? && stock_level.available_count >= line_item.quantity
end
end
end
diff --cc spree/api/app/controllers/spree/api/v3/store/products_controller.rb
index c3f54c4848,4cba3082a4..299c84ff37
--- a/spree/api/app/controllers/spree/api/v3/store/products_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/store/products_controller.rb
@@@ -35,10 -35,18 +35,18 @@@ module Spre
# these scopes are not automatically picked by ar_lazy_preload gem and we need to explicitly include them
def scope_includes
[
- product_publications: [],
- primary_media: [attachment_attachment: :blob],
- default_variant: [:prices, stock_levels: [:stock_location, :active_stock_reservations]],
- variants: [:prices, stock_levels: [:stock_location, :active_stock_reservations]]
+ # `seller` is declared on both sides rather than left to lazy
+ # preloading: the buy box asks every variant who is selling it,
+ # and a variant with no seller of its own asks its product — so a
+ # listing would otherwise depend on ambient behaviour to avoid an
+ # N+1 on whichever of the two answers.
+ :seller,
+ {
+ product_publications: [],
+ primary_media: [attachment_attachment: :blob],
- default_variant: [:prices, stock_items: [:stock_location, :active_stock_reservations]],
- variants: [:prices, :seller, stock_items: [:stock_location, :active_stock_reservations]]
++ default_variant: [:prices, stock_levels: [:stock_location, :active_stock_reservations]],
++ variants: [:prices, :seller, stock_levels: [:stock_location, :active_stock_reservations]]
+ }
]
end