Fix reset stock when importing DFC products

This commit is contained in:
Maikel Linke
2025-02-14 10:27:09 +11:00
parent fec1021848
commit db874b18a4
2 changed files with 20 additions and 0 deletions

View File

@@ -15,6 +15,7 @@ class CatalogItemBuilder < DfcBuilder
if limit.to_i.negative?
variant.stock_items[0].backorderable = true
else
variant.stock_items[0].backorderable = false
variant.stock_items[0].count_on_hand = limit
end
end

View File

@@ -28,4 +28,23 @@ RSpec.describe DfcBuilder do
)
end
end
describe ".apply_stock" do
let(:item) { CatalogItemBuilder.catalog_item(variant) }
it "updates from on-demand to out-of-stock" do
variant.save!
variant.on_demand = true
variant.on_hand = -3
item.stockLimitation = 0
expect {
CatalogItemBuilder.apply_stock(item, variant)
variant.save!
}
.to change { variant.on_demand }.to(false)
.and change { variant.on_hand }.to(0)
end
end
end