From 524d6e87b7d016e3da6033ecff9021725351a678 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 9 May 2025 11:27:10 +1000 Subject: [PATCH] Fix product reset on import --- .../catalog/product_import/products_reset_strategy.rb | 4 +++- spec/system/admin/product_import_spec.rb | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/engines/catalog/app/services/catalog/product_import/products_reset_strategy.rb b/engines/catalog/app/services/catalog/product_import/products_reset_strategy.rb index f4a8b9a2dd..ef257c7edc 100644 --- a/engines/catalog/app/services/catalog/product_import/products_reset_strategy.rb +++ b/engines/catalog/app/services/catalog/product_import/products_reset_strategy.rb @@ -37,8 +37,10 @@ module Catalog def reset_variant_on_hand_and_on_demand(variant) was_on_demand = variant.on_demand - variant.on_demand = false + # Reset on_hand value first because a negative level wouldn't be valid + # with on_demand being false. variant.on_hand = 0 + variant.on_demand = false variant.on_hand.zero? || was_on_demand end end diff --git a/spec/system/admin/product_import_spec.rb b/spec/system/admin/product_import_spec.rb index fb55f3d1f5..55ddd50bf8 100644 --- a/spec/system/admin/product_import_spec.rb +++ b/spec/system/admin/product_import_spec.rb @@ -240,8 +240,6 @@ RSpec.describe "Product Import" do end it "can reset product stock to zero for products not present in the CSV" do - pending("#12933") - csv_data = <<~CSV name, producer, category, on_hand, price, units, unit_type, shipping_category_id Carrots, User Enterprise, Vegetables, 500, 3.20, 500, g, #{shipping_category_id_str}