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
Fix admin's variants form when numeric ids are used (#12346)
Damian Kaczmarczyk7f4ae9f318ae
diff --git a/admin/app/javascript/spree/admin/controllers/variants_form_controller.js b/admin/app/javascript/spree/admin/controllers/variants_form_controller.jsindex 3031c8fff1..15d6f06979 100644--- a/admin/app/javascript/spree/admin/controllers/variants_form_controller.js+++ b/admin/app/javascript/spree/admin/controllers/variants_form_controller.js@@ -191,6 +191,8 @@ export default class extends CheckboxSelectAll {}updateStockLocationId({ target: { value: newStockLocationId } }) {+ newStockLocationId = String(newStockLocationId)+this.currentStockLocationIdValue = newStockLocationIdthis.stockLocationsValue.forEach((stockLocationId) => {this.variantsContainerTarget@@ -604,7 +606,7 @@ export default class extends CheckboxSelectAll {}prepareStockInputs(variantTarget, internalName, idx) {- this.stockLocationsValue.forEach((stockLocationId, stockLocationIndex) => {+ this.stockLocationsValue.forEach((stockLocationId) => {const stockInput = variantTarget.querySelector(`input[data-slot="[stock_items_attributes][${stockLocationId}][count_on_hand]_input"]`)@@ -624,9 +626,9 @@ export default class extends CheckboxSelectAll {this.updateStockItemForVariant(internalName, stockItem, stockLocationId)}- stockInput.name = `product[variants_attributes][${idx}][stock_items_attributes][${stockLocationIndex}][count_on_hand]`- stockLocationIdInput.name = `product[variants_attributes][${idx}][stock_items_attributes][${stockLocationIndex}][stock_location_id]`- stockIdInput.name = `product[variants_attributes][${idx}][stock_items_attributes][${stockLocationIndex}][id]`+ stockInput.name = `product[variants_attributes][${idx}][stock_items_attributes][${stockLocationId}][count_on_hand]`+ stockLocationIdInput.name = `product[variants_attributes][${idx}][stock_items_attributes][${stockLocationId}][stock_location_id]`+ stockIdInput.name = `product[variants_attributes][${idx}][stock_items_attributes][${stockLocationId}][id]`stockInput.value = stockItem.count_on_handif (String(stockLocationId) === String(this.currentStockLocationIdValue)) {diff --git a/admin/app/views/spree/admin/products/form/_variants.html.erb b/admin/app/views/spree/admin/products/form/_variants.html.erbindex a3f753ca8f..549d41511d 100644--- a/admin/app/views/spree/admin/products/form/_variants.html.erb+++ b/admin/app/views/spree/admin/products/form/_variants.html.erb@@ -13,7 +13,7 @@data-variants-form-current-currency-value="<%= current_currency %>"data-variants-form-currencies-value="<%= supported_currencies.map(&:to_s).to_json %>"data-variants-form-current-stock-location-id-value="<%= default_stock_location_for_product(@product).id %>"- data-variants-form-stock-locations-value="<%= available_stock_locations_for_product(@product).ids.to_json %>"+ data-variants-form-stock-locations-value="<%= available_stock_locations_for_product(@product).ids.map(&:to_s).to_json %>"<% if @product_options.present? %> data-variants-form-options-value="<%= @product_options.to_json %>" <% end %><% if @product_stock.present? %> data-variants-form-stock-value="<%= @product_stock.to_json %>" <% end %><% if @product_prices.present? %> data-variants-form-prices-value="<%= @product_prices.to_json %>" <% end %>