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
extract CSV stock location to make it editable in spree extensions (#13914)
Kacper Mękarski1fb5a6db4903
diff --git a/spree/admin/app/views/spree/admin/products/form/_variants.html.erb b/spree/admin/app/views/spree/admin/products/form/_variants.html.erbindex 77b2a0f609..e3e25a4eed 100644--- a/spree/admin/app/views/spree/admin/products/form/_variants.html.erb+++ b/spree/admin/app/views/spree/admin/products/form/_variants.html.erb@@ -167,7 +167,7 @@<div class="variants-table__body" data-variants-form-target="variantsContainer" data-test-id="product-variants-table"></div><div class="variants-table__footer text-sm rounded-b-2xl">- <%= Spree.t('admin.variants_form.total_inventory_html', stock_location: current_store.default_stock_location.name, count: raw("<span data-variants-form-target='stockItemsCount'>#{@product.total_on_hand}</span>") )%>+ <%= Spree.t('admin.variants_form.total_inventory_html', stock_location: default_stock_location_for_product(@product).name, count: raw("<span data-variants-form-target='stockItemsCount'>#{@product.total_on_hand}</span>") )%></div></div></div>diff --git a/spree/core/app/models/spree/variant.rb b/spree/core/app/models/spree/variant.rbindex cf6117f270..7db37d8de9 100644--- a/spree/core/app/models/spree/variant.rb+++ b/spree/core/app/models/spree/variant.rb@@ -470,14 +470,17 @@ module Spree# @param backorderable [Boolean] the backorderable flag# @param stock_location [Spree::StockLocation] the stock location to set the stock for# @return [void]- def set_stock(count_on_hand, backorderable = nil, stock_location = nil)- stock_location ||= Spree::Store.current.default_stock_location- stock_item = stock_items.find_or_initialize_by(stock_location: stock_location)+ def set_stock(count_on_hand, backorderable = nil)+ stock_item = stock_items.find_or_initialize_by(stock_location: default_stock_location)stock_item.count_on_hand = count_on_handstock_item.backorderable = backorderable if backorderable.present?stock_item.save!end+ def default_stock_location+ Spree::Store.current.default_stock_location+ end+def price_modifier_amount_in(currency, options = {})return 0 unless options.present?diff --git a/spree/core/app/services/spree/imports/row_processors/product_variant.rb b/spree/core/app/services/spree/imports/row_processors/product_variant.rbindex a908f8bd44..a1b27a88ee 100644--- a/spree/core/app/services/spree/imports/row_processors/product_variant.rb+++ b/spree/core/app/services/spree/imports/row_processors/product_variant.rb@@ -47,7 +47,7 @@ module Spreeendif attributes['inventory_count'].present?- variant.set_stock(attributes['inventory_count'].to_i, attributes['inventory_backorderable']&.to_b, store.default_stock_location)+ variant.set_stock(attributes['inventory_count'].to_i, attributes['inventory_backorderable']&.to_b)endhandle_images(variant)diff --git a/spree/core/spec/services/spree/imports/row_processors/product_variant_spec.rb b/spree/core/spec/services/spree/imports/row_processors/product_variant_spec.rbindex 847236e4ba..b44c64b81a 100644--- a/spree/core/spec/services/spree/imports/row_processors/product_variant_spec.rb+++ b/spree/core/spec/services/spree/imports/row_processors/product_variant_spec.rb@@ -53,6 +53,7 @@ RSpec.describe Spree::Imports::RowProcessors::ProductVariant, type: :service doexpect(variant.weight.to_f).to eq 0.0expect(variant.stock_items.first.count_on_hand).to eq 100expect(variant.stock_items.first.backorderable).to eq true+ expect(variant.stock_items.first.stock_location).to eq store.default_stock_locationendcontext 'when updating an existing master variant' do